Skip to content

Migrates to kotlin.time.Instant from the stdlib#469

Closed
JayShortway wants to merge 4 commits into
mainfrom
instant-stdlib
Closed

Migrates to kotlin.time.Instant from the stdlib#469
JayShortway wants to merge 4 commits into
mainfrom
instant-stdlib

Conversation

@JayShortway

Copy link
Copy Markdown
Member

Description

The Instant (and Clock) types are moving from the kotlinx-datetime library to Kotlin's stdlib. They're available since Kotlin 2.1.20. Concretely this means that kotlinx.datetime.Instant is deprecated and replaced by kotlin.time.Instant. This PR makes use of the new type, and removes the kotlinx-datetime dependency (because we don't use anything else).

This is technically a breaking change, but the kotlinx-datetime library is still experimental in its entirety. This will only affect devs using that experimental library already.

The alternative is to bump the version of the kotlinx-datetime library to 0.7.1, which is a compatibility release still containing the deprecated types, but that's just delays the inevitable. Happy to hear thoughts.

Closes #468

@JayShortway JayShortway requested a review from a team August 12, 2025 08:42
@JayShortway JayShortway self-assigned this Aug 12, 2025
* * For Google subscriptions, productIds are `subscriptionId:basePlanId`.
* * For Amazon subscriptions, productsIds are `termSku`.
*/
@OptIn(ExperimentalTime::class)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to propagate these annotations?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're using types that are experimental, I think that makes sense to me!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed to propagate these annotations.

Comment thread datetime/api/datetime.api
public static final fun getLatestExpirationInstant (Lcom/revenuecat/purchases/kmp/models/CustomerInfo;)Lkotlinx/datetime/Instant;
public static final fun getOriginalPurchaseInstant (Lcom/revenuecat/purchases/kmp/models/CustomerInfo;)Lkotlinx/datetime/Instant;
public static final fun getRequestInstant (Lcom/revenuecat/purchases/kmp/models/CustomerInfo;)Lkotlinx/datetime/Instant;
public static final fun getFirstSeenInstant (Lcom/revenuecat/purchases/kmp/models/CustomerInfo;)Lkotlin/time/Instant;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm as you said this is a breaking change. I think it would be ok to do this, as long as devs had to previously OptIn into an experimental flag to be able to use them. If not, I would consider holding using the compatibility library version if possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main question is that before it seems we were able to use these types in the API tests without opting in to the experimental flag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that there's no way around that. Even updating to 0.7.1 and using kotlinx.datetime.Instant (the deprecated type), we're forced to add the experimental flag.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh :( So... I guess we're forced to do a breaking change... I really would love to avoid a major but wondering if we should do it, even if it's due to a dependency...

@skydoves skydoves left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great to me!

* * For Google subscriptions, productIds are `subscriptionId:basePlanId`.
* * For Amazon subscriptions, productsIds are `termSku`.
*/
@OptIn(ExperimentalTime::class)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed to propagate these annotations.

@JayShortway

Copy link
Copy Markdown
Member Author

Closing in favor of #514

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update KotlinX Date/Time to 0.7.1

3 participants