From d155c836c65f526f7f8613e85c2439ca30860bc7 Mon Sep 17 00:00:00 2001 From: CF Mitrah Date: Wed, 11 Dec 2024 16:29:19 +0530 Subject: [PATCH] Added a fix for the ticket LDEV-5173. --- .../international/LSParseDateTime.java | 22 +++++++++++++++++++ .../functions/string/ParseDateTime.java | 3 +++ 2 files changed, 25 insertions(+) diff --git a/core/src/main/java/lucee/runtime/functions/international/LSParseDateTime.java b/core/src/main/java/lucee/runtime/functions/international/LSParseDateTime.java index ac9a438f9d..d8696f7e90 100644 --- a/core/src/main/java/lucee/runtime/functions/international/LSParseDateTime.java +++ b/core/src/main/java/lucee/runtime/functions/international/LSParseDateTime.java @@ -22,6 +22,9 @@ package lucee.runtime.functions.international; import java.text.DateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Date; import java.util.Locale; import java.util.TimeZone; @@ -73,6 +76,25 @@ private static lucee.runtime.type.dt.DateTime _call(PageContext pc, Object oDate String strDate = StringUtil.replaceSpecialWhiteSpace(Caster.toString(oDate)); + if (format != null && "epoch".equalsIgnoreCase(format.trim())) { + String seconds = oDate.toString(); + long timeSeconds = Long.parseLong(seconds); + long milliseconds = timeSeconds*1000; + Instant instant = Instant.ofEpochMilli(milliseconds); + LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); + strDate = StringUtil.replaceSpecialWhiteSpace(Caster.toString(localDateTime)); + return DateCaster.toDateTime(locale, strDate, tz, isUSLike(locale)); + } + else if (format != null && "epochms".equalsIgnoreCase(format.trim())) { + String seconds = oDate.toString(); + long timeSeconds = Long.parseLong(seconds); + long milliseconds = timeSeconds; + Instant instant = Instant.ofEpochMilli(milliseconds); + LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime(); + strDate = StringUtil.replaceSpecialWhiteSpace(Caster.toString(localDateTime)); + return DateCaster.toDateTime(locale, strDate, tz, isUSLike(locale)); + } + // regular parse date time if (StringUtil.isEmpty(format, true)) return DateCaster.toDateTime(locale, strDate, tz, isUSLike(locale)); diff --git a/core/src/main/java/lucee/runtime/functions/string/ParseDateTime.java b/core/src/main/java/lucee/runtime/functions/string/ParseDateTime.java index 23c5057d17..91676e24d4 100644 --- a/core/src/main/java/lucee/runtime/functions/string/ParseDateTime.java +++ b/core/src/main/java/lucee/runtime/functions/string/ParseDateTime.java @@ -53,6 +53,9 @@ public static lucee.runtime.type.dt.DateTime call(PageContext pc, Object oDate, private static lucee.runtime.type.dt.DateTime _call(PageContext pc, Object oDate, String popConversion, TimeZone tz) throws PageException { if (!StringUtil.isEmpty(popConversion) && !"standard".equalsIgnoreCase(popConversion = popConversion.trim()) && !"pop".equalsIgnoreCase(popConversion.trim())) { + if("epoch".equalsIgnoreCase(popConversion.trim()) || "epochms".equalsIgnoreCase(popConversion.trim())){ + return LSParseDateTime.call(pc, oDate, Locale.US, tz.getID(), popConversion); + } popConversion = DateTimeFormat.convertMask(popConversion); return LSParseDateTime.call(pc, oDate, Locale.US, tz.getID(), popConversion); }