-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,357 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ build/** | |
### BOXLANG ### | ||
grapher/** | ||
/libs/ | ||
/bin/ | ||
src/test/resources/libs/ | ||
grapher/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#Fri Aug 09 20:10:30 UTC 2024 | ||
boxlangVersion=1.0.0-beta9 | ||
#Wed Sep 04 17:11:15 UTC 2024 | ||
boxlangVersion=1.0.0-snapshot | ||
jdkVersion=21 | ||
version=1.3.0 | ||
version=1.4.0 | ||
group=io.boxlang |
71 changes: 71 additions & 0 deletions
71
src/main/java/ortus/boxlang/modules/compat/bifs/temporal/LSDateTimeFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.modules.compat.bifs.temporal; | ||
|
||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.bifs.BoxMember; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.BoxLangType; | ||
|
||
@BoxBIF | ||
@BoxBIF( alias = "LSDateFormat" ) | ||
@BoxBIF( alias = "LSTimeFormat" ) | ||
@BoxMember( type = BoxLangType.DATETIME, name = "LSDateTimeFormat" ) | ||
@BoxMember( type = BoxLangType.DATETIME, name = "LSDateFormat" ) | ||
@BoxMember( type = BoxLangType.DATETIME, name = "LSTimeFormat" ) | ||
public class LSDateTimeFormat extends ortus.boxlang.runtime.bifs.global.temporal.DateTimeFormat { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public LSDateTimeFormat() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, "any", Key.date ), | ||
new Argument( false, "string", Key.mask ), | ||
new Argument( false, "string", Key.locale ), | ||
new Argument( false, "string", Key.timezone ) | ||
}; | ||
} | ||
|
||
/** | ||
* Formats a date in a locale-specific format | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.date The date string or object | ||
* | ||
* @argument.mask Optional format mask, or common mask | ||
* | ||
* @argument.locale Optional locale designation of the output ( e.g. es-SA ) | ||
* | ||
* @argument.timezone Optional specific timezone to apply to the date ( if not present in the date string ) | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
String functionName = arguments.getAsKey( BIF.__functionName ).getName(); | ||
Key dtFunctionName = Key.of( functionName.substring( 2 ) ); | ||
arguments.put( BIF.__functionName, dtFunctionName ); | ||
return super._invoke( context, arguments ); | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/ortus/boxlang/modules/compat/bifs/temporal/LSIsDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
package ortus.boxlang.modules.compat.bifs.temporal; | ||
|
||
import java.time.ZoneId; | ||
import java.time.zone.ZoneRulesException; | ||
import java.util.Locale; | ||
|
||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.dynamic.casters.StringCaster; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.DateTime; | ||
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException; | ||
import ortus.boxlang.runtime.util.LocalizationUtil; | ||
|
||
@BoxBIF | ||
|
||
public class LSIsDate extends BIF { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public LSIsDate() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, "any", Key.date ), | ||
new Argument( false, "string", Key.locale ), | ||
new Argument( false, "string", Key.timezone ) | ||
}; | ||
} | ||
|
||
/** | ||
* Determines whether a string is avalid date/time string with either a specific locale or within the current system/application locale | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.date The date/time string to check. | ||
* | ||
* @argument.locale The locale to use for parsing the date/time string. | ||
* | ||
* @argument.timezone Optional timezone to use for parsing the date/time string. | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
Object dateRef = arguments.get( Key.date ); | ||
String timezone = arguments.getAsString( Key.timezone ); | ||
String locale = arguments.getAsString( Key.locale ); | ||
Locale localeObj = LocalizationUtil.getParsedLocale( locale ); | ||
ZoneId zoneId = null; | ||
|
||
if ( dateRef instanceof DateTime ) { | ||
return true; | ||
} | ||
try { | ||
zoneId = timezone != null ? ZoneId.of( timezone ) : ZoneId.systemDefault(); | ||
} catch ( ZoneRulesException e ) { | ||
throw new BoxRuntimeException( | ||
String.format( | ||
"The value [%s] is not a valid timezone.", | ||
timezone | ||
), | ||
e | ||
); | ||
} | ||
|
||
try { | ||
new DateTime( StringCaster.cast( dateRef ), localeObj, zoneId ); | ||
return true; | ||
} catch ( Exception e ) { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/ortus/boxlang/modules/compat/bifs/temporal/LSParseDateTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
package ortus.boxlang.modules.compat.bifs.temporal; | ||
|
||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.bifs.BoxMember; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.BoxLangType; | ||
|
||
@BoxBIF | ||
@BoxMember( type = BoxLangType.STRING, name = "LSParseDateTime" ) | ||
public class LSParseDateTime extends ortus.boxlang.runtime.bifs.global.temporal.ParseDateTime { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public LSParseDateTime() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, "any", Key.date ), | ||
new Argument( false, "string", Key.locale ), | ||
new Argument( false, "string", Key.timezone ), | ||
new Argument( false, "string", Key.format ) | ||
}; | ||
} | ||
|
||
/** | ||
* Parses a locale-specific datetime string or object | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.date the date, datetime string or an object | ||
* | ||
* @argument.the ISO locale string ( e.g. en-US, en_US, es-SA, es_ES, ru-RU, etc ) | ||
* | ||
* @argument.format the format mask to use in parsing | ||
* | ||
* @argument.timezone the timezone to apply to the parsed datetime | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
return super._invoke( context, arguments ); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/ortus/boxlang/modules/compat/bifs/temporal/LSTimeUnits.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
package ortus.boxlang.modules.compat.bifs.temporal; | ||
|
||
import java.util.HashMap; | ||
|
||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.bifs.BoxMember; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.runtime.types.BoxLangType; | ||
import ortus.boxlang.runtime.types.Struct; | ||
|
||
@BoxBIF( alias = "LSWeek" ) | ||
@BoxBIF( alias = "LSDayOfWeek" ) | ||
@BoxMember( type = BoxLangType.DATETIME, name = "lsWeek" ) | ||
@BoxMember( type = BoxLangType.DATETIME, name = "lsDayOfWeek" ) | ||
public class LSTimeUnits extends TimeUnits { | ||
|
||
/** | ||
* Map of ls functions to TimeUnits functions | ||
*/ | ||
public final static Struct functionMap = new Struct( | ||
new HashMap<String, Key>() { | ||
|
||
{ | ||
put( "LSDayOfWeek", Key.of( "dayOfWeek" ) ); | ||
put( "LSWeek", Key.of( "week" ) ); | ||
} | ||
} | ||
); | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public LSTimeUnits() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, "any", Key.date ), | ||
new Argument( false, "string", Key.locale ), | ||
new Argument( false, "string", Key.timezone ) | ||
}; | ||
} | ||
|
||
/** | ||
* Provides the Localized BIF and member functions for time units ( e.g. different locales have different start days to the week ) | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.date The DateTime object or datetime string representation | ||
* | ||
* @argument.locale The locale string to be parsed and applied to the final result | ||
* | ||
* @argument.timezone The timezone with which to cast the result | ||
*/ | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
arguments.put( BIF.__functionName, functionMap.get( arguments.getAsKey( BIF.__functionName ) ) ); | ||
return super._invoke( context, arguments ); | ||
} | ||
|
||
} |
Oops, something went wrong.