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 long |
SECONDS_PER_DAY
The number of seconds per day.
|
static int |
SHIFT_MONTH
The offset of month bits in date values.
|
static int |
SHIFT_YEAR
The offset of year bits in date values.
|
| 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 java.lang.StringBuilder |
appendDate(java.lang.StringBuilder builder,
long dateValue)
Append a date to the string builder.
|
static java.lang.StringBuilder |
appendTime(java.lang.StringBuilder builder,
long nanos)
Append a time to the string builder.
|
static java.lang.StringBuilder |
appendTimeZone(java.lang.StringBuilder builder,
int tz)
Append a time zone to the string builder.
|
static long |
convertScale(long nanosOfDay,
int scale,
long range)
Converts scale of nanoseconds.
|
static ValueTimestampTimeZone |
currentTimestamp(TimeZoneProvider timeZone)
Returns current timestamp.
|
static ValueTimestampTimeZone |
currentTimestamp(TimeZoneProvider timeZone,
java.time.Instant now)
Returns current timestamp using the specified instant for its value.
|
static long[] |
dateAndTimeFromValue(Value value,
CastDataProvider provider)
Extracts date value and nanos of day from the specified value.
|
static Value |
dateTimeToValue(Value original,
long dateValue,
long timeNanos)
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 |
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 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 |
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 |
getWeekYearAbsoluteStart(int weekYear,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
Get absolute day of the first day in the 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 |
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 |
timestampTimeZoneAtOffset(long dateValue,
long timeNanos,
int oldOffset,
int newOffset)
Moves timestamp with time zone to a new time zone.
|
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 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 int SHIFT_YEAR
public static final int SHIFT_MONTH
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 ValueTimestampTimeZone currentTimestamp(TimeZoneProvider timeZone)
timeZone - the time zonepublic static ValueTimestampTimeZone currentTimestamp(TimeZoneProvider timeZone, java.time.Instant now)
timeZone - the time zonenow - timestamp source, must be greater than or equal to
1970-01-01T00:00:00Zpublic 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, may be null for
Standard-compliant literalswithTimeZone - 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 long getEpochSeconds(long dateValue,
long timeNanos,
int offsetSeconds)
dateValue - date valuetimeNanos - nanoseconds since midnightoffsetSeconds - time zone offset in secondspublic static long[] dateAndTimeFromValue(Value value, CastDataProvider provider)
value - value to extract fields fromprovider - the cast information providerpublic static Value dateTimeToValue(Value original, long dateValue, long timeNanos)
original - original valuedateValue - date value for the returned valuetimeNanos - nanos of day for the returned valuepublic 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 long getWeekYearAbsoluteStart(int weekYear,
int firstDayOfWeek,
int minimalDaysInFirstWeek)
weekYear - the week yearfirstDayOfWeek - first day of week, Monday as 1, Sunday as 7 or 0minimalDaysInFirstWeek - minimal days in first week of yearpublic 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 nanosFromLocalSeconds(long localSeconds)
localSeconds - the seconds since 1970-01-01public static long normalizeNanosOfDay(long nanos)
nanos - the nanoseconds (may be negative or larger than one day)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 java.lang.StringBuilder appendDate(java.lang.StringBuilder builder,
long dateValue)
builder - the target string builderdateValue - the date valuepublic static java.lang.StringBuilder appendTime(java.lang.StringBuilder builder,
long nanos)
builder - the target string buildernanos - the time in nanosecondspublic static java.lang.StringBuilder appendTimeZone(java.lang.StringBuilder builder,
int tz)
builder - the target string buildertz - 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)public static ValueTimestampTimeZone timestampTimeZoneAtOffset(long dateValue, long timeNanos, int oldOffset, int newOffset)
dateValue - the date valuetimeNanos - the nanoseconds since midnightoldOffset - old offsetnewOffset - new offset