Skip to content

Commit

Permalink
BL-745 Resolve - Add support for alt JS toString output with TZ abbre…
Browse files Browse the repository at this point in the history
…viation
  • Loading branch information
jclausen committed Nov 5, 2024
1 parent e4fa5fe commit e6d601b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ortus/boxlang/runtime/types/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class DateTime implements IType, IReferenceable, Serializable, ValueWrite
public static final String ODBC_TIME_FORMAT_MASK = "'{t '''HH:mm:ss'''}'";
// The format used by most browsers when calling toString on a Javascript date object - note that this is implementation dependent and may not be reliable
public static final String JS_COMMON_TO_STRING_MASK = "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzzz)";
// The format used by most browsers when calling toString on a Javascript date object - note that this is implementation dependent and may not be reliable
public static final String JS_COMMON_ALT_STRING_MASK = "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzz)";

/**
* Common Modes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ public static DateTimeFormatter getLocaleDateTimeParsers( Locale locale ) {
.appendOptional( DateTimeFormatter.ofPattern( DateTime.DEFAULT_DATETIME_FORMAT_MASK ) )
.appendOptional( DateTimeFormatter.ofPattern( DateTime.TS_FORMAT_MASK ) )
.appendOptional( DateTimeFormatter.ofPattern( DateTime.JS_COMMON_TO_STRING_MASK ) )
.appendOptional( DateTimeFormatter.ofPattern( DateTime.JS_COMMON_ALT_STRING_MASK ) )
.appendOptional( DateTimeFormatter.ISO_INSTANT )
.appendOptional( DateTimeFormatter.ISO_DATE_TIME )
.appendOptional( DateTimeFormatter.ISO_LOCAL_DATE_TIME )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ public void testParseJSStringDate() {

}

@DisplayName( "It tests the BIF ParseDateTime using the alt Node Javascript toString format" )
@Test
public void testParseJSAltStringDate() {
instance.executeSource(
"""
result = ParseDateTime( "Wed Sep 18 2024 09:20:47 GMT-0700 (PDT)" );
""",
context );
DateTime result = ( DateTime ) variables.get( Key.of( "result" ) );
assertThat( result ).isInstanceOf( DateTime.class );
assertThat( result.toString() ).isInstanceOf( String.class );
assertThat( IntegerCaster.cast( result.format( "yyyy" ) ) ).isEqualTo( 2024 );
assertThat( IntegerCaster.cast( result.format( "M" ) ) ).isEqualTo( 9 );
assertThat( IntegerCaster.cast( result.format( "d" ) ) ).isEqualTo( 18 );
assertThat( IntegerCaster.cast( result.format( "H" ) ) ).isEqualTo( 9 );
assertThat( IntegerCaster.cast( result.format( "m" ) ) ).isEqualTo( 20 );
assertThat( IntegerCaster.cast( result.format( "s" ) ) ).isEqualTo( 47 );

}

@DisplayName( "It tests the BIF ParseDateTime allowing Luis to use lower-case am/pm format" )
@Test
public void testParseLuisFormat() {
Expand Down

0 comments on commit e6d601b

Please sign in to comment.