Skip to content

Commit

Permalink
getTime() on DateTime object helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed May 2, 2024
1 parent aceaa6e commit 8405526
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/ortus/boxlang/runtime/types/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ public String toString() {
/*
* Clones this object to produce a new object
*/
@Override
public DateTime clone() {
return clone( this.wrapped.getZone() );
}
Expand Down Expand Up @@ -759,6 +758,13 @@ public static Locale getParsedLocale( String locale ) {
return localeObj;
}

/**
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
*/
public Long getTime() {
return this.wrapped.toInstant().toEpochMilli();
}

/**
* --------------------------------------------------------------------------
* IReferenceable Interface Methods
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/ortus/boxlang/runtime/types/DateTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@ void testModifications() {
assertThat( initialQuarter ).isEqualTo( LongCaster.cast( initialDateTime.format( "Q" ) ) );
}

@DisplayName( "Test getTime() helper" )
@Test
void testGetTime() {
DateTime defaultDateTime = new DateTime( "2023-12-31 00:00:00", "yyyy-MM-dd HH:mm:ss" );
assertThat( defaultDateTime.getTime() ).isEqualTo( defaultDateTime.getWrapped().toInstant().toEpochMilli() );
}

}

0 comments on commit 8405526

Please sign in to comment.