vulcan
vulcan copied to clipboard
Introduce codecs for instant micros and local timestamp millis
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
Hello @bplommer , can you take a look when you get the chance?
Any news on this @bplommer?