Package org.h2.util

# Class LegacyDateTimeUtils

java.lang.Object
org.h2.util.LegacyDateTimeUtils

public final class LegacyDateTimeUtils extends Object
Date and time utilities for `Date`, `Time`, and `Timestamp` classes.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Date`
`PROLEPTIC_GREGORIAN_CHANGE`
Gregorian change date for a `GregorianCalendar` that represents a proleptic Gregorian calendar.
`static final TimeZone`
`UTC`
UTC time zone.

## Method Summary

Modifier and Type
Method
Description
`static long`
`dateValueFromLocalMillis(long ms)`
Convert a local datetime in millis to an encoded date.
`static ValueDate`
`fromDate(CastDataProvider provider, TimeZone timeZone, Date date)`
Get or create a date value for the given date.
`static ValueTime`
`fromTime(CastDataProvider provider, TimeZone timeZone, Time time)`
Get or create a time value for the given time.
`static ValueTimestamp`
`fromTimestamp(CastDataProvider provider, long ms, int nanos)`
Get or create a timestamp value for the given date/time in millis.
`static ValueTimestamp`
`fromTimestamp(CastDataProvider provider, TimeZone timeZone, Timestamp timestamp)`
Get or create a timestamp value for the given timestamp.
`static long`
`getMillis(CastDataProvider provider, 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`
`getTimeZoneOffsetMillis(CastDataProvider provider, long ms)`
Returns local time zone offset for a specified timestamp.
`static TypeInfo`
`legacyClassToType(Class<?> clazz)`
Get the type information for the given legacy Java class.
`static Value`
`legacyObjectToValue(CastDataProvider session, Object x)`
Convert a legacy Java object to a value.
`static long`
`nanosFromLocalMillis(long ms)`
Convert a time in milliseconds in local time to the nanoseconds since midnight.
`static Date`
`toDate(CastDataProvider provider, TimeZone timeZone, Value value)`
Get the date value converted to the specified time zone.
`static Time`
`toTime(CastDataProvider provider, TimeZone timeZone, Value value)`
Get the time value converted to the specified time zone.
`static Timestamp`
`toTimestamp(CastDataProvider provider, TimeZone timeZone, Value value)`
Get the timestamp value converted to the specified time zone.
`static <T> T`
`valueToLegacyType(Class<T> type, Value value, CastDataProvider provider)`
Converts the specified value to an object of the specified legacy type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### PROLEPTIC_GREGORIAN_CHANGE

public static final Date PROLEPTIC_GREGORIAN_CHANGE
Gregorian change date for a `GregorianCalendar` that represents a proleptic Gregorian calendar.

### UTC

public static final TimeZone UTC
UTC time zone.

## Method Details

### fromDate

public static ValueDate fromDate(CastDataProvider provider, TimeZone timeZone, Date date)
Get or create a date value for the given date.

Parameters:
  `provider` - the cast information provider
  `timeZone` - time zone, or `null` for default
  `date` - the date
Returns:
  the value

### fromTime

public static ValueTime fromTime(CastDataProvider provider, TimeZone timeZone, Time time)
Get or create a time value for the given time.

Parameters:
  `provider` - the cast information provider
  `timeZone` - time zone, or `null` for default
  `time` - the time
Returns:
  the value

### fromTimestamp

public static ValueTimestamp fromTimestamp(CastDataProvider provider, TimeZone timeZone, Timestamp timestamp)
Get or create a timestamp value for the given timestamp.

Parameters:
  `provider` - the cast information provider
  `timeZone` - time zone, or `null` for default
  `timestamp` - the timestamp
Returns:
  the value

### fromTimestamp

public static ValueTimestamp fromTimestamp(CastDataProvider provider, long ms, int nanos)
Get or create a timestamp value for the given date/time in millis.

Parameters:
  `provider` - the cast information provider
  `ms` - the milliseconds
  `nanos` - the nanoseconds
Returns:
  the value

### dateValueFromLocalMillis

public static long dateValueFromLocalMillis(long ms)
Convert a local datetime in millis to an encoded date.

Parameters:
  `ms` - the milliseconds
Returns:
  the date value

### nanosFromLocalMillis

public static long nanosFromLocalMillis(long ms)
Convert a time in milliseconds in local time to the nanoseconds since midnight.

Parameters:
  `ms` - the milliseconds
Returns:
  the nanoseconds

### toDate

public static Date toDate(CastDataProvider provider, TimeZone timeZone, Value value)
Get the date value converted to the specified time zone.

Parameters:
  `provider` - the cast information provider
  `timeZone` - the target time zone
  `value` - the value to convert
Returns:
  the date

### toTime

public static Time toTime(CastDataProvider provider, TimeZone timeZone, Value value)
Get the time value converted to the specified time zone.

Parameters:
  `provider` - the cast information provider
  `timeZone` - the target time zone
  `value` - the value to convert
Returns:
  the time

### toTimestamp

public static Timestamp toTimestamp(CastDataProvider provider, TimeZone timeZone, Value value)
Get the timestamp value converted to the specified time zone.

Parameters:
  `provider` - the cast information provider
  `timeZone` - the target time zone
  `value` - the value to convert
Returns:
  the timestamp

### getMillis

public static long getMillis(CastDataProvider provider, TimeZone tz, long dateValue, long timeNanos)
Calculate the milliseconds since 1970-01-01 (UTC) for the given date and time (in the specified timezone).

Parameters:
  `provider` - the cast information provider
  `tz` - the timezone of the parameters, or null for the default timezone
  `dateValue` - date value
  `timeNanos` - nanoseconds since midnight
Returns:
  the number of milliseconds (UTC)

### getTimeZoneOffsetMillis

public static int getTimeZoneOffsetMillis(CastDataProvider provider, long ms)
Returns local time zone offset for a specified timestamp.

Parameters:
  `provider` - the cast information provider
  `ms` - milliseconds since Epoch in UTC
Returns:
  local time zone offset

### legacyObjectToValue

public static Value legacyObjectToValue(CastDataProvider session, Object x)
Convert a legacy Java object to a value.

Parameters:
  `session` - the session
  `x` - the value
Returns:
  the value, or `null` if not supported

### valueToLegacyType

public static <T> T valueToLegacyType(Class<T> type, Value value, CastDataProvider provider)
Converts the specified value to an object of the specified legacy type.

Type Parameters:
  `T` - the type
Parameters:
  `type` - the class
  `value` - the value
  `provider` - the cast information provider
Returns:
  an instance of the specified class, or `null` if not supported

### legacyClassToType

public static TypeInfo legacyClassToType(Class<?> clazz)
Get the type information for the given legacy Java class.

Parameters:
  `clazz` - the Java class
Returns:
  the value type, or `null` if not supported