From bca6dd8b49e11b5f3005177173cfb93f329f92af Mon Sep 17 00:00:00 2001 From: jclausen Date: Thu, 23 May 2024 16:11:59 -0400 Subject: [PATCH] BL-135 resolve --- .../runtime/bifs/global/temporal/TimeUnits.java | 2 +- .../bifs/global/temporal/TimeUnitsTest.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnits.java b/src/main/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnits.java index fb78d3b75..062f8c469 100644 --- a/src/main/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnits.java +++ b/src/main/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnits.java @@ -207,7 +207,7 @@ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { } // LS Subclass locales - Locale locale = LocalizationUtil.parseLocale( arguments.getAsString( Key.locale ) ); + Locale locale = LocalizationUtil.parseLocaleFromContext( context, arguments ); Key bifMethodKey = arguments.getAsKey( BIF.__functionName ); String methodName = null; diff --git a/src/test/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnitsTest.java b/src/test/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnitsTest.java index b1b3ad348..0796da572 100644 --- a/src/test/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnitsTest.java +++ b/src/test/java/ortus/boxlang/runtime/bifs/global/temporal/TimeUnitsTest.java @@ -27,6 +27,8 @@ import java.time.ZonedDateTime; import java.time.temporal.ChronoField; import java.time.temporal.IsoFields; +import java.time.temporal.WeekFields; +import java.util.Locale; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -38,6 +40,7 @@ import ortus.boxlang.runtime.context.IBoxContext; import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; import ortus.boxlang.runtime.dynamic.casters.LongCaster; +import ortus.boxlang.runtime.scopes.ArgumentsScope; import ortus.boxlang.runtime.scopes.IScope; import ortus.boxlang.runtime.scopes.Key; import ortus.boxlang.runtime.scopes.VariablesScope; @@ -50,6 +53,7 @@ public class TimeUnitsTest { IBoxContext context; IScope variables; static Key result = new Key( "result" ); + static Locale locale; @BeforeAll public static void setUp() { @@ -64,6 +68,7 @@ public static void teardown() { public void setupEach() { context = new ScriptingRequestBoxContext( instance.getRuntimeContext() ); variables = context.getScopeNearby( VariablesScope.name ); + locale = LocalizationUtil.parseLocaleFromContext( context, new ArgumentsScope() ); } @DisplayName( "It tests the BIF Year" ) @@ -276,7 +281,7 @@ public void testMemberDaysInYear() { @DisplayName( "It tests the BIF DayOfWeek" ) @Test public void testBifDayOfWeek() { - Integer refDayOfWeek = ZonedDateTime.now().getDayOfWeek().getValue(); + Integer refDayOfWeek = ZonedDateTime.now().get( WeekFields.of( locale ).dayOfWeek() ); instance.executeSource( """ now = now(); @@ -285,12 +290,20 @@ public void testBifDayOfWeek() { context ); Integer result = ( Integer ) variables.get( Key.of( "result" ) ); assertEquals( result, refDayOfWeek ); + instance.executeSource( + """ + now = parseDateTime( "2024-04-07" ); + result = dayOfWeek( now ); + """, + context ); + result = variables.getAsInteger( Key.of( "result" ) ); + assertEquals( 1, result ); } @DisplayName( "It tests the DateTime Member function DayOfWeek" ) @Test public void testMemberDayOfWeek() { - Integer refDayOfWeek = ZonedDateTime.now().getDayOfWeek().getValue(); + Integer refDayOfWeek = ZonedDateTime.now().get( WeekFields.of( locale ).dayOfWeek() ); instance.executeSource( """ result = now().dayOfWeek();