- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.DateTimeUtils
-
public class DateTimeUtils extends Object
Utilities for working with date/time values.
-
-
Field Summary
Fields Modifier and Type Field Description static TimeZoneCST_TIMEZONEstatic TimeZoneLOCALTZDeprecated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longepochDaysToMillis(long epochDays, TimeZone tz)Gets the instant in time at midnight in the specified time zone corresponding to the given date.static Stringformat(DateValued value)Converts a date value into an ISO8601 date formatted string.static Stringformat(TimestampValued value)Converts a time stamp value into an ISO8601 time stamp formatted string.static Stringformat(TimeValued value)Converts a time of day value into an ISO8601 time formatted string.static StringformatDaysSinceEpoch(long epochDays)Converts a date, expressed as days, into an ISO8601 date formatted string.static StringformatEpochTime(long seconds, int nanos, int offsetSecs)Converts a time stamp, expressed as component values, into an ISO8601 time stamp formatted string.static StringformatMillisSinceMidnight(int dayMillis)Converts a time of day, expressed as milliseconds, into an ISO8601 time formatted string.static org.joda.time.chrono.ISOChronologygetDefaultChronology()static TimeZonegetDefaultTimeZone()static intnormalizeMillisSinceMidnight(long millis)Normalize elapsed milliseconds to the standard range from midnight to midnight.protected static intparseIntField(String str, int startPos, int endPos)static voidparseInto(String text, DateSettable buffer)Parses a date in ISO8601 format, storing the result into a date valued container.static voidparseInto(String text, TimeSettable buffer)Parses a time of day in ISO8601 time format, storing the result into a time valued container.static voidparseInto(String text, TimestampSettable buffer)Parses a timestamp in ISO8601 format, storing the result into a timestamp valued container..static intparseTimeFields(String str, com.pervasive.datarush.tokens.scalar.DateTimeUtils.TimeParsingContext ctx, int pos)static longparseToDaysSinceEpoch(String text)Parses a date in ISO8601 time format into days since epoch.static intparseToMillisSinceMidnight(String text)Parses a time of day in ISO8601 time format into milliseconds since midnight.static DatetoDate(long epochDays)Gets the instant in time at midnight in the default time zone corresponding to the given date.static DatetoDate(long epochDays, TimeZone tz)Gets the instant in time at midnight in the specified time zone corresponding to the given date.static longtoDaysSinceEpoch(int year, int monthOfYear, int dayOfMonth)Gets the specified date as days since epoch.static longtoDaysSinceEpoch(long millis)Gets the date represented by the given instant in the default time zone as days since epoch.static longtoDaysSinceEpoch(long millis, TimeZone tz)Gets the date represented by the given instant in the specified time zone as days since epoch.static longtoDaysSinceEpoch(Date date)Gets the date represented by the given instant in the default time zone as days since epoch.static longtoDaysSinceEpoch(Date date, TimeZone tz)Gets the date represented by the given instant in the specified time zone as days since epoch.static voidtoEpochTime(long millis, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the default time zone for the offset.static voidtoEpochTime(long millis, TimeZone tz, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the specified time zone for the offset.static voidtoEpochTime(Timestamp timestamp, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the default time zone for the offset.static voidtoEpochTime(Timestamp timestamp, TimeZone tz, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the specified time zone for the offset.static voidtoEpochTime(Date date, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the default time zone for the offset.static voidtoEpochTime(Date date, TimeZone tz, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the specified time zone for the offset.static inttoMillisSinceMidnight(int hourOfDay, int minuteOfHour, int secondOfMinute)Gets the time, in 24-hour format, as milliseconds since midnight.static inttoMillisSinceMidnight(long instant)Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.static inttoMillisSinceMidnight(long instant, int tzoffset)Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.static inttoMillisSinceMidnight(long instant, TimeZone tz)Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.static inttoMillisSinceMidnight(Date time)Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.static inttoMillisSinceMidnight(Date time, TimeZone tz)Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.static TimetoTime(long dayMillis)Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.static TimetoTime(long dayMillis, TimeZone tz)Gets the instant in time on January 1, 1970 in the specified time zone corresponding to the given time of day.static TimestamptoTimestamp(long epochSecs, int subsecNanos, int offsetSecs)Gets the instant in time on corresponding to the specified epoch time.static voidwithCSTTimeZone(Runnable runnable)
-
-
-
Field Detail
-
LOCALTZ
@Deprecated public static final TimeZone LOCALTZ
Deprecated.The default time zone used in date conversions. This matches the time zone returned byTimeZone.getDefault(). Deprecated because this static instance is unsafe to use because tests or end users may want to set the default Timezone late and that should be respected. Only use TimeZone.getDefault directly instead.
-
CST_TIMEZONE
public static final TimeZone CST_TIMEZONE
-
-
Method Detail
-
parseIntField
protected static int parseIntField(String str, int startPos, int endPos)
-
parseTimeFields
public static int parseTimeFields(String str, com.pervasive.datarush.tokens.scalar.DateTimeUtils.TimeParsingContext ctx, int pos)
-
toDaysSinceEpoch
public static long toDaysSinceEpoch(int year, int monthOfYear, int dayOfMonth)Gets the specified date as days since epoch.- Parameters:
year- the year portion of the datemonthOfYear- the month portion of the date. Months are counted as on a calendar, starting with 1 for January.dayOfMonth- the day portion of the date- Returns:
- the number of days elapsed since January 1, 1970
-
toDaysSinceEpoch
public static long toDaysSinceEpoch(long millis)
Gets the date represented by the given instant in the default time zone as days since epoch.- Parameters:
millis- the instant in time to convert- Returns:
- the number of days elapsed since January 1, 1970
-
toDaysSinceEpoch
public static long toDaysSinceEpoch(long millis, TimeZone tz)Gets the date represented by the given instant in the specified time zone as days since epoch.- Parameters:
millis- the instant in time to converttz- the time zone relative to which to interpret the instant- Returns:
- the number of days elapsed since January 1, 1970
-
toDaysSinceEpoch
public static long toDaysSinceEpoch(Date date)
Gets the date represented by the given instant in the default time zone as days since epoch.- Parameters:
date- the instant in time to converttz- the time zone relative to which to interpret the instant- Returns:
- the number of days elapsed since January 1, 1970
-
toDaysSinceEpoch
public static long toDaysSinceEpoch(Date date, TimeZone tz)
Gets the date represented by the given instant in the specified time zone as days since epoch.- Parameters:
date- the instant in time to converttz- the time zone relative to which to interpret the instant- Returns:
- the number of days elapsed since January 1, 1970
-
epochDaysToMillis
public static long epochDaysToMillis(long epochDays, TimeZone tz)Gets the instant in time at midnight in the specified time zone corresponding to the given date.- Parameters:
epochDays- the number of milliseconds elapsed since January 1, 1970tz- the time zone relative to which to convert the date- Returns:
- the resulting instant in time as milliseconds in epoch
-
toDate
public static Date toDate(long epochDays)
Gets the instant in time at midnight in the default time zone corresponding to the given date.- Parameters:
epochDays- the number of milliseconds elapsed since January 1, 1970- Returns:
- a
Dateobject representing the date
-
toDate
public static Date toDate(long epochDays, TimeZone tz)
Gets the instant in time at midnight in the specified time zone corresponding to the given date.- Parameters:
epochDays- the number of milliseconds elapsed since January 1, 1970tz- the time zone relative to which to convert the date- Returns:
- a
Dateobject representing the date
-
parseToDaysSinceEpoch
public static long parseToDaysSinceEpoch(String text)
Parses a date in ISO8601 time format into days since epoch.- Parameters:
text- a date in ISO8601 format- Returns:
- the number of days elapsed since January 1, 1970
-
parseInto
public static void parseInto(String text, DateSettable buffer)
Parses a date in ISO8601 format, storing the result into a date valued container. The empty string is parsed as a null value.- Parameters:
text- a date in ISO8601 format.buffer- the container in which to store the parsed value
-
formatDaysSinceEpoch
public static String formatDaysSinceEpoch(long epochDays)
Converts a date, expressed as days, into an ISO8601 date formatted string.- Parameters:
epochDays- the number of days elapsed since January 1, 1970- Returns:
- the date in ISO8601 format
-
format
public static String format(DateValued value)
Converts a date value into an ISO8601 date formatted string.- Parameters:
value- the date value to convert- Returns:
- the date in ISO8601 format. If the input is null valued, the empty string is returned.
-
normalizeMillisSinceMidnight
public static int normalizeMillisSinceMidnight(long millis)
Normalize elapsed milliseconds to the standard range from midnight to midnight.- Parameters:
millis- milliseconds elapsed since midnight- Returns:
- the normalize milliseconds representing the same time of day
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(int hourOfDay, int minuteOfHour, int secondOfMinute)Gets the time, in 24-hour format, as milliseconds since midnight.- Parameters:
hourOfDay- the hour portion of the timeminuteOfHour- the minutes portion of the timesecondOfMinute- the seconds portion of the time- Returns:
- the number of milliseconds elapsed since midnight
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(long instant)
Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.- Parameters:
instant- the instant in time to convert- Returns:
- the number of milliseconds elapsed since midnight
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(long instant, TimeZone tz)Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.- Parameters:
instant- the instant in time to converttz- the time zone relative to which to interpret the instant- Returns:
- the number of milliseconds elapsed since midnight
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(long instant, int tzoffset)Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.- Parameters:
instant- the instant in time to converttzoffset- the time zone offset with which to interpret the instant- Returns:
- the number of milliseconds elapsed since midnight
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(Date time)
Gets the time of day represented by the given instant in the default time zone as milliseconds since midnight.- Parameters:
time- the instant in time to convert- Returns:
- the number of milliseconds elapsed since midnight
-
toMillisSinceMidnight
public static int toMillisSinceMidnight(Date time, TimeZone tz)
Gets the time of day represented by the given instant in the specified time zone as milliseconds since midnight.- Parameters:
time- the instant in time to converttz- the time zone relative to which to interpret the instant- Returns:
- the number of milliseconds elapsed since midnight
-
toTime
public static Time toTime(long dayMillis)
Gets the instant in time on January 1, 1970 in the default time zone corresponding to the given time of day.- Parameters:
dayMillis- the number of milliseconds elapsed since midnight- Returns:
- a
Timeobject representing the time of day
-
toTime
public static Time toTime(long dayMillis, TimeZone tz)
Gets the instant in time on January 1, 1970 in the specified time zone corresponding to the given time of day.- Parameters:
dayMillis- the number of milliseconds elapsed since midnighttz- the time zone relative to which to convert the time of day- Returns:
- a
Timeobject representing the time of day
-
parseToMillisSinceMidnight
public static int parseToMillisSinceMidnight(String text)
Parses a time of day in ISO8601 time format into milliseconds since midnight.- Parameters:
text- a time of day in ISO8601 format- Returns:
- the number of milliseconds elapsed since midnight
-
parseInto
public static void parseInto(String text, TimeSettable buffer)
Parses a time of day in ISO8601 time format, storing the result into a time valued container. The empty string is parsed as a null value.- Parameters:
text- a time of day in ISO8601 format.buffer- the container in which to store the parsed value
-
formatMillisSinceMidnight
public static String formatMillisSinceMidnight(int dayMillis)
Converts a time of day, expressed as milliseconds, into an ISO8601 time formatted string.- Parameters:
millisSinceMidnight- the number of milliseconds elapsed since midnight- Returns:
- the time of day in ISO8601 format
-
format
public static String format(TimeValued value)
Converts a time of day value into an ISO8601 time formatted string.- Parameters:
value- the time value to format- Returns:
- the time of day in ISO8601 format. If the input is null valued, the empty string is returned.
-
toEpochTime
public static void toEpochTime(long millis, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the default time zone for the offset.- Parameters:
millis- the instant in time to convertbuffer- the container into which to store the value
-
toEpochTime
public static void toEpochTime(long millis, TimeZone tz, TimestampSettable buffer)Stores the given instant into a time stamp buffer using the specified time zone for the offset.- Parameters:
millis- the instant in time to converttz- the time zone relative to which to interpret the instantbuffer- the container into which to store the value
-
toEpochTime
public static void toEpochTime(Date date, TimestampSettable buffer)
Stores the given instant into a time stamp buffer using the default time zone for the offset. Nanosecond precision in the source value will be preserved, if present.- Parameters:
date- the instant in time to convertbuffer- the container into which to store the value
-
toEpochTime
public static void toEpochTime(Date date, TimeZone tz, TimestampSettable buffer)
Stores the given instant into a time stamp buffer using the specified time zone for the offset. Nanosecond precision in the source value will be preserved, if present.- Parameters:
date- the instant in time to converttz- the time zone relative to which to interpret the instantbuffer- the container into which to store the value
-
toEpochTime
public static void toEpochTime(Timestamp timestamp, TimestampSettable buffer)
Stores the given instant into a time stamp buffer using the default time zone for the offset. The nanosecond precision of the source value is preserved.- Parameters:
timestamp- the instant in time to convertbuffer- the container into which to store the value
-
toEpochTime
public static void toEpochTime(Timestamp timestamp, TimeZone tz, TimestampSettable buffer)
Stores the given instant into a time stamp buffer using the specified time zone for the offset. The nanosecond precision of the source value is preserved.- Parameters:
timestamp- the instant in time to converttz- the time zone relative to which to interpret the instantbuffer- the container into which to store the value
-
toTimestamp
public static Timestamp toTimestamp(long epochSecs, int subsecNanos, int offsetSecs)
Gets the instant in time on corresponding to the specified epoch time.- Parameters:
epochSecs- number of seconds since Java epochsubsecNanos- fractional portion of epoch time in nanosecondsoffsetSecs- time zone + daylight saving time offset in secondsdayMillis- the number of milliseconds elapsed since midnight- Returns:
- a
Timestampobject representing the time stamp
-
parseInto
public static void parseInto(String text, TimestampSettable buffer)
Parses a timestamp in ISO8601 format, storing the result into a timestamp valued container.. The empty string is parsed as a null value.- Parameters:
text- a timestamp in ISO8601 format.buffer- the container in which to store the parsed value
-
formatEpochTime
public static String formatEpochTime(long seconds, int nanos, int offsetSecs)
Converts a time stamp, expressed as component values, into an ISO8601 time stamp formatted string.- Parameters:
seconds- number of seconds since Java epochnanos- fractional portion of epoch time in nanosecondsoffsetSeconds- time zone and daylight saving time offset, in seconds- Returns:
- the time stamp in ISO8601 format
-
format
public static String format(TimestampValued value)
Converts a time stamp value into an ISO8601 time stamp formatted string.- Parameters:
value- the time stamp value to format- Returns:
- the time stamp in ISO8601 format. If the input is null valued, the empty string is returned.
-
getDefaultTimeZone
public static TimeZone getDefaultTimeZone()
-
withCSTTimeZone
public static void withCSTTimeZone(Runnable runnable)
-
getDefaultChronology
public static org.joda.time.chrono.ISOChronology getDefaultChronology()
-
-