Moved renderer methods to RenderUtils
This commit is contained in:
parent
54f40eb41e
commit
b7c9695395
7 changed files with 178 additions and 175 deletions
|
@ -20,9 +20,7 @@ package rife.render;
|
|||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
|
||||
/**
|
||||
* <p>Renders the current time in Swatch Internet (.beat) Time format.</p>
|
||||
|
@ -38,24 +36,11 @@ import java.time.temporal.ChronoField;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class BeatTime implements ValueRenderer {
|
||||
/**
|
||||
* Returns the Swatch Internet (.beat) Time for the give date-time.
|
||||
*
|
||||
* @param zonedDateTime the date and time.
|
||||
* @return the .beat time. (eg.: {@code @248})
|
||||
*/
|
||||
public static String beatTime(ZonedDateTime zonedDateTime) {
|
||||
var zdt = zonedDateTime.withZoneSameInstant(ZoneId.of("UTC+01:00"));
|
||||
var beats = (int) ((zdt.get(ChronoField.SECOND_OF_MINUTE) + (zdt.get(ChronoField.MINUTE_OF_HOUR) * 60)
|
||||
+ (zdt.get(ChronoField.HOUR_OF_DAY) * 3600)) / 86.4);
|
||||
return String.format("@%03d", beats);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
return beatTime(ZonedDateTime.now());
|
||||
return RenderUtils.beatTime(ZonedDateTime.now());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue