Skip to content

Commit

Permalink
timetag.format move to method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 27, 2021
1 parent b913baa commit 82532ca
Showing 1 changed file with 13 additions and 3 deletions.
Expand Up @@ -671,9 +671,7 @@ public static void registerTags() {
// For the full format specification, refer to "Patterns for Formatting and Parsing" on <@link url https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html>.
// -->
registerTag("format", (attribute, object) -> {
String formatText = attribute.hasContext(1) ? attribute.getContext(1) : "yyyy/MM/dd HH:mm:ss";
DateTimeFormatter format = DateTimeFormatter.ofPattern(formatText);
return new ElementTag(object.instant.format(format));
return new ElementTag(object.format(attribute.hasContext(1) ? attribute.getContext(1) : null));
});

registerTag("duration_compat", (attribute, object) -> {
Expand All @@ -687,6 +685,18 @@ public static void registerTags() {
});
}

public String format() {
return format(null);
}

public String format(String formatText) {
if (formatText == null) {
formatText = "yyyy/MM/dd HH:mm:ss";
}
DateTimeFormatter format = DateTimeFormatter.ofPattern(formatText);
return instant.format(format);
}

public long millis() {
return instant.toEpochSecond() * 1000 + instant.getNano() / 1_000_000;
}
Expand Down

0 comments on commit 82532ca

Please sign in to comment.