Package utils

Class TimestampTzConverter

java.lang.Object
utils.TimestampTzConverter

public final class TimestampTzConverter extends Object
Bridges MEOS TimestampTz values and java.time types.

A MEOS TimestampTz is a signed 64-bit count of microseconds since the PostgreSQL epoch. This class converts that count to and from OffsetDateTime and LocalDateTime, applying both the epoch offset and the microsecond unit.

Timezone resolution stays in MEOS: a timestamp string is parsed by pg_timestamptz_in; this class only converts the numeric TimestampTz.

  • Field Details

    • EPOCH_UNIX_SECONDS

      private static final long EPOCH_UNIX_SECONDS
      Unix seconds at the PostgreSQL epoch.
      See Also:
    • MICROS_PER_SECOND

      private static final long MICROS_PER_SECOND
      See Also:
    • NANOS_PER_MICRO

      private static final long NANOS_PER_MICRO
      See Also:
  • Constructor Details

    • TimestampTzConverter

      private TimestampTzConverter()
  • Method Details

    • toTimestampTz

      public static long toTimestampTz(OffsetDateTime t)
      Converts an OffsetDateTime to a MEOS TimestampTz (microseconds since the PostgreSQL epoch).
    • toTimestampTz

      public static long toTimestampTz(LocalDateTime t)
      Converts a LocalDateTime, taken as UTC, to a MEOS TimestampTz.
    • toOffsetDateTime

      public static OffsetDateTime toOffsetDateTime(long ts)
      Converts a MEOS TimestampTz to an OffsetDateTime in UTC.
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(long ts)
      Converts a MEOS TimestampTz to a LocalDateTime in UTC.
    • toInstant

      private static Instant toInstant(long ts)