vulcan icon indicating copy to clipboard operation
vulcan copied to clipboard

Introduce codecs for instant micros and local timestamp millis

Open lucaviolanti opened this issue 2 years ago • 2 comments

The codec for instant micros introduces a custom type that wraps Instant (to avoid clashing with the existing codec for Instant). Alternatively we already have another branch that introduces a non-implicit variant of the form

  lazy val instantMicros: Codec.Aux[Avro.Long, Instant] =
    LongCodec
      .imap { microsSinceEpoch =>
        Instant.ofEpochSecond(
          MICROSECONDS.toSeconds(microsSinceEpoch),
          MICROSECONDS.toNanos(Math.floorMod(microsSinceEpoch, SECONDS.toMicros(1)))
        )
      } { instant =>
        NANOSECONDS.toMicros(SECONDS.toNanos(instant.getEpochSecond) + instant.getNano)
      }
      .withLogicalType(LogicalTypes.timestampMicros)
      .withTypeName("Instant")

Co-authored by: @bphenriques @filosganga

lucaviolanti avatar May 19 '23 16:05 lucaviolanti

Hello @bplommer , can you take a look when you get the chance?

bphenriques avatar Jul 25 '23 14:07 bphenriques

Any news on this @bplommer?

Dieman89 avatar Jan 26 '24 12:01 Dieman89