Class DateTimeUtils

java.lang.Object
com.pervasive.datarush.tokens.scalar.DateTimeUtils

public class DateTimeUtils extends Object
Utilities for working with date/time values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TimeZone
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    epochDaysToMillis(long epochDays, ZoneId zoneId)
    Gets the instant in time at midnight in the specified time zone corresponding to the given date.
    static String
    Converts a date value into an ISO8601 date formatted string.
    static String
    Converts a time stamp value into an ISO8601 time stamp formatted string.
    static String
    Converts a time of day value into an ISO8601 time formatted string.
    static String
    formatDaysSinceEpoch(long epochDays)
    Converts a date, expressed as days, into an ISO8601 date formatted string.
    static String
    formatEpochTime(long seconds, int nanos, int offsetSecs)
    Converts a time stamp, expressed as component values, into an ISO8601 time stamp formatted string.
    static String
    Converts a time of day, expressed as milliseconds, into an ISO8601 time formatted string.
    static ZoneId
     
    static int
    Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.
    static String
    Gets the value - day, month, year, hour, minutes, seconds etc ChronoField values represented by the given Zoned Date Time
    static int
    Gets the value - day, month, year, hour, minutes, seconds etc ChronoField values represented by the given Zoned Date Time
    static int
    Normalize elapsed milliseconds to the standard range from midnight to midnight.
    protected static int
    parseIntField(String str, int startPos, int endPos)
     
    static void
    parseInto(String text, DateSettable buffer)
    Parses a date in ISO8601 format, storing the result into a date valued container.
    static void
    parseInto(String text, TimeSettable buffer)
    Parses a time of day in ISO8601 time format, storing the result into a time valued container.
    static void
    Parses a timestamp in ISO8601 format, storing the result into a timestamp valued container.
    static int
    parseTimeFields(String str, com.pervasive.datarush.tokens.scalar.DateTimeUtils.TimeParsingContext ctx, int pos)
     
    static long
    Parses a date in ISO8601 time format into days since epoch.
    static int
    Parses a time of day in ISO8601 time format into milliseconds since midnight.
    static LocalDate
    toDate(long epochDays)
    Gets the instant in time at midnight in the default time zone corresponding to the given date.
    static LocalDate
    toDate(long epochDays, ZoneId zoneId)
    Gets the instant in time at midnight in the specified time zone corresponding to the given date.
    static long
    toDaysSinceEpoch(int year, int monthOfYear, int dayOfMonth)
    Gets the specified date as days since epoch.
    static long
    toDaysSinceEpoch(long millis)
    Gets the date represented by the given instant in the default time zone as days since epoch.
    static long
    toDaysSinceEpoch(long millis, ZoneId zoneId)
    Gets the date represented by the given instant in the specified time zone as days since epoch.
    static long
    Gets the date represented by the given instant in the default time zone as days since epoch.
    static long
    Gets the date represented by the given instant in the default time zone as days since epoch.
    static long
    toDaysSinceEpoch(Date date, ZoneId zoneId)
    Gets the date represented by the given instant in the specified time zone as days since epoch.
    static void
    toEpochTime(long millis, TimestampSettable buffer)
    Stores the given instant into a time stamp buffer using the default time zone for the offset.
    static void
    toEpochTime(long millis, ZoneId zoneId, TimestampSettable buffer)
    Stores the given instant into a time stamp buffer using the specified time zone for the offset.
    static void
    Stores the given instant into a time stamp buffer using the default time zone for the offset.
    static void
    toEpochTime(Timestamp timestamp, ZoneId zoneId, TimestampSettable buffer)
    Stores the given instant into a time stamp buffer using the specified time zone for the offset.
    static void
    Stores the given instant into a time stamp buffer using the default time zone for the offset.
    static void
    toEpochTime(Date date, ZoneId zoneId, TimestampSettable buffer)
    Stores the given instant into a time stamp buffer using the specified time zone for the offset.
    static LocalDate
    toLocalDate(long milliSec)
     
    static int
    toMillisSinceMidnight(int hourOfDay, int minuteOfHour, int secondOfMinute)
    Gets the time, in 24-hour format, as milliseconds since midnight.
    static int
    toMillisSinceMidnight(long instant)
    Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
    static int
    toMillisSinceMidnight(long instant, int offset)
    Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
    static int
    toMillisSinceMidnight(long millis, ZoneId zoneId)
    Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
    static int
    Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
    static int
    Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
    static int
    Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
    static int
    Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
    static LocalTime
    toTime(long dayMillis)
    Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.
    static Timestamp
    toTimestamp(long epochSecs, int subsecNanos, int offsetSecs)
    Gets the instant in time on corresponding to the specified epoch time.
    static void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CST_TIMEZONE

      public static final TimeZone CST_TIMEZONE
  • Method Details

    • parseIntField

      protected static int parseIntField(String str, int startPos, int endPos)
    • parseTimeFields

      public static int parseTimeFields(String str, com.pervasive.datarush.tokens.scalar.DateTimeUtils.TimeParsingContext ctx, int pos)
    • millisToTextValue

      public static String millisToTextValue(TemporalField field, ZonedDateTime zdt)
      Gets the value - day, month, year, hour, minutes, seconds etc ChronoField values represented by the given Zoned Date Time
      Parameters:
      field - the TemporalField
      zdt - the ZonedDateTime
      Returns:
      value of the field represented by the supplied ZonedDateTime
    • millisToValue

      public static int millisToValue(TemporalField field, ZonedDateTime zdt)
      Gets the value - day, month, year, hour, minutes, seconds etc ChronoField values represented by the given Zoned Date Time
      Parameters:
      field - the TemporalField
      zdt - the ZonedDateTime
      Returns:
      value of the field represented by the supplied ZonedDateTime
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(int year, int monthOfYear, int dayOfMonth)
      Gets the specified date as days since epoch.
      Parameters:
      year - the year portion of the date
      monthOfYear - the month portion of the date. Months are counted as on a calendar, starting with 1 for January.
      dayOfMonth - the day portion of the date
      Returns:
      the number of days elapsed since January 1, 1970
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(Date date)
      Gets the date represented by the given instant in the default time zone as days since epoch.
      Parameters:
      date - the instant in time to convert
      Returns:
      the number of days elapsed since January 1, 1970
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(Date date, ZoneId zoneId)
      Gets the date represented by the given instant in the specified time zone as days since epoch.
      Parameters:
      date - the instant in time to convert
      zoneId - the time zone relative to which to interpret the instant
      Returns:
      the number of days elapsed since January 1, 1970
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(long millis)
      Gets the date represented by the given instant in the default time zone as days since epoch.
      Parameters:
      millis - the instant in time to convert
      Returns:
      the number of days elapsed since January 1, 1970
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(long millis, ZoneId zoneId)
      Gets the date represented by the given instant in the specified time zone as days since epoch.
      Parameters:
      millis - the instant in time to convert
      zoneId - the time zone id relative to which to interpret the instant
      Returns:
      the number of days elapsed since January 1, 1970
    • toDaysSinceEpoch

      public static long toDaysSinceEpoch(LocalDate localDate)
      Gets the date represented by the given instant in the default time zone as days since epoch.
      Parameters:
      date - the instant in time to convert
      Returns:
      the number of days elapsed since January 1, 1970
    • epochDaysToMillis

      public static long epochDaysToMillis(long epochDays, ZoneId zoneId)
      Gets the instant in time at midnight in the specified time zone corresponding to the given date.
      Parameters:
      epochDays - the number of milliseconds elapsed since January 1, 1970
      zoneId - the time zone id relative to which to convert the date
      Returns:
      the resulting instant in time as milliseconds in epoch
    • toDate

      public static LocalDate toDate(long epochDays)
      Gets the instant in time at midnight in the default time zone corresponding to the given date.
      Parameters:
      epochDays - the number of milliseconds elapsed since January 1, 1970
      Returns:
      a LocalDate object representing the date
    • toDate

      public static LocalDate toDate(long epochDays, ZoneId zoneId)
      Gets the instant in time at midnight in the specified time zone corresponding to the given date.
      Parameters:
      epochDays - the number of milliseconds elapsed since January 1, 1970
      zoneId - the time zone id relative to which to convert the date
      Returns:
      a LocalDate object representing the date
    • toLocalDate

      public static LocalDate toLocalDate(long milliSec)
    • parseToDaysSinceEpoch

      public static long parseToDaysSinceEpoch(String text)
      Parses a date in ISO8601 time format into days since epoch.
      Parameters:
      text - a date in ISO8601 format
      Returns:
      the number of days elapsed since January 1, 1970
    • parseInto

      public static void parseInto(String text, DateSettable buffer)
      Parses a date in ISO8601 format, storing the result into a date valued container. The empty string is parsed as a null value.
      Parameters:
      text - a date in ISO8601 format.
      buffer - the container in which to store the parsed value
    • formatDaysSinceEpoch

      public static String formatDaysSinceEpoch(long epochDays)
      Converts a date, expressed as days, into an ISO8601 date formatted string.
      Parameters:
      epochDays - the number of days elapsed since January 1, 1970
      Returns:
      the date in ISO8601 format
    • format

      public static String format(DateValued value)
      Converts a date value into an ISO8601 date formatted string.
      Parameters:
      value - the date value to convert
      Returns:
      the date in ISO8601 format. If the input is null valued, the empty string is returned.
    • normalizeMillisSinceMidnight

      public static int normalizeMillisSinceMidnight(long millis)
      Normalize elapsed milliseconds to the standard range from midnight to midnight.
      Parameters:
      millis - milliseconds elapsed since midnight
      Returns:
      the normalize milliseconds representing the same time of day
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(int hourOfDay, int minuteOfHour, int secondOfMinute)
      Gets the time, in 24-hour format, as milliseconds since midnight.
      Parameters:
      hourOfDay - the hour portion of the time
      minuteOfHour - the minutes portion of the time
      secondOfMinute - the seconds portion of the time
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(long instant)
      Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
      Parameters:
      instant - the instant in time to convert
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(long millis, ZoneId zoneId)
      Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
      Parameters:
      millis - the instant in time to convert
      zoneId - the time zone id relative to which to interpret the instant
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(long instant, int offset)
      Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
      Parameters:
      instant - the instant in time to convert
      offset - the time zone offset with which to interpret the instant
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(Date time)
      Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
      Parameters:
      time - the instant in time to convert
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(LocalDate localDate)
      Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
      Parameters:
      time - the instant in time to convert
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(LocalDate localDate, ZoneId zoneId)
      Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.
      Parameters:
      time - the instant in time to convert
      Returns:
      the number of milliseconds elapsed since midnight
    • toMillisSinceMidnight

      public static int toMillisSinceMidnight(Date time, ZoneId zoneId)
      Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.
      Parameters:
      time - the instant in time to convert
      zoneId - the time zone id relative to which to interpret the instant
      Returns:
      the number of milliseconds elapsed since midnight
    • toTime

      public static LocalTime toTime(long dayMillis)
      Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.
      Parameters:
      dayMillis - the number of milliseconds elapsed since midnight
      Returns:
      a LocalTime object representing the time of day
    • localTimeToSeconds

      public static int localTimeToSeconds(LocalTime localTime)
      Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.
      Parameters:
      localTime - the localTime
      Returns:
      millis since epoch
    • parseToMillisSinceMidnight

      public static int parseToMillisSinceMidnight(String text)
      Parses a time of day in ISO8601 time format into milliseconds since midnight.
      Parameters:
      text - a time of day in ISO8601 format
      Returns:
      the number of milliseconds elapsed since midnight
    • parseInto

      public static void parseInto(String text, TimeSettable buffer)
      Parses a time of day in ISO8601 time format, storing the result into a time valued container. The empty string is parsed as a null value.
      Parameters:
      text - a time of day in ISO8601 format.
      buffer - the container in which to store the parsed value
    • formatMillisSinceMidnight

      public static String formatMillisSinceMidnight(int dayMillis)
      Converts a time of day, expressed as milliseconds, into an ISO8601 time formatted string.
      Parameters:
      dayMillis - the number of milliseconds elapsed since midnight
      Returns:
      the time of day in ISO8601 format
    • format

      public static String format(TimeValued value)
      Converts a time of day value into an ISO8601 time formatted string.
      Parameters:
      value - the time value to format
      Returns:
      the time of day in ISO8601 format. If the input is null valued, the empty string is returned.
    • toEpochTime

      public static void toEpochTime(long millis, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the default time zone for the offset.
      Parameters:
      millis - the instant in time to convert
      buffer - the container into which to store the value
    • toEpochTime

      public static void toEpochTime(long millis, ZoneId zoneId, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the specified time zone for the offset.
      Parameters:
      millis - the instant in time to convert
      zoneId - the time zone Id relative to which to interpret the instant
      buffer - the container into which to store the value
    • toEpochTime

      public static void toEpochTime(Date date, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the default time zone for the offset. Nanosecond precision in the source value will be preserved, if present.
      Parameters:
      date - the instant in time to convert
      buffer - the container into which to store the value
    • toEpochTime

      public static void toEpochTime(Date date, ZoneId zoneId, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the specified time zone for the offset. Nanosecond precision in the source value will be preserved, if present.
      Parameters:
      date - the instant in time to convert
      zoneId - the time zone Id relative to which to interpret the instant
      buffer - the container into which to store the value
    • toEpochTime

      public static void toEpochTime(Timestamp timestamp, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the default time zone for the offset. The nanosecond precision of the source value is preserved.
      Parameters:
      timestamp - the instant in time to convert
      buffer - the container into which to store the value
    • toEpochTime

      public static void toEpochTime(Timestamp timestamp, ZoneId zoneId, TimestampSettable buffer)
      Stores the given instant into a time stamp buffer using the specified time zone for the offset. The nanosecond precision of the source value is preserved.
      Parameters:
      timestamp - the instant in time to convert
      zoneId - the time zone id relative to which to interpret the instant
      buffer - the container into which to store the value
    • toTimestamp

      public static Timestamp toTimestamp(long epochSecs, int subsecNanos, int offsetSecs)
      Gets the instant in time on corresponding to the specified epoch time.
      Parameters:
      epochSecs - number of seconds since Java epoch
      subsecNanos - fractional portion of epoch time in nanoseconds
      offsetSecs - time zone + daylight saving time offset in seconds
      Returns:
      a Timestamp object representing the time stamp
    • parseInto

      public static void parseInto(String text, TimestampSettable buffer)
      Parses a timestamp in ISO8601 format, storing the result into a timestamp valued container. The empty string is parsed as a null value.
      Parameters:
      text - a timestamp in ISO8601 format.
      buffer - the container in which to store the parsed value
    • formatEpochTime

      public static String formatEpochTime(long seconds, int nanos, int offsetSecs)
      Converts a time stamp, expressed as component values, into an ISO8601 time stamp formatted string.
      Parameters:
      seconds - number of seconds since Java epoch
      nanos - fractional portion of epoch time in nanoseconds
      offsetSeconds - time zone and daylight saving time offset, in seconds
      Returns:
      the time stamp in ISO8601 format
    • format

      public static String format(TimestampValued value)
      Converts a time stamp value into an ISO8601 time stamp formatted string.
      Parameters:
      value - the time stamp value to format
      Returns:
      the time stamp in ISO8601 format. If the input is null valued, the empty string is returned.
    • getDefaultTimeZone

      public static ZoneId getDefaultTimeZone()
    • withCSTTimeZone

      public static void withCSTTimeZone(Runnable runnable)