Class DateTimeCaster

java.lang.Object
ortus.boxlang.runtime.dynamic.casters.DateTimeCaster
All Implemented Interfaces:
IBoxCaster

public class DateTimeCaster extends Object implements IBoxCaster
I cast to DateTime objects
  • Constructor Details

    • DateTimeCaster

      public DateTimeCaster()
  • Method Details

    • attempt

      public static CastAttempt<DateTime> attempt(Object object)
      Tests to see if the value can be cast. Returns a CastAttempt<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

      public static DateTime cast(Object object)
      Used to cast anything, throwing exception if we fail
      Parameters:
      object - The value to cast
      Returns:
      The value
    • cast

      public static DateTime cast(Object object, Boolean fail)
      Used to cast anything
      Parameters:
      object - The value to cast
      fail - True to throw exception when failing.
      Returns:
      The value, or null when cannot be cast
    • cast

      public static DateTime cast(Object object, Boolean fail, ZoneId timezone)
      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 cast
      fail - 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)
      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 cast
      fail - True to throw exception when failing.
      timezone - The ZoneId to ensure a timezone is applied
      clone - 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

      public static boolean isKnownDateClass(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. 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