Class LocalDateTimeField
java.lang.Object
io.datarouter.model.field.BaseField<T>
io.datarouter.model.field.BasePrimitiveField<java.time.LocalDateTime,LocalDateTimeFieldKey>
io.datarouter.model.field.imp.custom.LocalDateTimeField
- All Implemented Interfaces:
ByteEncodedField<java.time.LocalDateTime>,StringEncodedField<java.time.LocalDateTime>,Field<java.time.LocalDateTime>,java.lang.Comparable<Field<java.time.LocalDateTime>>
public class LocalDateTimeField extends BasePrimitiveField<java.time.LocalDateTime,LocalDateTimeFieldKey>
LocalDateTime stores the value of nanoseconds in a range from 0 to 999,999,999.
However, the MySQL DATETIME column type cannot handle this level of granularity
(it can handle at most 6 digits of fractional seconds).
LocalDateTimeField defaults to a truncation of the LocalDateTime nanosecond value of up to 3 fractional seconds
as this corresponds to the fractional seconds granularity of System.currentTimeMillis() and LocalDateTime.now().
This is the recommended use, but can be overridden to store the full value.
A LocalDateTime object created using LocalDateTime::of might not be equivalent to a LocalDateTime retrieved from
MySQL because of the truncation of nanoseconds. Use .now() or use the LocalDateTime::of method that
ignores the nanoseconds field
-
Nested Class Summary
Nested classes/interfaces inherited from class io.datarouter.model.field.BaseField
BaseField.FieldColumnNameComparator -
Field Summary
-
Constructor Summary
Constructors Constructor Description LocalDateTimeField(LocalDateTimeFieldKey key, java.time.LocalDateTime value)LocalDateTimeField(java.lang.String prefix, LocalDateTimeFieldKey key, java.time.LocalDateTime value) -
Method Summary
Modifier and Type Method Description java.time.LocalDateTimefromBytesButDoNotSet(byte[] bytes, int offset)byte[]getBytes()intgetNumFractionalSeconds()java.lang.StringgetStringEncodedValue()java.time.LocalDateTimegetTruncatedLocalDateTime(java.time.LocalDateTime value)intnumBytesWithSeparator(byte[] bytes, int offset)java.time.LocalDateTimeparseStringEncodedValueButDoNotSet(java.lang.String str)Methods inherited from class io.datarouter.model.field.BaseField
fromBytesWithSeparatorButDoNotSet, fromString, getBytesWithSeparator, getPrefix, getPrefixedName, getPreparedStatementValue, getValue, getValueHashCode, getValueString, setPrefix, setUsingReflection, setValue, toString
-
Field Details
-
pattern
public static final java.lang.String pattern- See Also:
- Constant Field Values
-
formatter
public static final java.time.format.DateTimeFormatter formatter
-
-
Constructor Details
-
LocalDateTimeField
-
LocalDateTimeField
public LocalDateTimeField(java.lang.String prefix, LocalDateTimeFieldKey key, java.time.LocalDateTime value)
-
-
Method Details
-
getTruncatedLocalDateTime
public java.time.LocalDateTime getTruncatedLocalDateTime(java.time.LocalDateTime value) -
getNumFractionalSeconds
public int getNumFractionalSeconds() -
getStringEncodedValue
public java.lang.String getStringEncodedValue() -
parseStringEncodedValueButDoNotSet
public java.time.LocalDateTime parseStringEncodedValueButDoNotSet(java.lang.String str) -
getBytes
public byte[] getBytes() -
numBytesWithSeparator
public int numBytesWithSeparator(byte[] bytes, int offset) -
fromBytesButDoNotSet
public java.time.LocalDateTime fromBytesButDoNotSet(byte[] bytes, int offset)
-