Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions moment.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ component displayname="moment" {
return from( nnow );
}

public function epoch() hint="returns the number of milliseconds since 1/1/1970 (local)" {
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);
}

public function getDateTime() hint="return raw datetime object in current zone" {
Expand Down Expand Up @@ -390,6 +390,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
//===========================================
Expand Down