Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Sep 16, 2024
2 parents 3d55cca + 2430f2a commit 23b0e69
Show file tree
Hide file tree
Showing 14 changed files with 1,357 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ build/**
### BOXLANG ###
grapher/**
/libs/
/bin/
src/test/resources/libs/
grapher/*
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {
branch = System.getenv( 'BRANCH' ) ?: 'development'
}

if (branch == 'development') {
if ( branch == 'development' ) {
// If the branch is 'development', ensure the version ends with '-snapshot'
// This replaces any existing prerelease identifier with '-snapshot'
version = version.contains('-') ? version.replaceAll(/-.*/, '-snapshot') : "${version}-snapshot"
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
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
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 );
}

}
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;
}

}

}
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 );
}

}
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 );
}

}
Loading

0 comments on commit 23b0e69

Please sign in to comment.