Remove DateTimeUtc, replaced with tz property of DateTimeIso

This commit is contained in:
Erik C. Thauvin 2023-03-17 21:46:20 -07:00
parent 26e03588ea
commit 7f1cea5714
5 changed files with 25 additions and 50 deletions

View file

@ -21,8 +21,12 @@ import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.Localization;
import java.io.IOException;
import java.io.StringReader;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Properties;
/**
* <p>Return the current date and time in ISO 8601 format.</p>
@ -49,6 +53,20 @@ public class DateTimeIso implements ValueRenderer {
*/
@Override
public String render(Template template, String valueId, String differentiator) {
if (template.hasDefaultValue(valueId)) {
var properties = new Properties();
try {
var tz = "tz";
properties.load(new StringReader(template.getDefaultValue(valueId)));
if (properties.containsKey(tz)) {
return ZonedDateTime.now().format(
DateTimeIso.iso8601Formatter.withZone(ZoneId.of(properties.getProperty(tz))));
}
} catch (IOException ignore) {
// do nothing
}
}
return ZonedDateTime.now().format(iso8601Formatter);
}
}