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

Use kotlinx-datetime instead of Java APIs #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MGaetan89
Copy link
Member

@MGaetan89 MGaetan89 commented Sep 2, 2024

Description

This PR replaces Java-specific APIs with Kotlin's ones. In particular, it:

Warning

This PR is a breaking change compared to the previous version!

kotlinx-datetime

  • ✅ It supports kotlinx-serialization out of the box. So the ISO8601DateParser and DateSerializer are no longer necessary.
  • ✅ It is a multiplatform library, in case we ever want to go down that road.
  • ⚠️ It is currently in alpha, meaning that its API may change or be removed at any time. However, according to Kotlin's roadmap, it should reach the beta status "soon" (KT-64578), meaning that the APIs is close to finalized and breaking changes should be rare.
  • ⚠️ On Android, it uses the java.time API internally. So if the min API is less than 26, core library desugaring is necessary.

Migration guide

The official documentation provides more information about kotlinx-datetime API, but here are some quick tips to help you get started:

Java API Kotlin API Example
Date() Clock.System.now()
Date.time Instant.toEpochMilliseconds()
Date.after(Date) Instant > Instant
Date.before(Date) Instant < Instant
Date(timestamp + offset) Instant + Duration Clock.System.now() + 5.minutes

Next steps

Following the merge of this PR:

@MGaetan89 MGaetan89 self-assigned this Sep 2, 2024
@MGaetan89 MGaetan89 marked this pull request as ready for review September 4, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🍿 Code Review
Development

Successfully merging this pull request may close these issues.

1 participant