Class DateTimeCaster
java.lang.Object
ortus.boxlang.runtime.dynamic.casters.DateTimeCaster
- All Implemented Interfaces:
IBoxCaster
I cast to DateTime objects
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CastAttempt<DateTime> Tests to see if the value can be cast.static CastAttempt<DateTime> attempt(Object object, IBoxContext context) Tests to see if the value can be cast.static DateTimeUsed to cast anything, throwing exception if we failstatic DateTimeUsed to cast anything to a DateTime object.static DateTimecast(Object object, Boolean fail, ZoneId timezone, IBoxContext context) Used to cast anything to a DateTime object.static DateTimecast(Object object, Boolean fail, IBoxContext context) Used to cast anythingstatic DateTimecast(Object object, IBoxContext context) Used to cast anything, throwing exception if we failstatic booleanisKnownDateClass(Object object) This is not meant as a cast or instance of check really-- just a conveneince method of known date classes to differentiate a variable that could possibly be cast to a date (like) a string from a variable which is ALREADY an instance of a specific date class.
-
Constructor Details
-
DateTimeCaster
public DateTimeCaster()
-
-
Method Details
-
attempt
Tests to see if the value can be cast. Returns aCastAttempt<T>which will contain the result if casting was was successfull, or can be interogated to proceed otherwise.- Parameters:
object- The value to cast- Returns:
- The value
-
attempt
Tests to see if the value can be cast. Returns aCastAttempt<T>which will contain the result if casting was was successfull, or can be interogated to proceed otherwise.- Parameters:
object- The value to cast- Returns:
- The value
-
cast
Used to cast anything, throwing exception if we fail- Parameters:
object- The value to cast- Returns:
- The value
-
cast
Used to cast anything, throwing exception if we fail- Parameters:
object- The value to cast- Returns:
- The value
-
cast
Used to cast anything- Parameters:
object- The value to castfail- True to throw exception when failing.- Returns:
- The value, or null when cannot be cast
-
cast
Used to cast anything to a DateTime object. We start off by testing the object against commonly known Java date objects, and then try to parse the object as a string. If we fail, we return null.- Parameters:
object- The value to castfail- True to throw exception when failing.timezone- The ZoneId to ensure a timezone is applied- Returns:
- The value, or null when cannot be cast
-
cast
public static DateTime cast(Object object, Boolean fail, ZoneId timezone, Boolean clone, IBoxContext context) Used to cast anything to a DateTime object. We start off by testing the object against commonly known Java date objects, and then try to parse the object as a string. If we fail, we return null.- Parameters:
object- The value to castfail- True to throw exception when failing.timezone- The ZoneId to ensure a timezone is appliedclone- If true, will return a clone of the object if it was originally a DateTime.- Returns:
- The value, or null when cannot be cast
-
isKnownDateClass
This is not meant as a cast or instance of check really-- just a conveneince method of known date classes to differentiate a variable that could possibly be cast to a date (like) a string from a variable which is ALREADY an instance of a specific date class. If this method returns true for an object, that means it SHOULD successfully cast to a DateTime- Parameters:
object- The object to check- Returns:
- True if the object is a known date class
-