Package io.debezium.time
Class NanoTimestamp
- java.lang.Object
-
- io.debezium.time.NanoTimestamp
-
public class NanoTimestamp extends Object
A utility for converting various Java time representations into the signedINT64
number of nanoseconds past epoch, and for defining a Kafka ConnectSchema
for timestamp values with no timezone information.- Author:
- Randall Hauch
- See Also:
Timestamp
,MicroTimestamp
,ZonedTimestamp
-
-
Field Summary
Fields Modifier and Type Field Description static String
SCHEMA_NAME
-
Constructor Summary
Constructors Modifier Constructor Description private
NanoTimestamp()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.kafka.connect.data.SchemaBuilder
builder()
Returns aSchemaBuilder
for aNanoTimestamp
.static org.apache.kafka.connect.data.Schema
schema()
Returns a Schema for aNanoTimestamp
but with all other default Schema settings.static long
toEpochNanos(Object value, TemporalAdjuster adjuster)
private static long
toEpochNanos(LocalDate date)
Get the number of nanoseconds past epoch of the givenLocalDate
.private static long
toEpochNanos(LocalDateTime timestamp)
Get the number of nanoseconds past epoch of the givenLocalDateTime
.
-
-
-
Field Detail
-
SCHEMA_NAME
public static final String SCHEMA_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
builder
public static org.apache.kafka.connect.data.SchemaBuilder builder()
Returns aSchemaBuilder
for aNanoTimestamp
. The resulting schema will describe a field with the "io.debezium.time.NanoTimestamp" as thename
andINT64
for the literal type storing the number of nanoseconds past midnight.You can use the resulting SchemaBuilder to set or override additional schema settings such as required/optional, default value, and documentation.
- Returns:
- the schema builder
-
schema
public static org.apache.kafka.connect.data.Schema schema()
Returns a Schema for aNanoTimestamp
but with all other default Schema settings. The schema describes a field with the "io.debezium.time.NanoTimestamp" as thename
andINT64
for the literal type storing the number of nanoseconds past midnight.- Returns:
- the schema
- See Also:
builder()
-
toEpochNanos
public static long toEpochNanos(Object value, TemporalAdjuster adjuster)
Get the number of nanoseconds past epoch of the givenLocalDateTime
,LocalDate
,LocalTime
,Date
,Date
,Time
, orTimestamp
.- Parameters:
value
- the local or SQL date, time, or timestamp value; may not be nulladjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary- Returns:
- the epoch nanoseconds
- Throws:
IllegalArgumentException
- if the value is not an instance of the acceptable types
-
toEpochNanos
private static long toEpochNanos(LocalDateTime timestamp)
Get the number of nanoseconds past epoch of the givenLocalDateTime
.- Parameters:
timestamp
- the Java timestamp value- Returns:
- the epoch nanoseconds
-
-