Class DBTimeUtils
public class DBTimeUtils extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DBTimeUtils.DateStyle
Date formatting styles for use in conversion functions such asconvertDateQuiet(String, DateStyle)
.static class
DBTimeUtils.DBDateTimeOverflowException
A type of RuntimeException thrown when operations resulting inDBDateTime
values would exceed the range available by max or min long nanoseconds.static class
DBTimeUtils.Result
A 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 String
currentDateNy
static String
currentDateNyOverride
Allows setting an alternate date instead of "today" to be returned fromcurrentDateNy
.static long
DAY
Constant value of one day in nanoseconds.static long
endOfCurrentDateNy
static long
endOfCurrentDateNyLastBusinessDay
Expiration for cachedlastBusinessDateNy
as milliseconds from Epoch.static long
HOUR
Constant value of one hour in nanoseconds.static String
lastBusinessDateNy
Cached value of lastBusinessDateNy, which expires after milliseconds from Epoch value ofendOfCurrentDateNyLastBusinessDay
static String
lastBusinessDayNyOverride
Allows setting an alternate date instead of the business day before "today" to be returned fromlastBusinessDateNy
.static long
MINUTE
Constant value of one minute in nanoseconds.static long
SECOND
Constant value of one second in nanoseconds.static TimeProvider
timeProvider
Allows setting a custom time provider instead of actual current time.static long
WEEK
Constant value of one week in nanoseconds.static long
YEAR
Constant value of one year (365 days) in nanoseconds. -
Constructor Summary
Constructors Constructor Description DBTimeUtils()
-
Method Summary
Modifier and Type Method Description static DBDateTime
autoEpochToTime(long epoch)
Converts a long offset from Epoch value to aDBDateTime
.static DBDateTime
cappedTimeOffset(DBDateTime original, DBPeriod period, DBDateTime cap)
Returns aDBDateTime
value based on a starting value and aDBPeriod
to add to it, but with a cap max value which is returned in case the starting value plus period exceeds the cap.static String
consistentDateNy()
Convenience method invokingCompositeTableDataServiceConsistencyMonitor.consistentDateNy()
.static LocalDate
convertDate(String s)
Attempt to convert the given string to a LocalDate.static LocalDate
convertDateQuiet(String s)
Attempt to convert the given string to a LocalDate.static LocalDate
convertDateQuiet(String s, DBTimeUtils.DateStyle dateStyle)
Attempt to convert the given string to a LocalDate.static DBDateTime
convertDateTime(String s)
Converts a DateTime String from a few specific zoned formats to a DBDateTimestatic DBDateTime
convertDateTimeQuiet(String s)
Converts a DateTime String from a few specific zoned formats to a DBDateTimestatic DBTimeUtils.Result
convertExpression(String formula)
Converts an expression, replacing DBDateTime and DBPeriod literals with references to constant DBDateTime/DBPeriod instances.static DBDateTime
convertJimDateTimeQuiet(String s)
Deprecated.static DBDateTime
convertJimMicrosDateTimeQuiet(String s)
Deprecated.static DBDateTime
convertJimMicrosDateTimeQuietFast(String s, org.joda.time.DateTimeZone timeZone)
Deprecated.static org.joda.time.DateTimeZone
convertJimMicrosDateTimeQuietFastTz(String s)
Deprecated.static LocalTime
convertLocalTimeQuiet(String s)
Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to aLocalTime
.static DBPeriod
convertPeriod(String s)
Converts a String into aDBPeriod
object.static DBPeriod
convertPeriodQuiet(String s)
Converts a String into aDBPeriod
object.static long
convertTime(String s)
Converts a String time to nanoseconds from Epoch.static long
convertTimeQuiet(String s)
Converts a time String in the form hh:mm:ss[.nnnnnnnnn] to a long nanoseconds offset from Epoch.static DateTimeFormatter
createFormatter(String timeZoneName)
Create a DateTimeFormatter formatter with the specified time zone name using the standard yyyy-MM-dd format.static String
currentDate(DBTimeZone timeZone)
Returns a String of the current date in the specifiedDBTimeZone
.static String
currentDateNy()
Provides a String representing the current date in the New York time zone or, if a customcurrentDateNyOverride
has been set, the date provided by that override.static DBDateTime
currentTime()
Provides the current date/time, or, if a customtimeProvider
has been configured, provides the current time according to the custom provider.static DBDateTime
dateAtMidnight(DBDateTime dateTime, DBTimeZone timeZone)
Returns aDBDateTime
for the requestedDBDateTime
at midnight in the specified time zone.static double
dayDiff(DBDateTime start, DBDateTime end)
Deprecated.static int
dayOfMonth(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the day of the month for aDBDateTime
and specified time zone.static int
dayOfMonthNy(DBDateTime dateTime)
Returns an int value of the day of the month for aDBDateTime
in the New York time zone.static int
dayOfWeek(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the day of the week for aDBDateTime
in the specified time zone, with 1 being Monday and 7 being Sunday.static int
dayOfWeekNy(DBDateTime dateTime)
Returns an int value of the day of the week for aDBDateTime
in the New York time zone, with 1 being Monday and 7 being Sunday.static int
dayOfYear(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the day of the year (Julian date) for aDBDateTime
in the specified time zone.static int
dayOfYearNy(DBDateTime dateTime)
Returns an int value of the day of the year (Julian date) for aDBDateTime
in the New York time zone.static long
diff(DBDateTime d1, DBDateTime d2)
Deprecated.static double
diffDay(DBDateTime start, DBDateTime end)
Returns a double value of the number of days difference between twoDBDateTime
values.static long
diffNanos(DBDateTime d1, DBDateTime d2)
Returns the difference in nanoseconds between twoDBDateTime
values.static double
diffYear(DBDateTime start, DBDateTime end)
Returns a double value of the number of 365 day units difference between twoDBDateTime
values.static long
expressionToNanos(String formula)
Converts a String date/time to nanoseconds from Epoch or a nanoseconds period.static String
format(long nanos)
Returns a String date/time representation.static String
format(DBDateTime dateTime, DBTimeZone timeZone)
Returns a String date/time representation.static String
formatDate(DBDateTime dateTime, DBTimeZone timeZone)
Returns a String date representation of aDBDateTime
interpreted for a specified time zone.static String
formatDateNy(DBDateTime dateTime)
Returns a String date representation of aDBDateTime
interpreted for the New York time zone.static String
formatNy(DBDateTime dateTime)
Returns a String date/time representation of aDBDateTime
interpreted for the New York time zone.static double
getExcelDateTime(DBDateTime dateTime)
Returns the Excel double time format representation of aDBDateTime
.static double
getExcelDateTime(DBDateTime dateTime, DBTimeZone timeZone)
Returns the Excel double time format representation of aDBDateTime
.static double
getExcelDateTime(DBDateTime dateTime, TimeZone timeZone)
Returns the Excel double time format representation of aDBDateTime
.static ChronoField
getFinestDefinedUnit(String timeDef)
Returns aChronoField
indicating the level of precision in a String time value.static String
getPartitionFromTimestampMicros(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 String
getPartitionFromTimestampMillis(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 String
getPartitionFromTimestampNanos(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 String
getPartitionFromTimestampSeconds(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 ZonedDateTime
getZonedDateTime(DBDateTime dateTime)
Converts aDBDateTime
to aZonedDateTime
.static ZonedDateTime
getZonedDateTime(DBDateTime dateTime, DBTimeZone timeZone)
Converts aDBDateTime
to aZonedDateTime
.static ZonedDateTime
getZonedDateTime(DBDateTime dateTime, ZoneId timeZone)
Converts aDBDateTime
to aZonedDateTime
.static int
hourOfDay(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the hour of the day for aDBDateTime
in the specified time zone.static int
hourOfDayNy(DBDateTime dateTime)
Returns an int value of the hour of the day for aDBDateTime
in the New York time zone.static boolean
isAfter(DBDateTime d1, DBDateTime d2)
Evaluates whether oneDBDateTime
value is later than a secondDBDateTime
value.static boolean
isBefore(DBDateTime d1, DBDateTime d2)
Evaluates whether oneDBDateTime
value is earlier than a secondDBDateTime
value.static String
lastBusinessDateNy()
Provides a String representing the previous business date in the New York time zone using the NYSE calendar, or, if a customlastBusinessDayNyOverride
has been set, the date provided by that override.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 customlastBusinessDayNyOverride
has been set, the date provided by that override.static DBDateTime
lowerBin(DBDateTime dateTime, long intervalNanos)
Returns aDBDateTime
value, which is at the starting (lower) end of a time range defined by the interval nanoseconds.static DBDateTime
lowerBin(DBDateTime dateTime, long intervalNanos, long offset)
Returns aDBDateTime
value, which is at the starting (lower) end of a time range defined by the interval nanoseconds.static Instant
makeInstant(long nanos)
Convert nanos since epoch to anInstant
value.static ZonedDateTime
makeZonedDateTime(long nanos)
Converts nanos of epoch to aZonedDateTime
using thedefault
time zone.static ZonedDateTime
makeZonedDateTime(long nanos, DBTimeZone timeZone)
Converts nanos of epoch to aZonedDateTime
.static ZonedDateTime
makeZonedDateTime(long nanos, ZoneId zone)
Converts nanos of epoch to aZonedDateTime
.static int
microsOfMilli(DBDateTime dateTime, DBTimeZone timeZone)
Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTime
in the specified time zone.static int
microsOfMilliNy(DBDateTime dateTime)
Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTime
in the New York time zone.static long
microsToNanos(long micros)
Converts microseconds to nanoseconds.static DBDateTime
microsToTime(long micros)
Converts a value of microseconds from Epoch in the UTC time zone to aDBDateTime
.static long
millis(DBDateTime dateTime)
Returns milliseconds since Epoch for aDBDateTime
value.static int
millisOfDay(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of milliseconds since midnight for aDBDateTime
in the specified time zone.static int
millisOfDayNy(DBDateTime dateTime)
Returns an int value of milliseconds since midnight for aDBDateTime
in the New York time zone.static int
millisOfSecond(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of milliseconds since the top of the second for aDBDateTime
in the specified time zone.static int
millisOfSecondNy(DBDateTime dateTime)
Returns an int value of milliseconds since the top of the second for aDBDateTime
in the New York time zone.static DBDateTime
millisToDateAtMidnight(long millis, DBTimeZone timeZone)
Returns aDBDateTime
representing midnight in a selected time zone on the date specified by a number of milliseconds from Epoch.static DBDateTime
millisToDateAtMidnightNy(long millis)
Returns aDBDateTime
representing midnight in New York time zone on the date specified by the a number of milliseconds from Epoch.static long
millisToNanos(long millis)
Converts milliseconds to nanoseconds.static DBDateTime
millisToTime(long millis)
Converts a value of milliseconds from Epoch in the UTC time zone to aDBDateTime
.static DBDateTime
minus(DBDateTime dateTime, long nanos)
Subtracts one time from another.static long
minus(DBDateTime d1, DBDateTime d2)
Subtracts one time from another.static DBDateTime
minus(DBDateTime dateTime, DBPeriod period)
Subtracts one time from another.static int
minuteOfDay(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of minutes since midnight for aDBDateTime
in the specified time zone.static int
minuteOfDayNy(DBDateTime dateTime)
Returns an int value of minutes since midnight for aDBDateTime
in the New York time zone.static int
minuteOfHour(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of minutes since the top of the hour for aDBDateTime
in the specified time zone.static int
minuteOfHourNy(DBDateTime dateTime)
Returns an int value of minutes since the top of the hour for aDBDateTime
in the New York time zone.static int
monthOfYear(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value for the month of aDBDateTime
in the specified time zone.static int
monthOfYearNy(DBDateTime dateTime)
Returns an int value for the month of aDBDateTime
in the New York time zone.static long
nanos(DBDateTime dateTime)
Returns nanoseconds since Epoch for aDBDateTime
value.static long
nanosOfDay(DBDateTime dateTime, DBTimeZone timeZone)
Returns a long value of nanoseconds since midnight for aDBDateTime
in the specified time zone.static long
nanosOfDayNy(DBDateTime dateTime)
Returns a long value of nanoseconds since midnight for aDBDateTime
in the New York time zone.static long
nanosOfSecond(DBDateTime dateTime, DBTimeZone timeZone)
Returns a long value of nanoseconds since the top of the second for aDBDateTime
in the specified time zone.static long
nanosOfSecondNy(DBDateTime dateTime)
Returns a long value of nanoseconds since the top of the second for aDBDateTime
in the New York time zone.static long
nanosToMicros(long nanos)
Converts nanoseconds to microseconds.static long
nanosToMillis(long nanos)
Converts nanoseconds to milliseconds.static DBDateTime
nanosToTime(long nanos)
Converts a value of nanoseconds from Epoch to aDBDateTime
.static void
overrideLastBusinessDateNyFromCurrentDateNy()
Sets thelastBusinessDayNyOverride
to the previous business day from a currently setcurrentDateNyOverride
value.static DBDateTime
plus(DBDateTime dateTime, long nanos)
Adds one time from another.static DBDateTime
plus(DBDateTime dateTime, DBPeriod period)
Adds one time from another.static int
secondOfDay(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of seconds since midnight for aDBDateTime
in the specified time zone.static int
secondOfDayNy(DBDateTime dateTime)
Returns an int value of seconds since midnight for aDBDateTime
in the New York time zone.static int
secondOfMinute(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of seconds since the top of the minute for aDBDateTime
in the specified time zone.static int
secondOfMinuteNy(DBDateTime dateTime)
Returns an int value of seconds since the top of the minute for aDBDateTime
in the New York time zone.static long
secondsToNanos(long seconds)
Converts seconds to nanoseconds.static DBDateTime
secondsToTime(long seconds)
Converts a value of seconds from Epoch in the UTC time zone to aDBDateTime
.static DBDateTime
toDateTime(ZonedDateTime zonedDateTime)
Converts aZonedDateTime
to aDBDateTime
.static long
toEpochNano(Instant value)
Convert the specified instant to nanoseconds since epoch, ornull
.static long
toEpochNano(ZonedDateTime value)
Convert the specifiedZonedDateTime
to nanoseconds since epoch, ornull
.static DBDateTime
upperBin(DBDateTime dateTime, long intervalNanos)
Returns aDBDateTime
value, which is at the ending (upper) end of a time range defined by the interval nanoseconds.static DBDateTime
upperBin(DBDateTime dateTime, long intervalNanos, long offset)
Returns aDBDateTime
value, which is at the ending (upper) end of a time range defined by the interval nanoseconds.static int
year(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the year for aDBDateTime
in the specified time zone.static double
yearDiff(DBDateTime start, DBDateTime end)
Deprecated.static int
yearNy(DBDateTime dateTime)
Returns an int value of the year for aDBDateTime
in the New York time zone.static int
yearOfCentury(DBDateTime dateTime, DBTimeZone timeZone)
Returns an int value of the two-digit year for aDBDateTime
in the specified time zone.static int
yearOfCenturyNy(DBDateTime dateTime)
Returns an int value of the two-digit year for aDBDateTime
in 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 cachedlastBusinessDateNy
as milliseconds from Epoch.
-
-
Constructor Details
-
DBTimeUtils
public DBTimeUtils()
-
-
Method Details
-
millis
Returns milliseconds since Epoch for aDBDateTime
value.- Parameters:
dateTime
- TheDBDateTime
for which the milliseconds offset should be returned.- Returns:
- A long value of milliseconds since Epoch, or a
QueryConstants.NULL_LONG
value if theDBDateTime
is null.
-
nanos
Returns nanoseconds since Epoch for aDBDateTime
value.- Parameters:
dateTime
- TheDBDateTime
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
Evaluates whether oneDBDateTime
value is earlier than a secondDBDateTime
value.- Parameters:
d1
- The firstDBDateTime
value to compare.d2
- The secondDBDateTime
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
Evaluates whether oneDBDateTime
value is later than a secondDBDateTime
value.- Parameters:
d1
- The firstDBDateTime
value to compare.d2
- The secondDBDateTime
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
Adds one time from another.- Parameters:
dateTime
- The startingDBDateTime
value.nanos
- The long number of nanoseconds to add to dateTime.- Returns:
- a null
DBDateTime
if either input is null; the startingDBDateTime
plus the specified number of nanoseconds, if the result is not too large for aDBDateTime
; or throws aDBDateTimeOverflowException
if the resultant value is more than max long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
dateTime
- The startingDBDateTime
value.nanos
- The long number of nanoseconds to subtract from dateTime.- Returns:
- a null
DBDateTime
if either input is null; the startingDBDateTime
minus the specified number of nanoseconds, if the result is not too negative for aDBDateTime
; or throws aDBDateTimeOverflowException
if the resultant value is more than min long nanoseconds from Epoch.
-
plus
Adds one time from another.- Parameters:
dateTime
- The startingDBDateTime
value.period
- TheDBPeriod
to add to dateTime.- Returns:
- a null
DBDateTime
if either input is null; the startingDBDateTime
plus the specified period, if the result is not too large for a DBDateTime; or throws aDBDateTimeOverflowException
if the resultant value is more than max long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
dateTime
- The startingDBDateTime
value.period
- TheDBPeriod
to subtract from dateTime.- Returns:
- a null
DBDateTime
if either input is null; the startingDBDateTime
minus the specified period, if the result is not too negative for aDBDateTime
; or throws aDBDateTimeOverflowException
if the resultant value is more than min long nanoseconds from Epoch.
-
minus
Subtracts one time from another.- Parameters:
d1
- The firstDBDateTime
.d2
- TheDBDateTime
to subtract from d1.- Returns:
QueryConstants.NULL_LONG
if either input is null; the long nanoseconds from Epoch value of the firstDBDateTime
minus d2, if the result is not out of range for a long value; or throws aDBDateTimeOverflowException
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. -
yearDiff
Deprecated. -
dayDiff
Deprecated. -
diffNanos
Returns the difference in nanoseconds between twoDBDateTime
values.- Parameters:
d1
- The firstDBDateTime
.d2
- The secondDBDateTime
.- Returns:
QueryConstants.NULL_LONG
if either input is null; the long nanoseconds from Epoch value of the firstDBDateTime
minus d2, if the result is not out of range for a long value; or throws aDBDateTimeOverflowException
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
Returns a double value of the number of 365 day units difference between twoDBDateTime
values.- Parameters:
start
- The firstDBDateTime
.end
- The secondDBDateTime
.- Returns:
QueryConstants.NULL_LONG
if either input is null; a double value of the number of 365 day periods obtained from the firstDBDateTime
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 aDBTimeUtils.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
Returns a double value of the number of days difference between twoDBDateTime
values.- Parameters:
start
- The firstDBDateTime
.end
- The secondDBDateTime
.- Returns:
QueryConstants.NULL_LONG
if either input is null; a double value of the number of days obtained from the firstDBDateTime
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 aDBDateTimeOverflowException
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
Returns aDBDateTime
for the requestedDBDateTime
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 aDBDateTime
representing midnight for the date and time zone of the inputs.
-
millisToDateAtMidnightNy
Returns aDBDateTime
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 theDBDateTime
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
Returns aDBDateTime
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 theDBDateTime
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
Returns a String date/time representation.- Parameters:
dateTime
- TheDBDateTime
to format as a String.timeZone
- TheDBTimeZone
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
Returns a String date/time representation of aDBDateTime
interpreted for the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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
Returns a String date representation of aDBDateTime
interpreted for a specified time zone.- Parameters:
dateTime
- TheDBDateTime
to format as a String.timeZone
- TheDBTimeZone
to 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 aDBDateTime
interpreted for the New York time zone.- Parameters:
dateTime
- TheDBDateTime
to 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 aDBDateTime
and specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the day of the month.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
dayOfMonthNy
Returns an int value of the day of the month for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
dayOfWeek
Returns an int value of the day of the week for aDBDateTime
in the specified time zone, with 1 being Monday and 7 being Sunday.- Parameters:
dateTime
- TheDBDateTime
for which to find the day of the week.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
dayOfWeekNy
Returns an int value of the day of the week for aDBDateTime
in the New York time zone, with 1 being Monday and 7 being Sunday.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
dayOfYear
Returns an int value of the day of the year (Julian date) for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the day of the year.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
dayOfYearNy
Returns an int value of the day of the year (Julian date) for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
hourOfDay
Returns an int value of the hour of the day for aDBDateTime
in the specified time zone. The hour is on a 24 hour clock (0 - 23).- Parameters:
dateTime
- TheDBDateTime
for which to find the hour of the day.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
hourOfDayNy
Returns an int value of the hour of the day for aDBDateTime
in the New York time zone. The hour is on a 24 hour clock (0 - 23).- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
millisOfDay
Returns an int value of milliseconds since midnight for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the milliseconds since midnight.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
millisOfDayNy
Returns an int value of milliseconds since midnight for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
millisOfSecond
Returns an int value of milliseconds since the top of the second for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the milliseconds.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
millisOfSecondNy
Returns an int value of milliseconds since the top of the second for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
nanosOfDay
Returns a long value of nanoseconds since midnight for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the nanoseconds since midnight.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
nanosOfDayNy
Returns a long value of nanoseconds since midnight for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
nanosOfSecond
Returns a long value of nanoseconds since the top of the second for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the nanoseconds.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
nanosOfSecondNy
Returns a long value of nanoseconds since the top of the second for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when 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 provideddateTime
in the specified time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.- Parameters:
dateTime
- TheDBDateTime
for which to find the microseconds.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
microsOfMilliNy
Returns the number of microseconds that have elapsed since the start of the millisecond represented by the provideddateTime
in the New York time zone. Nanoseconds are rounded, not dropped -- '20:41:39.123456700' has 457 micros, not 456.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
minuteOfDay
Returns an int value of minutes since midnight for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the minutes.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
minuteOfDayNy
Returns an int value of minutes since midnight for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
minuteOfHour
Returns an int value of minutes since the top of the hour for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the minutes.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
minuteOfHourNy
Returns an int value of minutes since the top of the hour for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
monthOfYear
Returns an int value for the month of aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the month.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone. January is 1, February is 2, etc.
-
monthOfYearNy
Returns an int value for the month of aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
secondOfDay
Returns an int value of seconds since midnight for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the seconds.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
secondOfDayNy
Returns an int value of seconds since midnight for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
secondOfMinute
Returns an int value of seconds since the top of the minute for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the seconds.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
secondOfMinuteNy
Returns an int value of seconds since the top of the minute for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
year
Returns an int value of the year for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the year.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
yearNy
Returns an int value of the year for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
yearOfCentury
Returns an int value of the two-digit year for aDBDateTime
in the specified time zone.- Parameters:
dateTime
- TheDBDateTime
for which to find the year.timeZone
- TheDBTimeZone
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 theDBDateTime
when interpreted in the specified time zone.
-
yearOfCenturyNy
Returns an int value of the two-digit year for aDBDateTime
in the New York time zone.- Parameters:
dateTime
- TheDBDateTime
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 theDBDateTime
when interpreted in the New York time zone.
-
getExcelDateTime
Returns the Excel double time format representation of aDBDateTime
.- Parameters:
dateTime
- TheDBDateTime
to convert.timeZone
- TheDBTimeZone
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
Returns the Excel double time format representation of aDBDateTime
.- Parameters:
dateTime
- TheDBDateTime
to convert.timeZone
- TheTimeZone
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
Returns the Excel double time format representation of aDBDateTime
.- Parameters:
dateTime
- TheDBDateTime
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 aDBTimeUtils.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
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_LONG
if the input is null, otherwise, aDBDateTime
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 toQueryConstants.NULL_LONG
. ThrowsDBTimeUtils.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 aDBTimeUtils.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
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_LONG
if the input is null, otherwise, aDBDateTime
representation 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_LONG
if the input is null, otherwise, aDBDateTime
representation 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 specifiedZonedDateTime
to nanoseconds since epoch, ornull
.- Parameters:
value
- the instant to convert- Returns:
- nanoseconds since epoch or
null
-
makeInstant
Convert nanos since epoch to anInstant
value.- Parameters:
nanos
- nanoseconds since epoch- Returns:
- a new
Instant
or null if nanos wasQueryConstants.NULL_LONG
.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTime
using thedefault
time zone.- Parameters:
nanos
- nanoseconds since epoch- Returns:
- a new
ZonedDateTime
or null if nanos wasQueryConstants.NULL_LONG
.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTime
.- Parameters:
nanos
- nanoseconds since epochtimeZone
- thetime zone
- Returns:
- a new
ZonedDateTime
or null if nanos wasQueryConstants.NULL_LONG
.
-
makeZonedDateTime
Converts nanos of epoch to aZonedDateTime
.- Parameters:
nanos
- nanoseconds since epochzone
- thetime zone
- Returns:
- a new
ZonedDateTime
or null if nanos wasQueryConstants.NULL_LONG
.
-
getZonedDateTime
Converts aDBDateTime
to aZonedDateTime
.- Parameters:
dateTime
- The aDBDateTime
to convert.- Returns:
- A
ZonedDateTime
using 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 aDBDateTime
to aZonedDateTime
.- Parameters:
dateTime
- The aDBDateTime
to convert.timeZone
- TheDBTimeZone
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 aDBDateTime
to aZonedDateTime
.- Parameters:
dateTime
- The aDBDateTime
to convert.timeZone
- TheZoneId
to use for the conversion.- Returns:
- A
ZonedDateTime
using the specified time zone. or null if dateTime was null
-
toDateTime
Converts aZonedDateTime
to aDBDateTime
.- Parameters:
zonedDateTime
- The aZonedDateTime
to convert.- Throws:
DBTimeUtils.DBDateTimeOverflowException
- if the input is out of the range for aDBDateTime
, otherwise, aDBDateTime
version of the input.
-
currentTime
Provides the current date/time, or, if a customtimeProvider
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
Provides a String representing the current date in the New York time zone or, if a customcurrentDateNyOverride
has 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 thelastBusinessDayNyOverride
to the previous business day from a currently setcurrentDateNyOverride
value. IfcurrentDateNyOverride
has 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 customlastBusinessDayNyOverride
has 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 customlastBusinessDayNyOverride
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
Returns a String of the current date in the specifiedDBTimeZone
.- Parameters:
timeZone
- TheDBTimeZone
to 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
, ornull
ifnanos
is 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_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 aDBDateTime
based on the inferred conversion.
-
cappedTimeOffset
Returns aDBDateTime
value based on a starting value and aDBPeriod
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 startingDBDateTime
value.period
- TheDBPeriod
to add to dateTime.cap
- ADBDateTime
value to use as the maximum return value.- Returns:
- a null
DBDateTime
if either original or period are null; the startingDBDateTime
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 aDBDateTimeOverflowException
if the resultant value is more than max long nanoseconds from Epoch.
-
lowerBin
Returns aDBDateTime
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
- TheDBDateTime
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
Returns aDBDateTime
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
- TheDBDateTime
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
Returns aDBDateTime
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
- TheDBDateTime
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
Returns aDBDateTime
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
- TheDBDateTime
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
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
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, orIllegalArgumentException
if 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 aDBDateTime
from 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
RuntimeException
if the String cannot be parsed.
-
convertPeriod
Converts a String into aDBPeriod
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 aDBPeriod
object.
-
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_LONG
if the String cannot be parsed, otherwise long nanoseconds offset from Epoch.
-
convertPeriodQuiet
Converts a String into aDBPeriod
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
Returns aChronoField
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
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
-