Skip to content

Comments

Introduce codecs for instant micros and local timestamp millis#524

Open
lucaviolanti wants to merge 4 commits intofd4s:masterfrom
lucaviolanti:introduce-instant-micros
Open

Introduce codecs for instant micros and local timestamp millis#524
lucaviolanti wants to merge 4 commits intofd4s:masterfrom
lucaviolanti:introduce-instant-micros

Conversation

@lucaviolanti
Copy link
Contributor

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

@filosganga filosganga requested a review from bplommer May 22, 2023 08:59
@bphenriques
Copy link

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

@Dieman89
Copy link

Any news on this @bplommer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants