Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Multiplatform equivalent for java.util.concurrent.TimeUnit? #7

Closed
abissell opened this issue May 30, 2018 · 4 comments
Closed

Multiplatform equivalent for java.util.concurrent.TimeUnit? #7

abissell opened this issue May 30, 2018 · 4 comments

Comments

@abissell
Copy link

A lot of Kotlin devs are probably used to this API especially for conversion between different units of time. Would you be interested in a (probably very small) PR to add a multiplatform version?

@soywiz
Copy link
Collaborator

soywiz commented May 30, 2018

Yeah, I would accept PRs. But, whats the benefit over this?

val time = 10.seconds
val tenSecondsInMilliseconds = time.milliseconds

@abissell abissell reopened this May 30, 2018
@abissell
Copy link
Author

abissell commented May 31, 2018

One benefit of TimeUnit is that it can convert between values without any class instantiation, but that may not be enough of a gain to justify adding it to the API. Maybe all that's needed is a little translation layer within the JVM module for conversions to work with Java/Kotlin APIs which expect a Long and a TimeUnit, like withTimeout. I'll chew it over for a bit and try to get you a PR. And thanks for the great library! :)

@soywiz
Copy link
Collaborator

soywiz commented May 31, 2018

Yeah, right now it instantates objects. The same goes for operator overloads:
1.seconds + 1000.milliseconds instantiates 3 objects. But it is safer to do artithmetic this way, and nicer for arguments and for storing times.
Allocation will be zero once inline classes ships: Kotlin/KEEP#103
And/Or project valhalla. Since most of these classes are immutable with a single field.

Still, if you think it makes sense, create a PR :)

@soywiz
Copy link
Collaborator

soywiz commented Nov 1, 2018

Klock 1.0.0 will be released later this week and will use Kotlin 1.3 inline, so I guess that this is not required anymore. I'm closing it. Feel free to reopen if required.

@soywiz soywiz closed this as completed Nov 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants