Class DBTimeUtils

java.lang.Object
com.illumon.iris.db.tables.utils.DBTimeUtils

public class DBTimeUtils
extends Object
Utilities for Deephaven date/time storage and manipulation.
  • Field Details

  • Constructor Details

  • Method Details

    • millis

      public static long millis​(DBDateTime dateTime)
      Returns milliseconds since Epoch for a DBDateTime value.
      Parameters:
      dateTime - The DBDateTime for which the milliseconds offset should be returned.
      Returns:
      A long value of milliseconds since Epoch, or a QueryConstants.NULL_LONG value if the DBDateTime is null.
    • nanos

      public static long nanos​(DBDateTime dateTime)
      Returns nanoseconds since Epoch for a DBDateTime value.
      Parameters:
      dateTime - The DBDateTime for which the nanoseconds offset should be returned.
      Returns:
      A long value of nanoseconds since Epoch, or a NULL_LONG value if the DBDateTime is null.
    • isBefore

      public static boolean isBefore​(DBDateTime d1, DBDateTime d2)
      Evaluates whether one DBDateTime value is earlier than a second DBDateTime value.
      Parameters:
      d1 - The first DBDateTime value to compare.
      d2 - The second DBDateTime value to compare.
      Returns:
      Boolean true if d1 is earlier than d2, false if either value is null, or if d2 is equal to or earlier than d1.
    • isAfter

      public static boolean isAfter​(DBDateTime d1, DBDateTime d2)
      Evaluates whether one DBDateTime value is later than a second DBDateTime value.
      Parameters:
      d1 - The first DBDateTime value to compare.
      d2 - The second DBDateTime value to compare.
      Returns:
      Boolean true if d1 is later than d2, false if either value is null, or if d2 is equal to or later than d1.
    • plus

      public static DBDateTime plus​(DBDateTime dateTime, long nanos)
      Adds one time from another.
      Parameters:
      dateTime - The starting DBDateTime value.
      nanos - The long number of nanoseconds to add to dateTime.
      Returns:
      a null DBDateTime if either input is null; the starting DBDateTime plus the specified number of nanoseconds, if the result is not too large for a DBDateTime; or throws a DBDateTimeOverflowException if the resultant value is more than max long nanoseconds from Epoch.
    • minus

      public static DBDateTime minus​(DBDateTime dateTime, long nanos)
      Subtracts one time from another.
      Parameters:
      dateTime - The starting DBDateTime value.
      nanos - The long number of nanoseconds to subtract from dateTime.
      Returns:
      a null DBDateTime if either input is null; the starting DBDateTime minus the specified number of nanoseconds, if the result is not too negative for a DBDateTime; or throws a DBDateTimeOverflowException if the resultant value is more than min long nanoseconds from Epoch.
    • plus

      public static DBDateTime plus​(DBDateTime dateTime, DBPeriod period)
      Adds one time from another.
      Parameters:
      dateTime - The starting DBDateTime value.
      period - The DBPeriod to add to dateTime.
      Returns:
      a null DBDateTime if either input is null; the starting DBDateTime plus the specified period, if the result is not too large for a DBDateTime; or throws a DBDateTimeOverflowException if the resultant value is more than max long nanoseconds from Epoch.
    • minus

      public static DBDateTime minus​(DBDateTime dateTime, DBPeriod period)
      Subtracts one time from another.
      Parameters:
      dateTime - The starting DBDateTime value.
      period - The DBPeriod to subtract from dateTime.
      Returns:
      a null DBDateTime if either input is null; the starting DBDateTime minus the specified period, if the result is not too negative for a DBDateTime; or throws a DBDateTimeOverflowException if the resultant value is more than min long nanoseconds from Epoch.
    • minus

      public static long minus​(DBDateTime d1, DBDateTime d2)
      Subtracts one time from another.
      Parameters:
      d1 - The first DBDateTime.
      d2 - The DBDateTime to subtract from d1.
      Returns:
      QueryConstants.NULL_LONG if either input is null; the long nanoseconds from Epoch value of the first DBDateTime minus d2, if the result is not out of range for a long value; or throws a DBDateTimeOverflowException if the resultant value would be more than min long or max long nanoseconds from Epoch.

      Note that the subtraction is done based the nanosecond offsets of the two dates from Epoch, so, if either date is before Epoch (negative offset), the result may be unexpected.

    • diff

      @Deprecated public static long diff​(DBDateTime d1, DBDateTime d2)
      Deprecated.
    • yearDiff

      @Deprecated public static double yearDiff​(DBDateTime start, DBDateTime end)
      Deprecated.
    • dayDiff

      @Deprecated public static double dayDiff​(DBDateTime start, DBDateTime end)
      Deprecated.
    • diffNanos

      public static long diffNanos​(DBDateTime d1, DBDateTime d2)
      Returns the difference in nanoseconds between two DBDateTime values.
      Parameters:
      d1 - The first DBDateTime.
      d2 - The second DBDateTime.
      Returns:
      QueryConstants.NULL_LONG if either input is null; the long nanoseconds from Epoch value of the first DBDateTime minus d2, if the result is not out of range for a long value; or throws a DBDateTimeOverflowException if the resultant value would be more than min long or max long nanoseconds from Epoch.

      Note that the subtraction is done based the nanosecond offsets of the two dates from Epoch, so, if either date is before Epoch (negative offset), the result may be unexpected.

      If the second value is greater than the first value, the result will be negative.
    • diffYear

      public static double diffYear​(DBDateTime start, DBDateTime end)
      Returns a double value of the number of 365 day units difference between two DBDateTime values.
      Parameters:
      start - The first DBDateTime.
      end - The second DBDateTime.
      Returns:
      QueryConstants.NULL_LONG if either input is null; a double value of the number of 365 day periods obtained from the first DBDateTime value minus d2, if the intermediate value of nanoseconds difference between the two dates is not out of range for a long value; or throws a DBTimeUtils.DBDateTimeOverflowException if the intermediate value would be more than min long or max long nanoseconds from Epoch.

      Note that the subtraction is done based the nanosecond offsets of the two dates from Epoch, so, if either date is before Epoch (negative offset), the result may be unexpected.

      If the second value is greater than the first value, the result will be negative.
    • diffDay

      public static double diffDay​(DBDateTime start, DBDateTime end)
      Returns a double value of the number of days difference between two DBDateTime values.
      Parameters:
      start - The first DBDateTime.
      end - The second DBDateTime.
      Returns:
      QueryConstants.NULL_LONG if either input is null; a double value of the number of days obtained from the first DBDateTime value minus d2, if the intermediate value of nanoseconds difference between the two dates is not out of range for a long value; or throws a DBDateTimeOverflowException if the intermediate value would be more than min long or max long nanoseconds from Epoch.

      Note that the subtraction is done based the nanosecond offsets of the two dates from Epoch, so, if either date is before Epoch (negative offset), the result may be unexpected.

      If the second value is greater than the first value, the result will be negative.
    • dateAtMidnight

      public static DBDateTime dateAtMidnight​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns a DBDateTime for the requested DBDateTime at midnight in the specified time zone.
      Parameters:
      dateTime - DBDateTime for which the new value at midnight should be calculated.
      timeZone - DBTimeZone for which the new value at midnight should be calculated.
      Returns:
      A null DBDateTime if either input is null, otherwise a DBDateTime representing midnight for the date and time zone of the inputs.
    • millisToDateAtMidnightNy

      public static DBDateTime millisToDateAtMidnightNy​(long millis)
      Returns a DBDateTime representing midnight in New York time zone on the date specified by the a number of milliseconds from Epoch.
      Parameters:
      millis - A long value of the number of milliseconds from Epoch for which the DBDateTime is to be calculated.
      Returns:
      A DBDateTime rounded down to midnight in the New York time zone for the specified number of milliseconds from Epoch.
    • millisToDateAtMidnight

      public static DBDateTime millisToDateAtMidnight​(long millis, DBTimeZone timeZone)
      Returns a DBDateTime representing midnight in a selected time zone on the date specified by a number of milliseconds from Epoch.
      Parameters:
      millis - A long value of the number of milliseconds from Epoch for which the DBDateTime is to be calculated.
      timeZone - DBTimeZone for which the new value at midnight should be calculated.
      Returns:
      A DBDateTime rounded down to midnight in the selected time zone for the specified number of milliseconds from Epoch.
    • format

      public static String format​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns a String date/time representation.
      Parameters:
      dateTime - The DBDateTime to format as a String.
      timeZone - The DBTimeZone to use when formatting the String.
      Returns:
      A null String if either input is null, otherwise a String formatted as yyyy-MM-ddThh:mm:ss.nnnnnnnnn TZ.
    • formatNy

      public static String formatNy​(DBDateTime dateTime)
      Returns a String date/time representation of a DBDateTime interpreted for the New York time zone.
      Parameters:
      dateTime - The DBDateTime to format as a String.
      Returns:
      A null String if the input is null, otherwise a String formatted as yyyy-MM-ddThh:mm:ss.nnnnnnnnn NY.
    • formatDate

      public static String formatDate​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns a String date representation of a DBDateTime interpreted for a specified time zone.
      Parameters:
      dateTime - The DBDateTime to format as a String.
      timeZone - The DBTimeZone to use when formatting the String.
      Returns:
      A null String if either input is null, otherwise a String formatted as yyyy-MM-dd.
    • formatDateNy

      public static String formatDateNy​(DBDateTime dateTime)
      Returns a String date representation of a DBDateTime interpreted for the New York time zone.
      Parameters:
      dateTime - The DBDateTime to format as a String.
      Returns:
      A null String if the input is null, otherwise a String formatted as yyyy-MM-dd.
    • format

      public static String format​(long nanos)
      Returns a String date/time representation.
      Parameters:
      nanos - The long number of nanoseconds offset from Epoch.
      Returns:
      A String of varying format depending on the offset.

      For values greater than one day, the output will start with dddT

      For values with fractional seconds, the output will be trailed by .nnnnnnnnn

      e.g. output may be dddThh:mm:ss.nnnnnnnnn or subsets of this.

    • dayOfMonth

      public static int dayOfMonth​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the day of the month for a DBDateTime and specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the month.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the day of the month represented by the DBDateTime when interpreted in the specified time zone.
    • dayOfMonthNy

      public static int dayOfMonthNy​(DBDateTime dateTime)
      Returns an int value of the day of the month for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the month.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of the day of the month represented by the DBDateTime when interpreted in the New York time zone.
    • dayOfWeek

      public static int dayOfWeek​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the day of the week for a DBDateTime in the specified time zone, with 1 being Monday and 7 being Sunday.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the week.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the day of the week represented by the DBDateTime when interpreted in the specified time zone.
    • dayOfWeekNy

      public static int dayOfWeekNy​(DBDateTime dateTime)
      Returns an int value of the day of the week for a DBDateTime in the New York time zone, with 1 being Monday and 7 being Sunday.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the week.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of the day of the week represented by the DBDateTime when interpreted in the New York time zone.
    • dayOfYear

      public static int dayOfYear​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the day of the year (Julian date) for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the year.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the day of the year represented by the DBDateTime when interpreted in the specified time zone.
    • dayOfYearNy

      public static int dayOfYearNy​(DBDateTime dateTime)
      Returns an int value of the day of the year (Julian date) for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the day of the year.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of the day of the year represented by the DBDateTime when interpreted in the New York time zone.
    • hourOfDay

      public static int hourOfDay​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the hour of the day for a DBDateTime in the specified time zone. The hour is on a 24 hour clock (0 - 23).
      Parameters:
      dateTime - The DBDateTime for which to find the hour of the day.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the hour of the day represented by the DBDateTime when interpreted in the specified time zone.
    • hourOfDayNy

      public static int hourOfDayNy​(DBDateTime dateTime)
      Returns an int value of the hour of the day for a DBDateTime in the New York time zone. The hour is on a 24 hour clock (0 - 23).
      Parameters:
      dateTime - The DBDateTime for which to find the hour of the day.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of the hour of the day represented by the DBDateTime when interpreted in the New York time zone.
    • millisOfDay

      public static int millisOfDay​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of milliseconds since midnight for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the milliseconds since midnight.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of milliseconds since midnight for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • millisOfDayNy

      public static int millisOfDayNy​(DBDateTime dateTime)
      Returns an int value of milliseconds since midnight for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the milliseconds since midnight.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of milliseconds since midnight for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • millisOfSecond

      public static int millisOfSecond​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of milliseconds since the top of the second for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the milliseconds.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of milliseconds since the top of the second for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • millisOfSecondNy

      public static int millisOfSecondNy​(DBDateTime dateTime)
      Returns an int value of milliseconds since the top of the second for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the milliseconds.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of milliseconds since the top of the second for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • nanosOfDay

      public static long nanosOfDay​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns a long value of nanoseconds since midnight for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the nanoseconds since midnight.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_LONG if either input is null, otherwise, a long value of nanoseconds since midnight for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • nanosOfDayNy

      public static long nanosOfDayNy​(DBDateTime dateTime)
      Returns a long value of nanoseconds since midnight for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the nanoseconds since midnight.
      Returns:
      A QueryConstants.NULL_LONG if the input is null, otherwise, a long value of nanoseconds since midnight for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • nanosOfSecond

      public static long nanosOfSecond​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns a long value of nanoseconds since the top of the second for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the nanoseconds.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_LONG if either input is null, otherwise, a long value of nanoseconds since the top of the second for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • nanosOfSecondNy

      public static long nanosOfSecondNy​(DBDateTime dateTime)
      Returns a long value of nanoseconds since the top of the second for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the nanoseconds.
      Returns:
      A QueryConstants.NULL_LONG if the input is null, otherwise, a long value of nanoseconds since the top of the second for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • microsOfMilli

      public static int microsOfMilli​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provided dateTime in the specified time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.
      Parameters:
      dateTime - The DBDateTime for which to find the microseconds.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of microseconds since the top of the millisecond for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • microsOfMilliNy

      public static int microsOfMilliNy​(DBDateTime dateTime)
      Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provided dateTime in the New York time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.
      Parameters:
      dateTime - The DBDateTime for which to find the microseconds.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of microseconds since the top of the millisecond for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • minuteOfDay

      public static int minuteOfDay​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of minutes since midnight for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the minutes.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of minutes since midnight for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • minuteOfDayNy

      public static int minuteOfDayNy​(DBDateTime dateTime)
      Returns an int value of minutes since midnight for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the milliseconds since midnight.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of minutes since midnight for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • minuteOfHour

      public static int minuteOfHour​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of minutes since the top of the hour for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the minutes.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of minutes since the top of the hour for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • minuteOfHourNy

      public static int minuteOfHourNy​(DBDateTime dateTime)
      Returns an int value of minutes since the top of the hour for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the minutes.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of minutes since the top of the hour for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • monthOfYear

      public static int monthOfYear​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value for the month of a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the month.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the month for the date/time represented by the DBDateTime when interpreted in the specified time zone. January is 1, February is 2, etc.
    • monthOfYearNy

      public static int monthOfYearNy​(DBDateTime dateTime)
      Returns an int value for the month of a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the month.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of the month for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • secondOfDay

      public static int secondOfDay​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of seconds since midnight for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the seconds.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of seconds since midnight for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • secondOfDayNy

      public static int secondOfDayNy​(DBDateTime dateTime)
      Returns an int value of seconds since midnight for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the seconds.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of seconds since midnight for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • secondOfMinute

      public static int secondOfMinute​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of seconds since the top of the minute for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the seconds.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of seconds since the top of the minute for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • secondOfMinuteNy

      public static int secondOfMinuteNy​(DBDateTime dateTime)
      Returns an int value of seconds since the top of the minute for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the seconds.
      Returns:
      A QueryConstants.NULL_INT if the input is null, otherwise, an int value of seconds since the top of the minute for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • year

      public static int year​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the year for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the year.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the year for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • yearNy

      public static int yearNy​(DBDateTime dateTime)
      Returns an int value of the year for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the year.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the year for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • yearOfCentury

      public static int yearOfCentury​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns an int value of the two-digit year for a DBDateTime in the specified time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the year.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the two-digit year for the date/time represented by the DBDateTime when interpreted in the specified time zone.
    • yearOfCenturyNy

      public static int yearOfCenturyNy​(DBDateTime dateTime)
      Returns an int value of the two-digit year for a DBDateTime in the New York time zone.
      Parameters:
      dateTime - The DBDateTime for which to find the year.
      Returns:
      A QueryConstants.NULL_INT if either input is null, otherwise, an int value of the two-digit year for the date/time represented by the DBDateTime when interpreted in the New York time zone.
    • getExcelDateTime

      public static double getExcelDateTime​(DBDateTime dateTime, DBTimeZone timeZone)
      Returns the Excel double time format representation of a DBDateTime.
      Parameters:
      dateTime - The DBDateTime to convert.
      timeZone - The DBTimeZone to use when interpreting the date/time.
      Returns:
      0.0 if either input is null, otherwise, a double value containing the Excel double format representation of a DBDateTime in the specified time zone.
    • getExcelDateTime

      public static double getExcelDateTime​(DBDateTime dateTime, TimeZone timeZone)
      Returns the Excel double time format representation of a DBDateTime.
      Parameters:
      dateTime - The DBDateTime to convert.
      timeZone - The TimeZone to use when interpreting the date/time.
      Returns:
      0.0 if either input is null, otherwise, a double value containing the Excel double format representation of a DBDateTime in the specified time zone.
    • getExcelDateTime

      public static double getExcelDateTime​(DBDateTime dateTime)
      Returns the Excel double time format representation of a DBDateTime.
      Parameters:
      dateTime - The DBDateTime to convert.
      Returns:
      0.0 if the input is null, otherwise, a double value containing the Excel double format representation of a DBDateTime in the New York time zone.
    • microsToNanos

      public static long microsToNanos​(long micros)
      Converts microseconds to nanoseconds.
      Parameters:
      micros - The long value of microseconds to convert.
      Returns:
      A QueryConstants.NULL_LONG if the input is null. Throws a DBTimeUtils.DBDateTimeOverflowException if the resultant value would exceed the range that can be stored in a long. Otherwise, returns a long containing the equivalent number of nanoseconds for the input in microseconds.
    • nanosToMicros

      public static long nanosToMicros​(long nanos)
      Converts nanoseconds to microseconds.
      Parameters:
      nanos - The long value of nanoseconds to convert.
      Returns:
      A QueryConstants.NULL_LONG if the input is null. Otherwise, returns a long containing the equivalent number of microseconds for the input in nanoseconds.
    • microsToTime

      public static DBDateTime microsToTime​(long micros)
      Converts a value of microseconds from Epoch in the UTC time zone to a DBDateTime.
      Parameters:
      micros - The long microseconds value to convert.
      Returns:
      QueryConstants.NULL_LONG if the input is null, otherwise, a DBDateTime representation of the input.
    • millisToNanos

      public static long millisToNanos​(long millis)
      Converts milliseconds to nanoseconds.
      Parameters:
      millis - The long milliseconds value to convert.
      Returns:
      QueryConstants.NULL_LONG if the input is equal to QueryConstants.NULL_LONG. Throws DBTimeUtils.DBDateTimeOverflowException if the input is too large for conversion. Otherwise returns a long of the equivalent number of nanoseconds to the input.
    • secondsToNanos

      public static long secondsToNanos​(long seconds)
      Converts seconds to nanoseconds.
      Parameters:
      seconds - The long value of seconds to convert.
      Returns:
      A QueryConstants.NULL_LONG if the input is null. Throws a DBTimeUtils.DBDateTimeOverflowException if the resultant value would exceed the range that can be stored in a long. Otherwise, returns a long containing the equivalent number of nanoseconds for the input in seconds.
    • nanosToMillis

      public static long nanosToMillis​(long nanos)
      Converts nanoseconds to milliseconds.
      Parameters:
      nanos - The long value of nanoseconds to convert.
      Returns:
      A QueryConstants.NULL_LONG if the input is null. Otherwise, returns a long containing the equivalent number of milliseconds for the input in nanoseconds.
    • millisToTime

      public static DBDateTime millisToTime​(long millis)
      Converts a value of milliseconds from Epoch in the UTC time zone to a DBDateTime.
      Parameters:
      millis - The long milliseconds value to convert.
      Returns:
      QueryConstants.NULL_LONG if the input is null, otherwise, a DBDateTime representation of the input.
    • secondsToTime

      public static DBDateTime secondsToTime​(long seconds)
      Converts a value of seconds from Epoch in the UTC time zone to a DBDateTime.
      Parameters:
      seconds - The long seconds value to convert.
      Returns:
      QueryConstants.NULL_LONG if the input is null, otherwise, a DBDateTime representation of the input.
    • toEpochNano

      public static long toEpochNano​(@Nullable Instant value)
      Convert the specified instant to nanoseconds since epoch, or null.
      Parameters:
      value - the instant to convert
      Returns:
      nanoseconds since epoch or null
    • toEpochNano

      public static long toEpochNano​(@Nullable ZonedDateTime value)
      Convert the specified ZonedDateTime to nanoseconds since epoch, or null.
      Parameters:
      value - the instant to convert
      Returns:
      nanoseconds since epoch or null
    • makeInstant

      @Nullable public static Instant makeInstant​(long nanos)
      Convert nanos since epoch to an Instant value.
      Parameters:
      nanos - nanoseconds since epoch
      Returns:
      a new Instant or null if nanos was QueryConstants.NULL_LONG.
    • makeZonedDateTime

      @Nullable public static ZonedDateTime makeZonedDateTime​(long nanos)
      Converts nanos of epoch to a ZonedDateTime using the default time zone.
      Parameters:
      nanos - nanoseconds since epoch
      Returns:
      a new ZonedDateTime or null if nanos was QueryConstants.NULL_LONG.
    • makeZonedDateTime

      @Nullable public static ZonedDateTime makeZonedDateTime​(long nanos, @NotNull DBTimeZone timeZone)
      Converts nanos of epoch to a ZonedDateTime.
      Parameters:
      nanos - nanoseconds since epoch
      timeZone - the time zone
      Returns:
      a new ZonedDateTime or null if nanos was QueryConstants.NULL_LONG.
    • makeZonedDateTime

      @Nullable public static ZonedDateTime makeZonedDateTime​(long nanos, ZoneId zone)
      Converts nanos of epoch to a ZonedDateTime.
      Parameters:
      nanos - nanoseconds since epoch
      zone - the time zone
      Returns:
      a new ZonedDateTime or null if nanos was QueryConstants.NULL_LONG.
    • getZonedDateTime

      @Nullable public static ZonedDateTime getZonedDateTime​(@Nullable DBDateTime dateTime)
      Converts a DBDateTime to a ZonedDateTime.
      Parameters:
      dateTime - The a DBDateTime to convert.
      Returns:
      A ZonedDateTime using the default time zone for the session as indicated by DBTimeZone.TZ_DEFAULT.
    • getZonedDateTime

      @Nullable public static ZonedDateTime getZonedDateTime​(@Nullable DBDateTime dateTime, @NotNull DBTimeZone timeZone)
      Converts a DBDateTime to a ZonedDateTime.
      Parameters:
      dateTime - The a DBDateTime to convert.
      timeZone - The DBTimeZone to use for the conversion.
      Returns:
      A ZonedDateTime using the specified time zone. or null if dateTime was null
    • getZonedDateTime

      @Nullable public static ZonedDateTime getZonedDateTime​(@Nullable DBDateTime dateTime, @NotNull ZoneId timeZone)
      Converts a DBDateTime to a ZonedDateTime.
      Parameters:
      dateTime - The a DBDateTime to convert.
      timeZone - The ZoneId to use for the conversion.
      Returns:
      A ZonedDateTime using the specified time zone. or null if dateTime was null
    • toDateTime

      @Nullable public static DBDateTime toDateTime​(@Nullable ZonedDateTime zonedDateTime)
      Converts a ZonedDateTime to a DBDateTime.
      Parameters:
      zonedDateTime - The a ZonedDateTime to convert.
      Throws:
      DBTimeUtils.DBDateTimeOverflowException - if the input is out of the range for a DBDateTime, otherwise, a DBDateTime version of the input.
    • currentTime

      public static DBDateTime currentTime()
      Provides the current date/time, or, if a custom timeProvider has been configured, provides the current time according to the custom provider.
      Returns:
      A DBDateTime of the current date and time from the system or from the configured alternate time provider.
    • currentDateNy

      public static String currentDateNy()
      Provides a String representing the current date in the New York time zone or, if a custom currentDateNyOverride has been set, the date provided by that override.
      Returns:
      A String in yyyy-MM-dd format.
    • consistentDateNy

      public static String consistentDateNy()
    • overrideLastBusinessDateNyFromCurrentDateNy

      public static void overrideLastBusinessDateNyFromCurrentDateNy()
      Sets the lastBusinessDayNyOverride to the previous business day from a currently set currentDateNyOverride value. If currentDateNyOverride has not been set, this method has no effect.
    • lastBusinessDateNy

      public static String lastBusinessDateNy()
      Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a custom lastBusinessDayNyOverride has been set, the date provided by that override.
      Returns:
      A String in yyyy-MM-dd format.
    • lastBusinessDateNy

      public static String lastBusinessDateNy​(long currentTimeMillis)
      Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a custom lastBusinessDayNyOverride has been set, the date provided by that override.
      Parameters:
      currentTimeMillis - The current date/time in milliseconds from Epoch to be used when determining the previous business date. Typically this is System.currentTimeMillis() and is passed in by calling the niladic variant of this method.
      Returns:
      A String in yyyy-MM-dd format.
    • currentDate

      public static String currentDate​(DBTimeZone timeZone)
      Returns a String of the current date in the specified DBTimeZone.
      Parameters:
      timeZone - The DBTimeZone to reference when evaluating the current date for "now".
      Returns:
      A String in format yyyy-MM-dd.
    • nanosToTime

      public static DBDateTime nanosToTime​(long nanos)
      Converts a value of nanoseconds from Epoch to a DBDateTime.
      Parameters:
      nanos - The long nanoseconds since Epoch value to convert.
      Returns:
      A DBDateTime for nanos, or null if nanos is equal to NULL_LONG.
    • autoEpochToTime

      public static DBDateTime autoEpochToTime​(long epoch)
      Converts a long offset from Epoch value to a DBDateTime. This method uses expected date ranges to infer whether the passed value is in milliseconds, microseconds, or nanoseconds. Thresholds used are TimeConstants.MICROTIME_THRESHOLD divided by 1000 for milliseconds, as-is for microseconds, and multiplied by 1000 for nanoseconds. The value is tested to see if its ABS exceeds the threshold. E.g. a value whose ABS is greater than 1000 * TimeConstants.MICROTIME_THRESHOLD will be treated as nanoseconds.
      Parameters:
      epoch - The long Epoch offset value to convert.
      Returns:
      null, if the input is equal to QueryConstants.NULL_LONG, otherwise a DBDateTime based on the inferred conversion.
    • cappedTimeOffset

      public static DBDateTime cappedTimeOffset​(DBDateTime original, DBPeriod period, DBDateTime cap)
      Returns a DBDateTime value based on a starting value and a DBPeriod to add to it, but with a cap max value which is returned in case the starting value plus period exceeds the cap.
      Parameters:
      original - The starting DBDateTime value.
      period - The DBPeriod to add to dateTime.
      cap - A DBDateTime value to use as the maximum return value.
      Returns:
      a null DBDateTime if either original or period are null; the starting DBDateTime plus the specified period, if the result is not too large for a DBDateTime and does not exceed the cap value; the cap value if this is less than offset plus period. Throws a DBDateTimeOverflowException if the resultant value is more than max long nanoseconds from Epoch.
    • lowerBin

      public static DBDateTime lowerBin​(DBDateTime dateTime, long intervalNanos)
      Returns a DBDateTime value, which is at the starting (lower) end of a time range defined by the interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the date/time value for the start of the five minute window that contains the input date time.
      Parameters:
      dateTime - The DBDateTime for which to evaluate the start of the containing window.
      intervalNanos - The size of the window in nanoseconds.
      Returns:
      Null if either input is null, otherwise a DBDateTime representing the start of the window.
    • lowerBin

      public static DBDateTime lowerBin​(DBDateTime dateTime, long intervalNanos, long offset)
      Returns a DBDateTime value, which is at the starting (lower) end of a time range defined by the interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the date/time value for the start of the five minute window that contains the input date time.
      Parameters:
      dateTime - The DBDateTime for which to evaluate the start of the containing window.
      intervalNanos - The size of the window in nanoseconds.
      offset - The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute.
      Returns:
      Null if either input is null, otherwise a DBDateTime representing the start of the window.
    • upperBin

      public static DBDateTime upperBin​(DBDateTime dateTime, long intervalNanos)
      Returns a DBDateTime value, which is at the ending (upper) end of a time range defined by the interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the date/time value for the end of the five minute window that contains the input date time.
      Parameters:
      dateTime - The DBDateTime for which to evaluate the end of the containing window.
      intervalNanos - The size of the window in nanoseconds.
      Returns:
      Null if either input is null, otherwise a DBDateTime representing the end of the window.
    • upperBin

      public static DBDateTime upperBin​(DBDateTime dateTime, long intervalNanos, long offset)
      Returns a DBDateTime value, which is at the ending (upper) end of a time range defined by the interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the date/time value for the end of the five minute window that contains the input date time.
      Parameters:
      dateTime - The DBDateTime for which to evaluate the end of the containing window.
      intervalNanos - The size of the window in nanoseconds.
      offset - The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute.
      Returns:
      Null if either input is null, otherwise a DBDateTime representing the end of the window.
    • convertExpression

      public static DBTimeUtils.Result convertExpression​(String formula) throws Exception
      Converts an expression, replacing DBDateTime and DBPeriod literals with references to constant DBDateTime/DBPeriod instances.
      Parameters:
      formula - The formula to convert.
      Returns:
      A DBTimeUtils.Result object, which includes the converted formula string, a string of instance variable declarations, and a map describing the names and types of these instance variables.
      Throws:
      Exception - If any error occurs or a literal value cannot be parsed.
    • expressionToNanos

      public static long expressionToNanos​(String formula)
      Converts a String date/time to nanoseconds from Epoch or a nanoseconds period. Three patterns are supported:

      yyyy-MM-ddThh:mm:ss[.nnnnnnnnn] TZ for date/time values

      hh:mm:ss[.nnnnnnnnn] for time values

      Period Strings in the form of numbertype, e.g. 1W for one week, and Tnumbertype for times, e.g. T1M for one minute

      Parameters:
      formula - The String to be evaluated and converted. Optionally, but preferred, enclosed in straight single ticks.
      Returns:
      A long value representing an Epoch offset in nanoseconds for a time or date/time, or a duration in nanoseconds for a period. Throws DBTimeUtils.DBDateTimeOverflowException if the resultant value would be longer than max long, or IllegalArgumentException if expression cannot be evaluated.
    • convertDate

      public static LocalDate convertDate​(String s)
      Attempt to convert the given string to a LocalDate. This should not accept dates with times, as we want those to be interpreted as DBDateTime values. The ideal date format is YYYY-MM-DD since it's the least ambiguous, but this method also parses slash-delimited dates according to the system "date style".
      Parameters:
      s - the date string to convert
      Throws:
      RuntimeException - if the date cannot be converted, otherwise returns a LocalDate
    • convertDateTime

      public static DBDateTime convertDateTime​(String s)
      Converts a DateTime String from a few specific zoned formats to a DBDateTime
      Parameters:
      s - String to be converted, usually in the form yyyy-MM-ddThh:mm:ss and with optional sub-seconds after an optional decimal point, followed by a mandatory time zone character code
      Throws:
      RuntimeException - if the String cannot be converted, otherwise a DBDateTime from the parsed String.
    • convertTime

      public static long convertTime​(String s)
      Converts a String time to nanoseconds from Epoch. The format for the String is:

      hh:mm:ss[.nnnnnnnnn].

      Parameters:
      s - The String to be evaluated and converted.
      Returns:
      A long value representing an Epoch offset in nanoseconds. Throws RuntimeException if the String cannot be parsed.
    • convertPeriod

      public static DBPeriod convertPeriod​(String s)
      Converts a String into a DBPeriod object.
      Parameters:
      s - The String to convert in the form of numbertype, e.g. 1W for one week, and Tnumbertype for times, e.g. T1M for one minute.
      Throws:
      RuntimeException - if the String cannot be parsed, otherwise a DBPeriod object.
    • convertLocalTimeQuiet

      public static LocalTime convertLocalTimeQuiet​(String s)
      Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to a LocalTime.
      Parameters:
      s - The String to convert.
      Returns:
      null if the String cannot be parsed, otherwise a LocalTime.
    • convertDateQuiet

      public static LocalDate convertDateQuiet​(String s)
      Attempt to convert the given string to a LocalDate. This should not accept dates with times, as we want those to be interpreted as DBDateTime values. The ideal date format is YYYY-MM-DD since it's the least ambiguous.
      Parameters:
      s - the date string to convert
      Returns:
      the LocalDate formatted using the default date style.
    • convertDateQuiet

      public static LocalDate convertDateQuiet​(String s, DBTimeUtils.DateStyle dateStyle)
      Attempt to convert the given string to a LocalDate. This should not accept dates with times, as we want those to be interpreted as DBDateTime values. The ideal date format is YYYY-MM-DD since it's the least ambiguous.
      Parameters:
      s - the date string
      dateStyle - indicates how to interpret slash-delimited dates
      Returns:
      the LocalDate
    • convertJimDateTimeQuiet

      @Deprecated public static DBDateTime convertJimDateTimeQuiet​(String s)
      Deprecated.
    • convertJimMicrosDateTimeQuiet

      @Deprecated public static DBDateTime convertJimMicrosDateTimeQuiet​(String s)
      Deprecated.
    • convertDateTimeQuiet

      public static DBDateTime convertDateTimeQuiet​(String s)
      Converts a DateTime String from a few specific zoned formats to a DBDateTime
      Parameters:
      s - String to be converted, usually in the form yyyy-MM-ddThh:mm:ss and with optional sub-seconds after an optional decimal point, followed by a mandatory time zone character code
      Returns:
      A DBDateTime from the parsed String, or null if the format is not recognized or an exception occurs
    • convertJimMicrosDateTimeQuietFast

      @Deprecated public static DBDateTime convertJimMicrosDateTimeQuietFast​(String s, org.joda.time.DateTimeZone timeZone)
      Deprecated.
    • convertJimMicrosDateTimeQuietFastTz

      @Deprecated public static org.joda.time.DateTimeZone convertJimMicrosDateTimeQuietFastTz​(String s)
      Deprecated.
    • convertTimeQuiet

      public static long convertTimeQuiet​(String s)
      Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to a long nanoseconds offset from Epoch.
      Parameters:
      s - The String to convert.
      Returns:
      QueryConstants.NULL_LONG if the String cannot be parsed, otherwise long nanoseconds offset from Epoch.
    • convertPeriodQuiet

      public static DBPeriod convertPeriodQuiet​(String s)
      Converts a String into a DBPeriod object.
      Parameters:
      s - The String to convert in the form of numbertype, e.g. 1W for one week, and Tnumbertype for times, e.g. T1M for one minute.
      Returns:
      null if the String cannot be parsed, otherwise a DBPeriod object.
    • getFinestDefinedUnit

      public static ChronoField getFinestDefinedUnit​(String timeDef)
      Returns a ChronoField indicating the level of precision in a String time value.
      Parameters:
      timeDef - The time String to evaluate.
      Returns:
      null if the time String cannot be parsed, otherwise a ChronoField for the finest units in the String (e.g. "10:00:00" would yield SecondOfMinute).
    • createFormatter

      public static DateTimeFormatter createFormatter​(String timeZoneName)
      Create a DateTimeFormatter formatter with the specified time zone name using the standard yyyy-MM-dd format.
      Parameters:
      timeZoneName - the time zone name
      Returns:
      a formatter set for the specified time zone
    • getPartitionFromTimestampMillis

      public static String getPartitionFromTimestampMillis​(@NotNull DateTimeFormatter dateTimeFormatter, long timestampMillis)
      Given a DateTimeFormatter and a timestamp in millis, return the date as a String in standard column-partition format of yyyy-MM-dd. A timestamp of NULL_LONG means use the system current time.
      Parameters:
      dateTimeFormatter - the date formatter
      timestampMillis - the timestamp in millis
      Returns:
      the formatted date
    • getPartitionFromTimestampMicros

      public static String getPartitionFromTimestampMicros​(@NotNull DateTimeFormatter dateTimeFormatter, long timestampMicros)
      Given a DateTimeFormatter and a timestamp in micros from epoch, return the date as a String in standard column-partition format of yyyy-MM-dd. A timestamp of NULL_LONG means use the system current time.
      Parameters:
      dateTimeFormatter - the date formatter
      timestampMicros - the timestamp in micros
      Returns:
      the formatted date
    • getPartitionFromTimestampNanos

      public static String getPartitionFromTimestampNanos​(@NotNull DateTimeFormatter dateTimeFormatter, long timestampNanos)
      Given a DateTimeFormatter and a timestamp in nanos from epoch, return the date as a String in standard column-partition format of yyyy-MM-dd. A timestamp of NULL_LONG means use the system current time.
      Parameters:
      dateTimeFormatter - the date formatter
      timestampNanos - the timestamp in nanos
      Returns:
      the formatted date
    • getPartitionFromTimestampSeconds

      public static String getPartitionFromTimestampSeconds​(@NotNull DateTimeFormatter dateTimeFormatter, long timestampSeconds)
      Given a DateTimeFormatter and a timestamp in seconds from epoch, return the date as a String in standard column-partition format of yyyy-MM-dd. A timestamp of NULL_LONG means use the system current time.
      Parameters:
      dateTimeFormatter - the date formatter
      timestampSeconds - the timestamp in seconds
      Returns:
      the formatted date