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..a135a7fa8e 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,20 @@ 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())) { + Instant instant = Instant.ofEpochMilli(Long.parseLong(oDate.toString()) * 1000); + 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())) { + Instant instant = Instant.ofEpochMilli(Long.parseLong(oDate.toString())); + 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)); @@ -117,4 +134,4 @@ public static final boolean isUSLike(Locale locale) { if (locale == null) return false; return locale.getLanguage().equalsIgnoreCase("en") && (StringUtil.isEmpty(locale.getCountry()) || "US".equalsIgnoreCase(locale.getCountry())); } -} \ No newline at end of file +} 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); }