Class NanoTimestamp

java.lang.Object
io.debezium.time.NanoTimestamp

public class NanoTimestamp extends Object
A utility for converting various Java time representations into the signed INT64 number of nanoseconds past epoch, and for defining a Kafka Connect Schema for timestamp values with no timezone information.
Author:
Randall Hauch
See Also:
  • Field Details

  • Constructor Details

    • NanoTimestamp

      private NanoTimestamp()
  • Method Details

    • builder

      public static org.apache.kafka.connect.data.SchemaBuilder builder()
      Returns a SchemaBuilder for a NanoTimestamp. The resulting schema will describe a field with the "io.debezium.time.NanoTimestamp" as the name and INT64 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 a NanoTimestamp but with all other default Schema settings. The schema describes a field with the "io.debezium.time.NanoTimestamp" as the name and INT64 for the literal type storing the number of nanoseconds past midnight.
      Returns:
      the schema
      See Also:
    • toEpochNanos

      public static long toEpochNanos(Object value, TemporalAdjuster adjuster)
      Get the number of nanoseconds past epoch of the given LocalDateTime, LocalDate, LocalTime, Date, Date, Time, or Timestamp.
      Parameters:
      value - the local or SQL date, time, or timestamp value; may not be null
      adjuster - 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 given LocalDateTime.
      Parameters:
      timestamp - the Java timestamp value
      Returns:
      the epoch nanoseconds
    • toEpochNanos

      private static long toEpochNanos(LocalDate date)
      Get the number of nanoseconds past epoch of the given LocalDate.
      Parameters:
      date - the Java date value
      Returns:
      the epoch nanoseconds