public class DateTimeUtils
extends java.lang.Object
Date value: a bit field with bits for the year, month, and day. Absolute day: the day number (0 means 1970-01-01).
| Modifier and Type | Field and Description |
|---|---|
static int |
EPOCH_DATE_VALUE
Date value for 1970-01-01.
|
static long |
MAX_DATE_VALUE
Maximum possible date value.
|
static long |
MILLIS_PER_DAY
The number of milliseconds per day.
|
static long |
MIN_DATE_VALUE
Minimum possible date value.
|
static long |
NANOS_PER_DAY
The number of nanoseconds per day.
|
static long |
NANOS_PER_HOUR
The number of nanoseconds per hour.
|
static long |
NANOS_PER_MINUTE
The number of nanoseconds per minute.
|
static long |
NANOS_PER_SECOND
The number of nanoseconds per second.
|
static java.sql.Date |
PROLEPTIC_GREGORIAN_CHANGE
Gregorian change date for a
GregorianCalendar that represents a
proleptic Gregorian calendar. |
static long |
SECONDS_PER_DAY
The number of seconds per day.
|
static java.util.TimeZone |
UTC
UTC time zone.
|
| Modifier and Type | Method and Description |
|---|---|
static long |
absoluteDayFromDateValue(long dateValue)
Calculate the absolute day from an encoded date value.
|
static long |
absoluteDayFromYear(long year)
Calculate the absolute day for a January, 1 of the specified year.
|
static void |
appendDate(java.lang.StringBuilder buff,
long dateValue)
Append a date to the string builder.
|
static void |
appendTime(java.lang.StringBuilder buff,
long nanos)
Append a time to the string builder.
|
static void |
appendTimestampTimeZone(java.lang.StringBuilder buff,
long dateValue,
long timeNanos,
int timeZoneOffsetSeconds)
Formats timestamp with time zone as string.
|
static void |
appendTimeZone(java.lang.StringBuilder buff,
int tz)
Append a time zone to the string builder.
|
static long |
convertScale(long nanosOfDay,
int scale,
long range)
Converts scale of nanoseconds.
|
static long[] |
dateAndTimeFromValue(Value value)
Extracts date value and nanos of day from the specified value.
|
static Value |
dateTimeToValue(Value original,
long dateValue,
long timeNanos,
boolean forceTimestamp)
Creates a new date-time value with the same type as original value.
|
static long |
dateValue(long year,
int month,
int day)
Get the date value from a given date.
|
static long |
dateValueFromAbsoluteDay(long absoluteDay)
Calculate the encoded date value from an absolute day.
|
static long |
dateValueFromDenormalizedDate(long year,
long month,
int day)
Get the date value from a given denormalized date with possible out of range
values of month and/or day.
|
static long |
dateValueFromLocalMillis(long ms)
Convert a local datetime in millis to an encoded date.
|
static long |
dateValueFromLocalSeconds(long localSeconds)
Convert a local seconds to an encoded date.
|
static int |
dayFromDateValue(long x)
Get the day of month from a date value.
|
static long |
decrementDateValue(long dateValue)
Return the previous date value.
|
static int |
getDayOfWeek(long dateValue,
int firstDayOfWeek)
Returns day of week.
|
static int |
getDayOfWeekFromAbsolute(long absoluteValue,
int firstDayOfWeek)
Get the day of the week from the absolute day value.
|
static int |
getDayOfYear(long dateValue)
Returns number of day in year.
|
static int |
getDaysInMonth(int year,
int month)
Returns number of days in month.
|
static long |
getEpochSeconds(long dateValue,
long timeNanos,
int offsetSeconds)
Calculates the seconds since epoch for the specified date value,
nanoseconds since midnight, and time zone offset.
|
static int |
getIsoDayOfWeek(long dateValue)
Returns ISO day of week.
|
static int |
getIsoWeekOfYear(long dateValue)
Returns ISO number of week in year.
|
static int |
getIsoWeekYear(long dateValue)
Returns ISO week year.
|
static long |
getMillis(java.util.TimeZone tz,
long dateValue,
long timeNanos)
Calculate the milliseconds since 1970-01-01 (UTC) for the given date and
time (in the specified timezone).
|
static int |
getSundayDayOfWeek(long dateValue)
Returns day of week with Sunday as 1.
|
static TimeZoneProvider |
getTimeZone()
Get the time zone provider for the default time zone.
|
static int |
getTimeZoneOffset(long epochSeconds)
Returns local time zone offset for a specified EPOCH second.
|
static int |
getTimeZoneOffset(long dateValue,
long timeNanos)
Calculates the time zone offset in seconds for the specified date
value, and nanoseconds since midnight.
|
static int |
getTimeZoneOffsetMillis(long ms)
Returns local time zone offset for a specified timestamp.
|
static int |
getWeekOfYear(long dateValue,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
Returns number of week in year.
|
static int |
getWeekYear(long dateValue,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
Returns week year.
|
static long |
incrementDateValue(long dateValue)
Return the next date value.
|
static boolean |
isValidDate(int year,
int month,
int day)
Verify if the specified date is valid.
|
static int |
monthFromDateValue(long x)
Get the month from a date value.
|
static long |
nanosFromLocalMillis(long ms)
Convert a time in milliseconds in local time to the nanoseconds since midnight.
|
static long |
nanosFromLocalSeconds(long localSeconds)
Convert a time in seconds in local time to the nanoseconds since midnight.
|
static long |
normalizeNanosOfDay(long nanos)
Calculate the normalized nanos of day.
|
static long |
parseDateValue(java.lang.String s,
int start,
int end)
Parse a date string.
|
static long |
parseTimeNanos(java.lang.String s,
int start,
int end)
Parse a time string.
|
static Value |
parseTimestamp(java.lang.String s,
CastDataProvider provider,
boolean withTimeZone)
Parses timestamp value from the specified string.
|
static ValueTimeTimeZone |
parseTimeWithTimeZone(java.lang.String s,
CastDataProvider provider)
Parses TIME WITH TIME ZONE value from the specified string.
|
static void |
resetCalendar()
Reset the cached calendar for default timezone, for example after
changing the default timezone.
|
static ValueTimestampTimeZone |
timestampTimeZoneFromLocalDateValueAndNanos(long dateValue,
long timeNanos)
Converts local date value and nanoseconds to timestamp with time zone.
|
static ValueTimestampTimeZone |
timestampTimeZoneFromMillis(long ms)
Creates the instance of the
ValueTimestampTimeZone from milliseconds. |
static java.lang.String |
timeZoneNameFromOffsetSeconds(int offsetSeconds)
Generates time zone name for the specified offset in seconds.
|
static int |
yearFromDateValue(long x)
Get the year from a date value.
|
public static final long MILLIS_PER_DAY
public static final long SECONDS_PER_DAY
public static final java.util.TimeZone UTC
public static final long NANOS_PER_SECOND
public static final long NANOS_PER_MINUTE
public static final long NANOS_PER_HOUR
public static final long NANOS_PER_DAY
public static final java.sql.Date PROLEPTIC_GREGORIAN_CHANGE
GregorianCalendar that represents a
proleptic Gregorian calendar.public static final int EPOCH_DATE_VALUE
public static final long MIN_DATE_VALUE
public static final long MAX_DATE_VALUE
public static void resetCalendar()
public static TimeZoneProvider getTimeZone()
public static long parseDateValue(java.lang.String s,
int start,
int end)
s - the string to parsestart - the parse index startend - the parse index endjava.lang.IllegalArgumentException - if there is a problempublic static long parseTimeNanos(java.lang.String s,
int start,
int end)
s - the string to parsestart - the parse index startend - the parse index endjava.lang.IllegalArgumentException - if there is a problempublic static Value parseTimestamp(java.lang.String s, CastDataProvider provider, boolean withTimeZone)
s - string to parseprovider - the cast information provider, or nullwithTimeZone - if true return ValueTimestampTimeZone instead of
ValueTimestamppublic static ValueTimeTimeZone parseTimeWithTimeZone(java.lang.String s, CastDataProvider provider)
s - string to parseprovider - the cast information provider, or nullpublic static int getTimeZoneOffset(long dateValue,
long timeNanos)
dateValue - date valuetimeNanos - nanoseconds since midnightpublic static int getTimeZoneOffsetMillis(long ms)
ms - milliseconds since Epoch in UTCpublic static int getTimeZoneOffset(long epochSeconds)
epochSeconds - seconds since Epoch in UTCpublic static long getEpochSeconds(long dateValue,
long timeNanos,
int offsetSeconds)
dateValue - date valuetimeNanos - nanoseconds since midnightoffsetSeconds - time zone offset in secondspublic static long getMillis(java.util.TimeZone tz,
long dateValue,
long timeNanos)
tz - the timezone of the parameters, or null for the default
timezonedateValue - date valuetimeNanos - nanoseconds since midnightpublic static long[] dateAndTimeFromValue(Value value)
value - value to extract fields frompublic static Value dateTimeToValue(Value original, long dateValue, long timeNanos, boolean forceTimestamp)
original - original valuedateValue - date value for the returned valuetimeNanos - nanos of day for the returned valueforceTimestamp - if true return ValueTimestamp if original argument is
ValueDate or ValueTimepublic static int getDayOfWeek(long dateValue,
int firstDayOfWeek)
dateValue - the date valuefirstDayOfWeek - first day of week, Monday as 1, Sunday as 7 or 0getIsoDayOfWeek(long)public static int getDayOfWeekFromAbsolute(long absoluteValue,
int firstDayOfWeek)
absoluteValue - the absolute dayfirstDayOfWeek - the first day of the weekpublic static int getDayOfYear(long dateValue)
dateValue - the date valuepublic static int getIsoDayOfWeek(long dateValue)
dateValue - the date valuegetSundayDayOfWeek(long)public static int getIsoWeekOfYear(long dateValue)
dateValue - the date valuegetIsoWeekYear(long),
getWeekOfYear(long, int, int)public static int getIsoWeekYear(long dateValue)
dateValue - the date valuegetIsoWeekOfYear(long),
getWeekYear(long, int, int)public static int getSundayDayOfWeek(long dateValue)
dateValue - the date valuegetIsoDayOfWeek(long)public static int getWeekOfYear(long dateValue,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
dateValue - the date valuefirstDayOfWeek - first day of week, Monday as 1, Sunday as 7 or 0minimalDaysInFirstWeek - minimal days in first week of yeargetIsoWeekOfYear(long)public static int getWeekYear(long dateValue,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
dateValue - the date valuefirstDayOfWeek - first day of week, Monday as 1, Sunday as 7 or 0minimalDaysInFirstWeek - minimal days in first week of yeargetIsoWeekYear(long)public static int getDaysInMonth(int year,
int month)
year - the yearmonth - the monthpublic static boolean isValidDate(int year,
int month,
int day)
year - the yearmonth - the month (January is 1)day - the day (1 is the first of the month)public static int yearFromDateValue(long x)
x - the date valuepublic static int monthFromDateValue(long x)
x - the date valuepublic static int dayFromDateValue(long x)
x - the date valuepublic static long dateValue(long year,
int month,
int day)
year - the yearmonth - the month (1..12)day - the day (1..31)public static long dateValueFromDenormalizedDate(long year,
long month,
int day)
year - the yearmonth - the month, if out of range month and year will be normalizedday - the day of the month, if out of range it will be saturatedpublic static long dateValueFromLocalSeconds(long localSeconds)
localSeconds - the seconds since 1970-01-01public static long dateValueFromLocalMillis(long ms)
ms - the millisecondspublic static long nanosFromLocalSeconds(long localSeconds)
localSeconds - the seconds since 1970-01-01public static long nanosFromLocalMillis(long ms)
ms - the millisecondspublic static long normalizeNanosOfDay(long nanos)
nanos - the nanoseconds (may be negative or larger than one day)public static ValueTimestampTimeZone timestampTimeZoneFromLocalDateValueAndNanos(long dateValue, long timeNanos)
dateValue - date valuetimeNanos - nanoseconds since midnightpublic static ValueTimestampTimeZone timestampTimeZoneFromMillis(long ms)
ValueTimestampTimeZone from milliseconds.ms - milliseconds since 1970-01-01 (UTC)public static long absoluteDayFromYear(long year)
year - the yearpublic static long absoluteDayFromDateValue(long dateValue)
dateValue - the date valuepublic static long dateValueFromAbsoluteDay(long absoluteDay)
absoluteDay - the absolute daypublic static long incrementDateValue(long dateValue)
dateValue - the date valuepublic static long decrementDateValue(long dateValue)
dateValue - the date valuepublic static void appendDate(java.lang.StringBuilder buff,
long dateValue)
buff - the target string builderdateValue - the date valuepublic static void appendTime(java.lang.StringBuilder buff,
long nanos)
buff - the target string buildernanos - the time in nanosecondspublic static void appendTimeZone(java.lang.StringBuilder buff,
int tz)
buff - the target string buildertz - the time zone offset in secondspublic static void appendTimestampTimeZone(java.lang.StringBuilder buff,
long dateValue,
long timeNanos,
int timeZoneOffsetSeconds)
buff - the target string builderdateValue - the year-month-day bit fieldtimeNanos - nanoseconds since midnighttimeZoneOffsetSeconds - the time zone offset in secondspublic static java.lang.String timeZoneNameFromOffsetSeconds(int offsetSeconds)
offsetSeconds - time zone offset in secondspublic static long convertScale(long nanosOfDay,
int scale,
long range)
nanosOfDay - nanoseconds of dayscale - fractional seconds precisionrange - the allowed range of values (0..range-1)