From 27142f4b052f712bdd2ea7bd2c2c529dc768cfb0 Mon Sep 17 00:00:00 2001 From: mograff Date: Thu, 30 Jul 2020 15:43:31 -0500 Subject: [PATCH] Update moment.cfc Fixed errors with epoch coming back in scientific notation. Also added function to convert epochTimeToDate --- moment.cfc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/moment.cfc b/moment.cfc index 65d5e63..58a5919 100755 --- a/moment.cfc +++ b/moment.cfc @@ -177,7 +177,7 @@ component displayname="moment" { public struct function getZoneTable(){ var list = createObject('java', 'java.util.TimeZone').getAvailableIDs(); var data = {}; - for (tz in list){ + for (var tz in list){ //display *CURRENT* offsets var ms = getTZ( tz ).getOffset( getSystemTimeMS() ); data[ tz ] = readableOffset( ms ); @@ -264,17 +264,17 @@ component displayname="moment" { return from( nnow ); } - public function epoch() hint="returns the number of milliseconds since 1/1/1970 (local). Call .utc() first to get utc epoch" { + public numeric function epoch() hint="returns the number of milliseconds since 1/1/1970 (local). Call .utc() first to get utc epoch" { /* It seems that we can't get CF to give us an actual UTC datetime object without using DateConvert(), which we can not rely on, because it depends on the system time being the local time converting from/to. Instead, we've devised a system of detecting the target time zone's offset and using it here (the only place it seems necessary) to return the expected epoch values. */ - return this.clone().getDateTime().getTime() - this.utc_conversion_offset; + return javacast("bigdecimal",this.clone().getDateTime().getTime() - this.utc_conversion_offset); var adjustment = (this.utc_conversion_offset > 0) ? -1 : 1; - return this.clone().getDateTime().getTime(); - return this.clone().getDateTime().getTime() - (this.utc_conversion_offset * adjustment); + return javacast("bigdecimal",this.clone().getDateTime().getTime()); + return javacast("bigdecimal",this.clone().getDateTime().getTime() - (this.utc_conversion_offset * adjustment)); } public function getDateTime() hint="return raw datetime object in current zone" { @@ -389,6 +389,10 @@ component displayname="moment" { return getTZ( this.zone ).inDayLightTime( dt ); } + public date function epochTimeToDate(epoch) { + return createObject( "java", "java.util.Date" ).init( javaCast( "long", epoch ) ); + } + //=========================================== //INTERNAL HELPERS //===========================================