org.h2.util

## Class LocalDateTimeUtils

- java.lang.Object
- - org.h2.util.LocalDateTimeUtils

    public class LocalDateTimeUtils
    extends java.lang.Object

This utility class contains time conversion functions for Java 8 Date and Time API classes.

This class is implemented using reflection so that it compiles on Java 7 as well.

For LocalDate and LocalTime the conversion methods provided by the JDK are used. For OffsetDateTime a custom conversion method is used because it has no equivalent in JDBC. For LocalDateTime a custom conversion method is used instead of the one provided by the JDK as well.

Using the JDK provided conversion method for LocalDateTime would introduces some errors in edge cases. Consider the following case: at 2016-03-27 02:00 in Europe/Berlin the clocks were set to 2016-03-27 03:00. This means that 2016-03-27 02:15 does not exist in Europe/Berlin. Unfortunately java.sql.Timestamp is in the the time zone of the JVM. That means if you run a JVM with the time zone Europe/Berlin then the SQL value 'TIMESTAMP 2016-03-27 02:15:00' can not be represented. java.time.LocalDateTime does not have these limitations but if we convert through java.sql.Timestamp we inherit its limitations. Therefore that conversion must be avoided.

Once the driver requires Java 8 all the reflection can be removed.

### Method Summary

Methods
`static java.lang.Class<?>` `getLocalDateClass()` Returns the class java.time.LocalDate.
`static java.lang.Class<?>` `getLocalDateTimeClass()` Returns the class java.time.LocalDateTime.
`static java.lang.Class<?>` `getLocalTimeClass()` Returns the class java.time.LocalTime.
`static java.lang.Class<?>` `getOffsetDateTimeClass()` Returns the class java.time.OffsetDateTime.
`static boolean` `isJava8DateApiPresent()` Checks if the Java 8 Date and Time API is present.
`static boolean` `isLocalDate(java.lang.Class<?> clazz)` Checks if the given class is LocalDate.
`static boolean` `isLocalDateTime(java.lang.Class<?> clazz)` Checks if the given class is LocalDateTime.
`static boolean` `isLocalTime(java.lang.Class<?> clazz)` Checks if the given class is LocalTime.
`static boolean` `isOffsetDateTime(java.lang.Class<?> clazz)` Checks if the given class is OffsetDateTime.
`static Value` `localDateTimeToValue(java.lang.Object localDateTime)` Converts a LocalDateTime to a Value.
`static Value` `localDateToDateValue(java.lang.Object localDate)` Converts a LocalDate to a Value.
`static Value` `localTimeToTimeValue(java.lang.Object localTime)` Converts a LocalTime to a Value.
`static Value` `offsetDateTimeToValue(java.lang.Object offsetDateTime)` Converts a OffsetDateTime to a Value.
`static java.lang.Object` `parseLocalDate(java.lang.CharSequence text)` Parses an ISO date string into a java.time.LocalDate.
`static java.lang.Object` `parseLocalDateTime(java.lang.CharSequence text)` Parses an ISO date string into a java.time.LocalDateTime.
`static java.lang.Object` `parseLocalTime(java.lang.CharSequence text)` Parses an ISO time string into a java.time.LocalTime.
`static java.lang.Object` `parseOffsetDateTime(java.lang.CharSequence text)` Parses an ISO date string into a java.time.OffsetDateTime.
`static java.lang.Object` `valueToLocalDate(Value value)` Converts a value to a LocalDate.
`static java.lang.Object` `valueToLocalDateTime(ValueTimestamp value)` Converts a value to a LocalDateTime.
`static java.lang.Object` `valueToLocalTime(Value value)` Converts a value to a LocalTime.
`static java.lang.Object` `valueToOffsetDateTime(ValueTimestampTimeZone value)` Converts a value to a OffsetDateTime.

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

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

### Method Detail

#### isJava8DateApiPresent

    public static boolean isJava8DateApiPresent()

Checks if the Java 8 Date and Time API is present.

This is the case on Java 8 and later and not the case on Java 7. Versions older than Java 7 are not supported.

Returns:
  if the Java 8 Date and Time API is present

#### getLocalDateClass

    public static java.lang.Class<?> getLocalDateClass()

Returns the class java.time.LocalDate.

Returns:
  the class java.time.LocalDate, null on Java 7

#### getLocalTimeClass

    public static java.lang.Class<?> getLocalTimeClass()

Returns the class java.time.LocalTime.

Returns:
  the class java.time.LocalTime, null on Java 7

