Class DBTimeUtils
public class DBTimeUtils extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDBTimeUtils.DateStyleDate formatting styles for use in conversion functions such asconvertDateQuiet(String, DateStyle).static classDBTimeUtils.DBDateTimeOverflowExceptionA type of RuntimeException thrown when operations resulting inDBDateTimevalues would exceed the range available by max or min long nanoseconds.static classDBTimeUtils.ResultA container object for the result ofconvertExpression(String), which includes the converted formula String, a String of instance variable declarations, and a map describing the names and types of these instance variables. -
Field Summary
Fields Modifier and Type Field Description static StringcurrentDateNystatic StringcurrentDateNyOverrideAllows setting an alternate date instead of "today" to be returned fromcurrentDateNy.static longDAYConstant value of one day in nanoseconds.static longendOfCurrentDateNystatic longendOfCurrentDateNyLastBusinessDayExpiration for cachedlastBusinessDateNyas milliseconds from Epoch.static longHOURConstant value of one hour in nanoseconds.static StringlastBusinessDateNyCached value of lastBusinessDateNy, which expires after milliseconds from Epoch value ofendOfCurrentDateNyLastBusinessDaystatic StringlastBusinessDayNyOverrideAllows setting an alternate date instead of the business day before "today" to be returned fromlastBusinessDateNy.static longMINUTEConstant value of one minute in nanoseconds.static longSECONDConstant value of one second in nanoseconds.static TimeProvidertimeProviderAllows setting a custom time provider instead of actual current time.static longWEEKConstant value of one week in nanoseconds.static longYEARConstant value of one year (365 days) in nanoseconds. -
Constructor Summary
Constructors Constructor Description DBTimeUtils() -
Method Summary
Modifier and Type Method Description static DBDateTimeautoEpochToTime(long epoch)Converts a long offset from Epoch value to aDBDateTime.static DBDateTimecappedTimeOffset(DBDateTime original, DBPeriod period, DBDateTime cap)Returns aDBDateTimevalue based on a starting value and aDBPeriodto add to it, but with a cap max value which is returned in case the starting value plus period exceeds the cap.static StringconsistentDateNy()Convenience method invokingCompositeTableDataServiceConsistencyMonitor.consistentDateNy().static LocalDateconvertDate(String s)Attempt to convert the given string to a LocalDate.static LocalDateconvertDateQuiet(String s)Attempt to convert the given string to a LocalDate.static LocalDateconvertDateQuiet(String s, DBTimeUtils.DateStyle dateStyle)Attempt to convert the given string to a LocalDate.static DBDateTimeconvertDateTime(String s)Converts a DateTime String from a few specific zoned formats to a DBDateTimestatic DBDateTimeconvertDateTimeQuiet(String s)Converts a DateTime String from a few specific zoned formats to a DBDateTimestatic DBTimeUtils.ResultconvertExpression(String formula)Converts an expression, replacing DBDateTime and DBPeriod literals with references to constant DBDateTime/DBPeriod instances.static DBDateTimeconvertJimDateTimeQuiet(String s)Deprecated.static DBDateTimeconvertJimMicrosDateTimeQuiet(String s)Deprecated.static DBDateTimeconvertJimMicrosDateTimeQuietFast(String s, org.joda.time.DateTimeZone timeZone)Deprecated.static org.joda.time.DateTimeZoneconvertJimMicrosDateTimeQuietFastTz(String s)Deprecated.static LocalTimeconvertLocalTimeQuiet(String s)Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to aLocalTime.static DBPeriodconvertPeriod(String s)Converts a String into aDBPeriodobject.static DBPeriodconvertPeriodQuiet(String s)Converts a String into aDBPeriodobject.static longconvertTime(String s)Converts a String time to nanoseconds from Epoch.static longconvertTimeQuiet(String s)Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to a long nanoseconds offset from Epoch.static DateTimeFormattercreateFormatter(String timeZoneName)Create a DateTimeFormatter formatter with the specified time zone name using the standard yyyy-MM-dd format.static StringcurrentDate(DBTimeZone timeZone)Returns a String of the current date in the specifiedDBTimeZone.static StringcurrentDateNy()Provides a String representing the current date in the New York time zone or, if a customcurrentDateNyOverridehas been set, the date provided by that override.static DBDateTimecurrentTime()Provides the current date/time, or, if a customtimeProviderhas been configured, provides the current time according to the custom provider.static DBDateTimedateAtMidnight(DBDateTime dateTime, DBTimeZone timeZone)Returns aDBDateTimefor the requestedDBDateTimeat midnight in the specified time zone.static doubledayDiff(DBDateTime start, DBDateTime end)Deprecated.static intdayOfMonth(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the day of the month for aDBDateTimeand specified time zone.static intdayOfMonthNy(DBDateTime dateTime)Returns an int value of the day of the month for aDBDateTimein the New York time zone.static intdayOfWeek(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the day of the week for aDBDateTimein the specified time zone, with 1 being Monday and 7 being Sunday.static intdayOfWeekNy(DBDateTime dateTime)Returns an int value of the day of the week for aDBDateTimein the New York time zone, with 1 being Monday and 7 being Sunday.static intdayOfYear(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the day of the year (Julian date) for aDBDateTimein the specified time zone.static intdayOfYearNy(DBDateTime dateTime)Returns an int value of the day of the year (Julian date) for aDBDateTimein the New York time zone.static longdiff(DBDateTime d1, DBDateTime d2)Deprecated.static doublediffDay(DBDateTime start, DBDateTime end)Returns a double value of the number of days difference between twoDBDateTimevalues.static longdiffNanos(DBDateTime d1, DBDateTime d2)Returns the difference in nanoseconds between twoDBDateTimevalues.static doublediffYear(DBDateTime start, DBDateTime end)Returns a double value of the number of 365 day units difference between twoDBDateTimevalues.static longexpressionToNanos(String formula)Converts a String date/time to nanoseconds from Epoch or a nanoseconds period.static Stringformat(long nanos)Returns a String date/time representation.static Stringformat(DBDateTime dateTime, DBTimeZone timeZone)Returns a String date/time representation.static StringformatDate(DBDateTime dateTime, DBTimeZone timeZone)Returns a String date representation of aDBDateTimeinterpreted for a specified time zone.static StringformatDateNy(DBDateTime dateTime)Returns a String date representation of aDBDateTimeinterpreted for the New York time zone.static StringformatNy(DBDateTime dateTime)Returns a String date/time representation of aDBDateTimeinterpreted for the New York time zone.static doublegetExcelDateTime(DBDateTime dateTime)Returns the Excel double time format representation of aDBDateTime.static doublegetExcelDateTime(DBDateTime dateTime, DBTimeZone timeZone)Returns the Excel double time format representation of aDBDateTime.static doublegetExcelDateTime(DBDateTime dateTime, TimeZone timeZone)Returns the Excel double time format representation of aDBDateTime.static ChronoFieldgetFinestDefinedUnit(String timeDef)Returns aChronoFieldindicating the level of precision in a String time value.static StringgetPartitionFromTimestampMicros(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.static StringgetPartitionFromTimestampMillis(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.static StringgetPartitionFromTimestampNanos(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.static StringgetPartitionFromTimestampSeconds(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.static ZonedDateTimegetZonedDateTime(DBDateTime dateTime)Converts aDBDateTimeto aZonedDateTime.static ZonedDateTimegetZonedDateTime(DBDateTime dateTime, DBTimeZone timeZone)Converts aDBDateTimeto aZonedDateTime.static ZonedDateTimegetZonedDateTime(DBDateTime dateTime, ZoneId timeZone)Converts aDBDateTimeto aZonedDateTime.static inthourOfDay(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the hour of the day for aDBDateTimein the specified time zone.static inthourOfDayNy(DBDateTime dateTime)Returns an int value of the hour of the day for aDBDateTimein the New York time zone.static booleanisAfter(DBDateTime d1, DBDateTime d2)Evaluates whether oneDBDateTimevalue is later than a secondDBDateTimevalue.static booleanisBefore(DBDateTime d1, DBDateTime d2)Evaluates whether oneDBDateTimevalue is earlier than a secondDBDateTimevalue.static StringlastBusinessDateNy()Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a customlastBusinessDayNyOverridehas been set, the date provided by that override.static StringlastBusinessDateNy(long currentTimeMillis)Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a customlastBusinessDayNyOverridehas been set, the date provided by that override.static DBDateTimelowerBin(DBDateTime dateTime, long intervalNanos)Returns aDBDateTimevalue, which is at the starting (lower) end of a time range defined by the interval nanoseconds.static DBDateTimelowerBin(DBDateTime dateTime, long intervalNanos, long offset)Returns aDBDateTimevalue, which is at the starting (lower) end of a time range defined by the interval nanoseconds.static InstantmakeInstant(long nanos)Convert nanos since epoch to anInstantvalue.static ZonedDateTimemakeZonedDateTime(long nanos)Converts nanos of epoch to aZonedDateTimeusing thedefaulttime zone.static ZonedDateTimemakeZonedDateTime(long nanos, DBTimeZone timeZone)Converts nanos of epoch to aZonedDateTime.static ZonedDateTimemakeZonedDateTime(long nanos, ZoneId zone)Converts nanos of epoch to aZonedDateTime.static intmicrosOfMilli(DBDateTime dateTime, DBTimeZone timeZone)Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTimein the specified time zone.static intmicrosOfMilliNy(DBDateTime dateTime)Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTimein the New York time zone.static longmicrosToNanos(long micros)Converts microseconds to nanoseconds.static DBDateTimemicrosToTime(long micros)Converts a value of microseconds from Epoch in the UTC time zone to aDBDateTime.static longmillis(DBDateTime dateTime)Returns milliseconds since Epoch for aDBDateTimevalue.static intmillisOfDay(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of milliseconds since midnight for aDBDateTimein the specified time zone.static intmillisOfDayNy(DBDateTime dateTime)Returns an int value of milliseconds since midnight for aDBDateTimein the New York time zone.static intmillisOfSecond(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of milliseconds since the top of the second for aDBDateTimein the specified time zone.static intmillisOfSecondNy(DBDateTime dateTime)Returns an int value of milliseconds since the top of the second for aDBDateTimein the New York time zone.static DBDateTimemillisToDateAtMidnight(long millis, DBTimeZone timeZone)Returns aDBDateTimerepresenting midnight in a selected time zone on the date specified by a number of milliseconds from Epoch.static DBDateTimemillisToDateAtMidnightNy(long millis)Returns aDBDateTimerepresenting midnight in New York time zone on the date specified by the a number of milliseconds from Epoch.static longmillisToNanos(long millis)Converts milliseconds to nanoseconds.static DBDateTimemillisToTime(long millis)Converts a value of milliseconds from Epoch in the UTC time zone to aDBDateTime.static DBDateTimeminus(DBDateTime dateTime, long nanos)Subtracts one time from another.static longminus(DBDateTime d1, DBDateTime d2)Subtracts one time from another.static DBDateTimeminus(DBDateTime dateTime, DBPeriod period)Subtracts one time from another.static intminuteOfDay(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of minutes since midnight for aDBDateTimein the specified time zone.static intminuteOfDayNy(DBDateTime dateTime)Returns an int value of minutes since midnight for aDBDateTimein the New York time zone.static intminuteOfHour(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of minutes since the top of the hour for aDBDateTimein the specified time zone.static intminuteOfHourNy(DBDateTime dateTime)Returns an int value of minutes since the top of the hour for aDBDateTimein the New York time zone.static intmonthOfYear(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value for the month of aDBDateTimein the specified time zone.static intmonthOfYearNy(DBDateTime dateTime)Returns an int value for the month of aDBDateTimein the New York time zone.static longnanos(DBDateTime dateTime)Returns nanoseconds since Epoch for aDBDateTimevalue.static longnanosOfDay(DBDateTime dateTime, DBTimeZone timeZone)Returns a long value of nanoseconds since midnight for aDBDateTimein the specified time zone.static longnanosOfDayNy(DBDateTime dateTime)Returns a long value of nanoseconds since midnight for aDBDateTimein the New York time zone.static longnanosOfSecond(DBDateTime dateTime, DBTimeZone timeZone)Returns a long value of nanoseconds since the top of the second for aDBDateTimein the specified time zone.static longnanosOfSecondNy(DBDateTime dateTime)Returns a long value of nanoseconds since the top of the second for aDBDateTimein the New York time zone.static longnanosToMicros(long nanos)Converts nanoseconds to microseconds.static longnanosToMillis(long nanos)Converts nanoseconds to milliseconds.static DBDateTimenanosToTime(long nanos)Converts a value of nanoseconds from Epoch to aDBDateTime.static voidoverrideLastBusinessDateNyFromCurrentDateNy()Sets thelastBusinessDayNyOverrideto the previous business day from a currently setcurrentDateNyOverridevalue.static DBDateTimeplus(DBDateTime dateTime, long nanos)Adds one time from another.static DBDateTimeplus(DBDateTime dateTime, DBPeriod period)Adds one time from another.static intsecondOfDay(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of seconds since midnight for aDBDateTimein the specified time zone.static intsecondOfDayNy(DBDateTime dateTime)Returns an int value of seconds since midnight for aDBDateTimein the New York time zone.static intsecondOfMinute(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of seconds since the top of the minute for aDBDateTimein the specified time zone.static intsecondOfMinuteNy(DBDateTime dateTime)Returns an int value of seconds since the top of the minute for aDBDateTimein the New York time zone.static longsecondsToNanos(long seconds)Converts seconds to nanoseconds.static DBDateTimesecondsToTime(long seconds)Converts a value of seconds from Epoch in the UTC time zone to aDBDateTime.static DBDateTimetoDateTime(ZonedDateTime zonedDateTime)Converts aZonedDateTimeto aDBDateTime.static longtoEpochNano(Instant value)Convert the specified instant to nanoseconds since epoch, ornull.static longtoEpochNano(ZonedDateTime value)Convert the specifiedZonedDateTimeto nanoseconds since epoch, ornull.static DBDateTimeupperBin(DBDateTime dateTime, long intervalNanos)Returns aDBDateTimevalue, which is at the ending (upper) end of a time range defined by the interval nanoseconds.static DBDateTimeupperBin(DBDateTime dateTime, long intervalNanos, long offset)Returns aDBDateTimevalue, which is at the ending (upper) end of a time range defined by the interval nanoseconds.static intyear(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the year for aDBDateTimein the specified time zone.static doubleyearDiff(DBDateTime start, DBDateTime end)Deprecated.static intyearNy(DBDateTime dateTime)Returns an int value of the year for aDBDateTimein the New York time zone.static intyearOfCentury(DBDateTime dateTime, DBTimeZone timeZone)Returns an int value of the two-digit year for aDBDateTimein the specified time zone.static intyearOfCenturyNy(DBDateTime dateTime)Returns an int value of the two-digit year for aDBDateTimein the New York time zone.
-
Field Details
-
SECOND
public static final long SECONDConstant value of one second in nanoseconds.- See Also:
- Constant Field Values
-
MINUTE
public static final long MINUTEConstant value of one minute in nanoseconds.- See Also:
- Constant Field Values
-
HOUR
public static final long HOURConstant value of one hour in nanoseconds.- See Also:
- Constant Field Values
-
DAY
public static final long DAYConstant value of one day in nanoseconds.- See Also:
- Constant Field Values
-
WEEK
public static final long WEEKConstant value of one week in nanoseconds.- See Also:
- Constant Field Values
-
YEAR
public static final long YEARConstant value of one year (365 days) in nanoseconds.- See Also:
- Constant Field Values
-
currentDateNyOverride
Allows setting an alternate date instead of "today" to be returned fromcurrentDateNy. This is mainly used when setting up for a replay simulation. -
lastBusinessDayNyOverride
Allows setting an alternate date instead of the business day before "today" to be returned fromlastBusinessDateNy. This is mainly used when setting up for a replay simulation. -
timeProvider
Allows setting a custom time provider instead of actual current time. This is mainly used when setting up for a replay simulation. -
currentDateNy
-
endOfCurrentDateNy
public static long endOfCurrentDateNy -
lastBusinessDateNy
Cached value of lastBusinessDateNy, which expires after milliseconds from Epoch value ofendOfCurrentDateNyLastBusinessDay -
endOfCurrentDateNyLastBusinessDay
public static long endOfCurrentDateNyLastBusinessDayExpiration for cachedlastBusinessDateNyas milliseconds from Epoch.
-
-
Constructor Details
-
DBTimeUtils
public DBTimeUtils()
-
-
Method Details
-
millis
Returns milliseconds since Epoch for aDBDateTimevalue.- Parameters:
dateTime- TheDBDateTimefor which the milliseconds offset should be returned.- Returns:
- A long value of milliseconds since Epoch, or a
QueryConstants.NULL_LONGvalue if theDBDateTimeis null.
-
nanos
Returns nanoseconds since Epoch for aDBDateTimevalue.- Parameters:
dateTime- TheDBDateTimefor which the nanoseconds offset should be returned.- Returns:
- A long value of nanoseconds since Epoch, or a NULL_LONG value if the
DBDateTimeis null.
-
isBefore
Evaluates whether oneDBDateTimevalue is earlier than a secondDBDateTimevalue.- Parameters:
d1- The firstDBDateTimevalue to compare.d2- The secondDBDateTimevalue 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
Evaluates whether oneDBDateTimevalue is later than a secondDBDateTimevalue.- Parameters:
d1- The firstDBDateTimevalue to compare.d2- The secondDBDateTimevalue 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
Adds one time from another.- Parameters:
dateTime- The startingDBDateTimevalue.nanos- The long number of nanoseconds to add to dateTime.- Returns:
- a null
DBDateTimeif either input is null; the startingDBDateTimeplus the specified number of nanoseconds, if the result is not too large for aDBDateTime; or throws aDBDateTimeOverflowExceptionif the resultant value is more than max long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
dateTime- The startingDBDateTimevalue.nanos- The long number of nanoseconds to subtract from dateTime.- Returns:
- a null
DBDateTimeif either input is null; the startingDBDateTimeminus the specified number of nanoseconds, if the result is not too negative for aDBDateTime; or throws aDBDateTimeOverflowExceptionif the resultant value is more than min long nanoseconds from Epoch.
-
plus
Adds one time from another.- Parameters:
dateTime- The startingDBDateTimevalue.period- TheDBPeriodto add to dateTime.- Returns:
- a null
DBDateTimeif either input is null; the startingDBDateTimeplus the specified period, if the result is not too large for a DBDateTime; or throws aDBDateTimeOverflowExceptionif the resultant value is more than max long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
dateTime- The startingDBDateTimevalue.period- TheDBPeriodto subtract from dateTime.- Returns:
- a null
DBDateTimeif either input is null; the startingDBDateTimeminus the specified period, if the result is not too negative for aDBDateTime; or throws aDBDateTimeOverflowExceptionif the resultant value is more than min long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
d1- The firstDBDateTime.d2- TheDBDateTimeto subtract from d1.- Returns:
QueryConstants.NULL_LONGif either input is null; the long nanoseconds from Epoch value of the firstDBDateTimeminus d2, if the result is not out of range for a long value; or throws aDBDateTimeOverflowExceptionif 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. -
yearDiff
Deprecated. -
dayDiff
Deprecated. -
diffNanos
Returns the difference in nanoseconds between twoDBDateTimevalues.- Parameters:
d1- The firstDBDateTime.d2- The secondDBDateTime.- Returns:
QueryConstants.NULL_LONGif either input is null; the long nanoseconds from Epoch value of the firstDBDateTimeminus d2, if the result is not out of range for a long value; or throws aDBDateTimeOverflowExceptionif 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
Returns a double value of the number of 365 day units difference between twoDBDateTimevalues.- Parameters:
start- The firstDBDateTime.end- The secondDBDateTime.- Returns:
QueryConstants.NULL_LONGif either input is null; a double value of the number of 365 day periods obtained from the firstDBDateTimevalue minus d2, if the intermediate value of nanoseconds difference between the two dates is not out of range for a long value; or throws aDBTimeUtils.DBDateTimeOverflowExceptionif 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
Returns a double value of the number of days difference between twoDBDateTimevalues.- Parameters:
start- The firstDBDateTime.end- The secondDBDateTime.- Returns:
QueryConstants.NULL_LONGif either input is null; a double value of the number of days obtained from the firstDBDateTimevalue minus d2, if the intermediate value of nanoseconds difference between the two dates is not out of range for a long value; or throws aDBDateTimeOverflowExceptionif 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
Returns aDBDateTimefor the requestedDBDateTimeat midnight in the specified time zone.- Parameters:
dateTime-DBDateTimefor which the new value at midnight should be calculated.timeZone-DBTimeZonefor which the new value at midnight should be calculated.- Returns:
- A null
DBDateTimeif either input is null, otherwise aDBDateTimerepresenting midnight for the date and time zone of the inputs.
-
millisToDateAtMidnightNy
Returns aDBDateTimerepresenting 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 theDBDateTimeis to be calculated.- Returns:
- A
DBDateTimerounded down to midnight in the New York time zone for the specified number of milliseconds from Epoch.
-
millisToDateAtMidnight
Returns aDBDateTimerepresenting 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 theDBDateTimeis to be calculated.timeZone-DBTimeZonefor which the new value at midnight should be calculated.- Returns:
- A
DBDateTimerounded down to midnight in the selected time zone for the specified number of milliseconds from Epoch.
-
format
Returns a String date/time representation.- Parameters:
dateTime- TheDBDateTimeto format as a String.timeZone- TheDBTimeZoneto 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
Returns a String date/time representation of aDBDateTimeinterpreted for the New York time zone.- Parameters:
dateTime- TheDBDateTimeto 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
Returns a String date representation of aDBDateTimeinterpreted for a specified time zone.- Parameters:
dateTime- TheDBDateTimeto format as a String.timeZone- TheDBTimeZoneto use when formatting the String.- Returns:
- A null String if either input is null, otherwise a String formatted as yyyy-MM-dd.
-
formatDateNy
Returns a String date representation of aDBDateTimeinterpreted for the New York time zone.- Parameters:
dateTime- TheDBDateTimeto format as a String.- Returns:
- A null String if the input is null, otherwise a String formatted as yyyy-MM-dd.
-
format
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
Returns an int value of the day of the month for aDBDateTimeand specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the month.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the day of the month represented by theDBDateTimewhen interpreted in the specified time zone.
-
dayOfMonthNy
Returns an int value of the day of the month for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the month.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of the day of the month represented by theDBDateTimewhen interpreted in the New York time zone.
-
dayOfWeek
Returns an int value of the day of the week for aDBDateTimein the specified time zone, with 1 being Monday and 7 being Sunday.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the week.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the day of the week represented by theDBDateTimewhen interpreted in the specified time zone.
-
dayOfWeekNy
Returns an int value of the day of the week for aDBDateTimein the New York time zone, with 1 being Monday and 7 being Sunday.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the week.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of the day of the week represented by theDBDateTimewhen interpreted in the New York time zone.
-
dayOfYear
Returns an int value of the day of the year (Julian date) for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the year.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the day of the year represented by theDBDateTimewhen interpreted in the specified time zone.
-
dayOfYearNy
Returns an int value of the day of the year (Julian date) for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the day of the year.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of the day of the year represented by theDBDateTimewhen interpreted in the New York time zone.
-
hourOfDay
Returns an int value of the hour of the day for aDBDateTimein the specified time zone. The hour is on a 24 hour clock (0 - 23).- Parameters:
dateTime- TheDBDateTimefor which to find the hour of the day.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the hour of the day represented by theDBDateTimewhen interpreted in the specified time zone.
-
hourOfDayNy
Returns an int value of the hour of the day for aDBDateTimein the New York time zone. The hour is on a 24 hour clock (0 - 23).- Parameters:
dateTime- TheDBDateTimefor which to find the hour of the day.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of the hour of the day represented by theDBDateTimewhen interpreted in the New York time zone.
-
millisOfDay
Returns an int value of milliseconds since midnight for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the milliseconds since midnight.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of milliseconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
millisOfDayNy
Returns an int value of milliseconds since midnight for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the milliseconds since midnight.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of milliseconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
millisOfSecond
Returns an int value of milliseconds since the top of the second for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the milliseconds.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of milliseconds since the top of the second for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
millisOfSecondNy
Returns an int value of milliseconds since the top of the second for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the milliseconds.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of milliseconds since the top of the second for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
nanosOfDay
Returns a long value of nanoseconds since midnight for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the nanoseconds since midnight.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_LONGif either input is null, otherwise, a long value of nanoseconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
nanosOfDayNy
Returns a long value of nanoseconds since midnight for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the nanoseconds since midnight.- Returns:
- A
QueryConstants.NULL_LONGif the input is null, otherwise, a long value of nanoseconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
nanosOfSecond
Returns a long value of nanoseconds since the top of the second for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the nanoseconds.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_LONGif either input is null, otherwise, a long value of nanoseconds since the top of the second for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
nanosOfSecondNy
Returns a long value of nanoseconds since the top of the second for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the nanoseconds.- Returns:
- A
QueryConstants.NULL_LONGif the input is null, otherwise, a long value of nanoseconds since the top of the second for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
microsOfMilli
Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTimein the specified time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.- Parameters:
dateTime- TheDBDateTimefor which to find the microseconds.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of microseconds since the top of the millisecond for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
microsOfMilliNy
Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTimein the New York time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.- Parameters:
dateTime- TheDBDateTimefor which to find the microseconds.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of microseconds since the top of the millisecond for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
minuteOfDay
Returns an int value of minutes since midnight for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the minutes.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of minutes since midnight for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
minuteOfDayNy
Returns an int value of minutes since midnight for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the milliseconds since midnight.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of minutes since midnight for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
minuteOfHour
Returns an int value of minutes since the top of the hour for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the minutes.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of minutes since the top of the hour for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
minuteOfHourNy
Returns an int value of minutes since the top of the hour for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the minutes.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of minutes since the top of the hour for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
monthOfYear
Returns an int value for the month of aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the month.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the month for the date/time represented by theDBDateTimewhen interpreted in the specified time zone. January is 1, February is 2, etc.
-
monthOfYearNy
Returns an int value for the month of aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the month.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of the month for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
secondOfDay
Returns an int value of seconds since midnight for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the seconds.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of seconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
secondOfDayNy
Returns an int value of seconds since midnight for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the seconds.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of seconds since midnight for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
secondOfMinute
Returns an int value of seconds since the top of the minute for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the seconds.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of seconds since the top of the minute for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
secondOfMinuteNy
Returns an int value of seconds since the top of the minute for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the seconds.- Returns:
- A
QueryConstants.NULL_INTif the input is null, otherwise, an int value of seconds since the top of the minute for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
year
Returns an int value of the year for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the year.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the year for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
yearNy
Returns an int value of the year for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the year.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the year for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
yearOfCentury
Returns an int value of the two-digit year for aDBDateTimein the specified time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the year.timeZone- TheDBTimeZoneto use when interpreting the date/time.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the two-digit year for the date/time represented by theDBDateTimewhen interpreted in the specified time zone.
-
yearOfCenturyNy
Returns an int value of the two-digit year for aDBDateTimein the New York time zone.- Parameters:
dateTime- TheDBDateTimefor which to find the year.- Returns:
- A
QueryConstants.NULL_INTif either input is null, otherwise, an int value of the two-digit year for the date/time represented by theDBDateTimewhen interpreted in the New York time zone.
-
getExcelDateTime
Returns the Excel double time format representation of aDBDateTime.- Parameters:
dateTime- TheDBDateTimeto convert.timeZone- TheDBTimeZoneto 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
DBDateTimein the specified time zone.
-
getExcelDateTime
Returns the Excel double time format representation of aDBDateTime.- Parameters:
dateTime- TheDBDateTimeto convert.timeZone- TheTimeZoneto 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
DBDateTimein the specified time zone.
-
getExcelDateTime
Returns the Excel double time format representation of aDBDateTime.- Parameters:
dateTime- TheDBDateTimeto convert.- Returns:
- 0.0 if the input is null, otherwise, a double value
containing the Excel double format representation of a
DBDateTimein 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_LONGif the input is null. Throws aDBTimeUtils.DBDateTimeOverflowExceptionif 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_LONGif the input is null. Otherwise, returns a long containing the equivalent number of microseconds for the input in nanoseconds.
-
microsToTime
Converts a value of microseconds from Epoch in the UTC time zone to aDBDateTime.- Parameters:
micros- The long microseconds value to convert.- Returns:
QueryConstants.NULL_LONGif the input is null, otherwise, aDBDateTimerepresentation 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_LONGif the input is equal toQueryConstants.NULL_LONG. ThrowsDBTimeUtils.DBDateTimeOverflowExceptionif 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_LONGif the input is null. Throws aDBTimeUtils.DBDateTimeOverflowExceptionif 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_LONGif the input is null. Otherwise, returns a long containing the equivalent number of milliseconds for the input in nanoseconds.
-
millisToTime
Converts a value of milliseconds from Epoch in the UTC time zone to aDBDateTime.- Parameters:
millis- The long milliseconds value to convert.- Returns:
QueryConstants.NULL_LONGif the input is null, otherwise, aDBDateTimerepresentation of the input.
-
secondsToTime
Converts a value of seconds from Epoch in the UTC time zone to aDBDateTime.- Parameters:
seconds- The long seconds value to convert.- Returns:
QueryConstants.NULL_LONGif the input is null, otherwise, aDBDateTimerepresentation of the input.
-
toEpochNano
Convert the specified instant to nanoseconds since epoch, ornull.- Parameters:
value- the instant to convert- Returns:
- nanoseconds since epoch or
null
-
toEpochNano
Convert the specifiedZonedDateTimeto nanoseconds since epoch, ornull.- Parameters:
value- the instant to convert- Returns:
- nanoseconds since epoch or
null
-
makeInstant
Convert nanos since epoch to anInstantvalue.- Parameters:
nanos- nanoseconds since epoch- Returns:
- a new
Instantor null if nanos wasQueryConstants.NULL_LONG.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTimeusing thedefaulttime zone.- Parameters:
nanos- nanoseconds since epoch- Returns:
- a new
ZonedDateTimeor null if nanos wasQueryConstants.NULL_LONG.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTime.- Parameters:
nanos- nanoseconds since epochtimeZone- thetime zone- Returns:
- a new
ZonedDateTimeor null if nanos wasQueryConstants.NULL_LONG.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTime.- Parameters:
nanos- nanoseconds since epochzone- thetime zone- Returns:
- a new
ZonedDateTimeor null if nanos wasQueryConstants.NULL_LONG.
-
getZonedDateTime
Converts aDBDateTimeto aZonedDateTime.- Parameters:
dateTime- The aDBDateTimeto convert.- Returns:
- A
ZonedDateTimeusing the default time zone for the session as indicated byDBTimeZone.TZ_DEFAULT.
-
getZonedDateTime
@Nullable public static ZonedDateTime getZonedDateTime(@Nullable DBDateTime dateTime, @NotNull DBTimeZone timeZone)Converts aDBDateTimeto aZonedDateTime.- Parameters:
dateTime- The aDBDateTimeto convert.timeZone- TheDBTimeZoneto use for the conversion.- Returns:
- A
ZonedDateTimeusing the specified time zone. or null if dateTime was null
-
getZonedDateTime
@Nullable public static ZonedDateTime getZonedDateTime(@Nullable DBDateTime dateTime, @NotNull ZoneId timeZone)Converts aDBDateTimeto aZonedDateTime.- Parameters:
dateTime- The aDBDateTimeto convert.timeZone- TheZoneIdto use for the conversion.- Returns:
- A
ZonedDateTimeusing the specified time zone. or null if dateTime was null
-
toDateTime
Converts aZonedDateTimeto aDBDateTime.- Parameters:
zonedDateTime- The aZonedDateTimeto convert.- Throws:
DBTimeUtils.DBDateTimeOverflowException- if the input is out of the range for aDBDateTime, otherwise, aDBDateTimeversion of the input.
-
currentTime
Provides the current date/time, or, if a customtimeProviderhas been configured, provides the current time according to the custom provider.- Returns:
- A
DBDateTimeof the current date and time from the system or from the configured alternate time provider.
-
currentDateNy
Provides a String representing the current date in the New York time zone or, if a customcurrentDateNyOverridehas been set, the date provided by that override.- Returns:
- A String in yyyy-MM-dd format.
-
consistentDateNy
Convenience method invokingCompositeTableDataServiceConsistencyMonitor.consistentDateNy(). -
overrideLastBusinessDateNyFromCurrentDateNy
public static void overrideLastBusinessDateNyFromCurrentDateNy()Sets thelastBusinessDayNyOverrideto the previous business day from a currently setcurrentDateNyOverridevalue. IfcurrentDateNyOverridehas not been set, this method has no effect. -
lastBusinessDateNy
Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a customlastBusinessDayNyOverridehas been set, the date provided by that override.- Returns:
- A String in yyyy-MM-dd format.
-
lastBusinessDateNy
Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a customlastBusinessDayNyOverridehas 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
Returns a String of the current date in the specifiedDBTimeZone.- Parameters:
timeZone- TheDBTimeZoneto reference when evaluating the current date for "now".- Returns:
- A String in format yyyy-MM-dd.
-
nanosToTime
Converts a value of nanoseconds from Epoch to aDBDateTime.- Parameters:
nanos- The long nanoseconds since Epoch value to convert.- Returns:
- A DBDateTime for
nanos, ornullifnanosis equal toNULL_LONG.
-
autoEpochToTime
Converts a long offset from Epoch value to aDBDateTime. This method uses expected date ranges to infer whether the passed value is in milliseconds, microseconds, or nanoseconds. Thresholds used areTimeConstants.MICROTIME_THRESHOLDdivided 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_THRESHOLDwill 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 aDBDateTimebased on the inferred conversion.
-
cappedTimeOffset
Returns aDBDateTimevalue based on a starting value and aDBPeriodto 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 startingDBDateTimevalue.period- TheDBPeriodto add to dateTime.cap- ADBDateTimevalue to use as the maximum return value.- Returns:
- a null
DBDateTimeif either original or period are null; the startingDBDateTimeplus 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 aDBDateTimeOverflowExceptionif the resultant value is more than max long nanoseconds from Epoch.
-
lowerBin
Returns aDBDateTimevalue, 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- TheDBDateTimefor 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
DBDateTimerepresenting the start of the window.
-
lowerBin
Returns aDBDateTimevalue, 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- TheDBDateTimefor 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
DBDateTimerepresenting the start of the window.
-
upperBin
Returns aDBDateTimevalue, 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- TheDBDateTimefor 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
DBDateTimerepresenting the end of the window.
-
upperBin
Returns aDBDateTimevalue, 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- TheDBDateTimefor 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
DBDateTimerepresenting the end of the window.
-
convertExpression
Converts an expression, replacing DBDateTime and DBPeriod literals with references to constant DBDateTime/DBPeriod instances.- Parameters:
formula- The formula to convert.- Returns:
- A
DBTimeUtils.Resultobject, 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
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.DBDateTimeOverflowExceptionif the resultant value would be longer than max long, orIllegalArgumentExceptionif expression cannot be evaluated.
-
convertDate
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 aLocalDate
-
convertDateTime
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 aDBDateTimefrom the parsed String.
-
convertTime
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
RuntimeExceptionif the String cannot be parsed.
-
convertPeriod
Converts a String into aDBPeriodobject.- 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 aDBPeriodobject.
-
convertLocalTimeQuiet
Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to aLocalTime.- Parameters:
s- The String to convert.- Returns:
- null if the String cannot be parsed, otherwise a
LocalTime.
-
convertDateQuiet
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
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 stringdateStyle- indicates how to interpret slash-delimited dates- Returns:
- the LocalDate
-
convertJimDateTimeQuiet
Deprecated. -
convertJimMicrosDateTimeQuiet
Deprecated. -
convertDateTimeQuiet
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. -
convertTimeQuiet
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_LONGif the String cannot be parsed, otherwise long nanoseconds offset from Epoch.
-
convertPeriodQuiet
Converts a String into aDBPeriodobject.- 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
DBPeriodobject.
-
getFinestDefinedUnit
Returns aChronoFieldindicating 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
ChronoFieldfor the finest units in the String (e.g. "10:00:00" would yield SecondOfMinute).
-
createFormatter
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 formattertimestampMillis- 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 formattertimestampMicros- 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 formattertimestampNanos- 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 formattertimestampSeconds- the timestamp in seconds- Returns:
- the formatted date
-