From 1a62ad6f85f52915c07f885c6361683d6561974f Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 21 Oct 2024 23:18:57 +0200 Subject: [PATCH] LDEV-5115 - switch to DateTimeFormatter --- .../displayFormatting/DateTimeFormat.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/lucee/runtime/functions/displayFormatting/DateTimeFormat.java b/core/src/main/java/lucee/runtime/functions/displayFormatting/DateTimeFormat.java index 458b62d188..f16f073ada 100644 --- a/core/src/main/java/lucee/runtime/functions/displayFormatting/DateTimeFormat.java +++ b/core/src/main/java/lucee/runtime/functions/displayFormatting/DateTimeFormat.java @@ -22,6 +22,8 @@ import java.util.Locale; import java.util.TimeZone; +import lucee.print; +import lucee.commons.date.TimeZoneConstants; import lucee.commons.i18n.FormatUtil; import lucee.commons.lang.StringUtil; import lucee.runtime.PageContext; @@ -102,11 +104,11 @@ else if ("epochms".equalsIgnoreCase(mask)) { } DateTimeFormatter formatter; - if (mask.equalsIgnoreCase("short")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); - else if (mask.equalsIgnoreCase("medium")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); - else if (mask.equalsIgnoreCase("long")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); - else if (mask.equalsIgnoreCase("full")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); - else if (mask.equalsIgnoreCase("iso8601")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); + if (mask != null && mask.equalsIgnoreCase("short")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); + else if (mask != null && mask.equalsIgnoreCase("medium")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); + else if (mask != null && mask.equalsIgnoreCase("long")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); + else if (mask != null && mask.equalsIgnoreCase("full")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); + else if (mask != null && mask.equalsIgnoreCase("iso8601")) formatter = FormatUtil.getDateTimeFormatter(locale, mask); else { formatter = FormatUtil.getDateTimeFormatter(locale, convertMask(mask)); @@ -354,6 +356,10 @@ private static boolean hasAlready(StringBuilder sb, char c, int count) { return false; } + public static void main(String[] args) throws Exception { + print.e(invoke(new java.util.Date(), null, Locale.US, TimeZoneConstants.UTC)); + } + /* * public static void main(String[] args) throws Exception { print.e(invoke(new java.util.Date(), * "t.Z.z.X.x.F.f.m.M.W.w.k.K.h.H.E.d.m.s.n.l.y.g.a", Locale.US, TimeZoneConstants.UTC));