#### getLocalDateTimeClass

    public static java.lang.Class<?> getLocalDateTimeClass()

Returns the class java.time.LocalDateTime.

Returns:
  the class java.time.LocalDateTime, null on Java 7

#### getOffsetDateTimeClass

    public static java.lang.Class<?> getOffsetDateTimeClass()

Returns the class java.time.OffsetDateTime.

Returns:
  the class java.time.OffsetDateTime, null on Java 7

#### parseLocalDate

    public static java.lang.Object parseLocalDate(java.lang.CharSequence text)

Parses an ISO date string into a java.time.LocalDate.

Parameters:
  `text` - the ISO date string
Returns:
  the java.time.LocalDate instance

#### parseLocalTime

    public static java.lang.Object parseLocalTime(java.lang.CharSequence text)

Parses an ISO time string into a java.time.LocalTime.

Parameters:
  `text` - the ISO time string
Returns:
  the java.time.LocalTime instance

#### parseLocalDateTime

    public static java.lang.Object parseLocalDateTime(java.lang.CharSequence text)

Parses an ISO date string into a java.time.LocalDateTime.

Parameters:
  `text` - the ISO date string
Returns:
  the java.time.LocalDateTime instance

#### parseOffsetDateTime

    public static java.lang.Object parseOffsetDateTime(java.lang.CharSequence text)

Parses an ISO date string into a java.time.OffsetDateTime.

Parameters:
  `text` - the ISO date string
Returns:
  the java.time.OffsetDateTime instance

#### isLocalDate

    public static boolean isLocalDate(java.lang.Class<?> clazz)

Checks if the given class is LocalDate.

This method can be called from Java 7.

Parameters:
  `clazz` - the class to check
Returns:
  if the class is LocalDate

#### isLocalTime

    public static boolean isLocalTime(java.lang.Class<?> clazz)

Checks if the given class is LocalTime.

This method can be called from Java 7.

Parameters:
  `clazz` - the class to check
Returns:
  if the class is LocalTime

#### isLocalDateTime

    public static boolean isLocalDateTime(java.lang.Class<?> clazz)

Checks if the given class is LocalDateTime.

This method can be called from Java 7.

Parameters:
  `clazz` - the class to check
Returns:
  if the class is LocalDateTime

#### isOffsetDateTime

    public static boolean isOffsetDateTime(java.lang.Class<?> clazz)

Checks if the given class is OffsetDateTime.

This method can be called from Java 7.

Parameters:
  `clazz` - the class to check
Returns:
  if the class is OffsetDateTime

#### valueToLocalDate

    public static java.lang.Object valueToLocalDate(Value value)

Converts a value to a LocalDate.

This method should only called from Java 8 or later.

Parameters:
  `value` - the value to convert
Returns:
  the LocalDate

#### valueToLocalTime

    public static java.lang.Object valueToLocalTime(Value value)

Converts a value to a LocalTime.

This method should only called from Java 8 or later.

Parameters:
  `value` - the value to convert
Returns:
  the LocalTime

#### valueToLocalDateTime

    public static java.lang.Object valueToLocalDateTime(ValueTimestamp value)

Converts a value to a LocalDateTime.

This method should only called from Java 8 or later.

Parameters:
  `value` - the value to convert
Returns:
  the LocalDateTime

#### valueToOffsetDateTime

    public static java.lang.Object valueToOffsetDateTime(ValueTimestampTimeZone value)

Converts a value to a OffsetDateTime.

This method should only called from Java 8 or later.

Parameters:
  `value` - the value to convert
Returns:
  the OffsetDateTime

#### localDateToDateValue

    public static Value localDateToDateValue(java.lang.Object localDate)

Converts a LocalDate to a Value.

Parameters:
  `localDate` - the LocalDate to convert, not `null`
Returns:
  the value

#### localTimeToTimeValue

    public static Value localTimeToTimeValue(java.lang.Object localTime)

Converts a LocalTime to a Value.

Parameters:
  `localTime` - the LocalTime to convert, not `null`
Returns:
  the value

#### localDateTimeToValue

    public static Value localDateTimeToValue(java.lang.Object localDateTime)

Converts a LocalDateTime to a Value.

Parameters:
  `localDateTime` - the LocalDateTime to convert, not `null`
Returns:
  the value

#### offsetDateTimeToValue

    public static Value offsetDateTimeToValue(java.lang.Object offsetDateTime)

Converts a OffsetDateTime to a Value.

Parameters:
  `offsetDateTime` - the OffsetDateTime to convert, not `null`
Returns:
  the value