Skip to content

Commit

Permalink
Added a fix for the ticket LDEV-5173.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfmitrah committed Dec 11, 2024
1 parent 656d2b3 commit d155c83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d155c83

Please sign in to comment.