in src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/FormatFilterExtension.java [222:253]
private String formatDate(String format, Date date, Locale locale, TimeZone timezone) {
if (date == null) {
return null;
}
try {
DateTimeFormatter formatter;
FormatStyle formattingStyle = getPredefinedFormattingStyleFromValue(format);
if (formattingStyle != null) {
formatter = DateTimeFormatter.ofLocalizedDate(formattingStyle);
if (locale != null) {
formatter = formatter.withLocale(locale);
}
} else {
// escape reserved characters, that are allowed according to the htl-tck
format = format.replaceAll("([{}#])", "'$1'");
// normalized text narrow form to full form to be compatible with java.text.SimpleDateFormat
// for example EEEEE becomes EEEE
format = format.replaceAll("([GMLQqEec])\\1{4}", "$1$1$1$1");
if (locale != null) {
formatter = DateTimeFormatter.ofPattern(format, locale);
} else {
formatter = DateTimeFormatter.ofPattern(format);
}
}
return formatter.format(timezone != null ? date.toInstant().atZone(timezone.toZoneId()) : date.toInstant());
} catch (Exception e) {
String error = String.format(
"Error during formatting of date %s with format %s, locale %s and timezone %s",
date, format, locale, timezone);
throw new SightlyException(error, e);
}
}