Class DateFunctions

java.lang.Object
com.scriptbasic.utility.functions.DateFunctions

public class DateFunctions extends Object
  • Field Details

    • DATE_ZERO

      public static final LocalDate DATE_ZERO
      Date zero is 30.12.1899 Due to compatibility with MS VBA
  • Constructor Details

    • DateFunctions

      public DateFunctions()
  • Method Details

    • setDateParser

      public static void setDateParser(DateFunctions.DateParser parser)
    • getDateParser

      public static DateFunctions.DateParser getDateParser()
    • setDateFormatter

      public static void setDateFormatter(DateFunctions.DateFormatter formatter)
    • getDateFormatter

      public static DateFunctions.DateFormatter getDateFormatter()
    • cdate

      public static LocalDate cdate(Object o) throws BasicRuntimeException
      Conversion function to date
      Parameters:
      o - date compatible object
      Returns:
      date
      Throws:
      BasicRuntimeException - failed to convert to date
    • date

      public static LocalDate date()
    • year

      public static Integer year(Object operand) throws ScriptBasicException
      Returns a Integer containing a whole number representing the year.
      Parameters:
      operand - value representing date (numeric, string, date)
      Returns:
      whole number representing the year
      Throws:
      ScriptBasicException - if operand is not date
    • month

      public static Integer month(Object operand) throws ScriptBasicException
      Returns a Integer specifying a whole number between 1 and 12, inclusive, representing the month of the year.
      Parameters:
      operand - value representing date (numeric, string, date)
      Returns:
      month, number between 1 and 12
      Throws:
      ScriptBasicException - if operand is not date
    • day

      public static Integer day(Object operand) throws ScriptBasicException
      Returns a Integer specifying a whole number between 1 and 31, inclusive, representing the day of the month.
      Parameters:
      operand - value representing date (numeric, string, date)
      Returns:
      day of the month, number between 1 and 31
      Throws:
      ScriptBasicException - if operand is not date
    • dateserial

      public static BasicDateValue dateserial(Integer year, Integer month, Integer dayOfMonth) throws ScriptBasicException
      Returns a Date for a specified year, month, and day.
      Parameters:
      year - number between 100 and 9999
      month - the month-of-year to represent, from 1 (January) to 12 (December)
      dayOfMonth - the day-of-month to represent, from 1 to 31
      Returns:
      date object
      Throws:
      ScriptBasicException - error when parameter is out of range
    • dateadd

      public static LocalDate dateadd(String interval, Long number, Object date) throws ScriptBasicException
      Returns a date containing a date to which a specified time interval has been added.
      Parameters:
      interval - String that is the interval of time you want to add.
      number - Number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
      date - Date or literal representing the date to which the interval is added.
      Returns:
      date with added time interval
      Throws:
      ScriptBasicException - when incorrect arguments
    • datediff

      public static long datediff(String interval, LocalDate date1, LocalDate date2) throws ScriptBasicException
      Returns a Variant (Long) specifying the number of time intervals between two specified dates.
      Parameters:
      interval - Interval of time used to calculate the difference between date1 and date2.
      date1 - Date used for calculation
      date2 - Date used for calculation
      Returns:
      number of time intervals between two specified dates
      Throws:
      ScriptBasicException - when unsupported type of interval
    • isoDateParser

      public static LocalDate isoDateParser(String src) throws BasicRuntimeException
      Basic implementation of date parser Obtains an instance of LocalDate from a text string such as 2007-12-03.
      Parameters:
      src - date to be parsed
      Returns:
      date
      Throws:
      BasicRuntimeException - Exception if failed to parse date
    • isoDateFormatter

      public static String isoDateFormatter(LocalDate localDate)
      Obtains an instance of LocalDate from a text string such as 2007-12-03.
      Parameters:
      localDate - date to format
      Returns:
      formatted date
    • isDate

      public static boolean isDate(Object o)