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

Add java.time.Clock converter #249

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

Conversation

GrahamBorland
Copy link

Adds a function to convert a java.time.Clock to a kotlinx.datetime.Clock.

@GrahamBorland GrahamBorland changed the title Add clock converter Add java.time.Clock converter Feb 7, 2023
/**
* Converts this [java.time.Clock][java.time.Clock] to a [kotlinx.datetime.Clock][Clock].
*/
public fun java.time.Clock.toKotlinClock(): Clock = this.let {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use let? Just remove it and return the object directly.

Copy link
Author

Choose a reason for hiding this comment

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

Oops, thanks. Fixed. 😄

@ilya-g
Copy link
Member

ilya-g commented Apr 28, 2023

Could you describe cases when such conversion could be useful?

@GrahamBorland
Copy link
Author

When you have a Java clock (e.g. injected from DI on Android) and you want to pass it to a KMP library using kotlinx-datetime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants