Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce codecs for instant micros and local timestamp millis #524

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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