LocalDateTimeUtils

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.

Custom conversion methods between H2 internal values and JSR-310 classes are used in most cases without intermediate conversions to java.sql classes. Direct conversion is simpler, faster, and it does not inherit limitations and issues from java.sql classes and conversion methods provided by JDK.

The only one exclusion is a conversion between {@link Timestamp} and Instant.

Once the driver requires Java 8 and Android API 26 all the reflection can be removed.



Methods
static Value instantToValue(Object instant)
Converts a Instant to a Value.
static Value instantToValue(Object instant)
Converts a Instant to a Value.
Parameters:
instant - the Instant to convert, not {@code null}
Returns:
the value
static boolean isJava8DateApiPresent()
Checks if the Java 8 Date and Time API is present.
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
static Value localDateTimeToValue(Object localDateTime)
Converts a LocalDateTime to a Value.
static Value localDateTimeToValue(Object localDateTime)
Converts a LocalDateTime to a Value.
Parameters:
localDateTime - the LocalDateTime to convert, not {@code null}
Returns:
the value
static Value localDateToDateValue(Object localDate)
Converts a LocalDate to a Value.
static Value localDateToDateValue(Object localDate)
Converts a LocalDate to a Value.
Parameters:
localDate - the LocalDate to convert, not {@code null}
Returns:
the value
static Value localTimeToTimeValue(Object localTime)
Converts a LocalTime to a Value.
static Value localTimeToTimeValue(Object localTime)
Converts a LocalTime to a Value.
Parameters:
localTime - the LocalTime to convert, not {@code null}
Returns:
the value
static Value offsetDateTimeToValue(Object offsetDateTime)
Converts a OffsetDateTime to a Value.
static Value offsetDateTimeToValue(Object offsetDateTime)
Converts a OffsetDateTime to a Value.
Parameters:
offsetDateTime - the OffsetDateTime to convert, not {@code null}
Returns:
the value
static Object parseLocalDate(CharSequence text)
Parses an ISO date string into a java.time.LocalDate.
static Object parseLocalDate(CharSequence text)
Parses an ISO date string into a java.time.LocalDate.
Parameters:
text - the ISO date string
Returns:
the java.time.LocalDate instance
static Object parseLocalDateTime(CharSequence text)
Parses an ISO date string into a java.time.LocalDateTime.
static Object parseLocalDateTime(CharSequence text)
Parses an ISO date string into a java.time.LocalDateTime.
Parameters:
text - the ISO date string
Returns:
the java.time.LocalDateTime instance
static Object parseLocalTime(CharSequence text)
Parses an ISO time string into a java.time.LocalTime.
static Object parseLocalTime(CharSequence text)
Parses an ISO time string into a java.time.LocalTime.
Parameters:
text - the ISO time string
Returns:
the java.time.LocalTime instance
static Object parseOffsetDateTime(CharSequence text)
Parses an ISO date string into a java.time.OffsetDateTime.
static Object parseOffsetDateTime(CharSequence text)
Parses an ISO date string into a java.time.OffsetDateTime.
Parameters:
text - the ISO date string
Returns:
the java.time.OffsetDateTime instance
static Object valueToInstant(Value value)
Converts a value to a Instant.
static Object valueToInstant(Value value)
Converts a value to a Instant.

This method should only called from Java 8 or later.

Parameters:
value - the value to convert
Returns:
the Instant
static Object valueToLocalDate(Value value)
Converts a value to a LocalDate.
static 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
static Object valueToLocalDateTime(Value value)
Converts a value to a LocalDateTime.
static Object valueToLocalDateTime(Value 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
static Object valueToLocalTime(Value value)
Converts a value to a LocalTime.
static 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
static Object valueToOffsetDateTime(Value value)
Converts a value to a OffsetDateTime.
static Object valueToOffsetDateTime(Value 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

Fields
static Class INSTANT
static Class LOCAL_DATE
static Class LOCAL_DATE_TIME
static Class LOCAL_TIME
static Class OFFSET_DATE_TIME

INSTANT

{@code Class} or {@code null}.

LOCAL_DATE

{@code Class} or {@code null}.

LOCAL_DATE_TIME

{@code Class} or {@code null}.

LOCAL_TIME

{@code Class} or {@code null}.

OFFSET_DATE_TIME

{@code Class} or {@code null}.