:mega: Please welcome our first step to the standa...
# stdlib
i
📣 Please welcome our first step to the standard way of working with time in Kotlin: Duration and time interval measurement API https://github.com/Kotlin/KEEP/blob/durations/proposals/stdlib/durations-and-clocks.md The proposal can be discussed in this issue: https://github.com/Kotlin/KEEP/issues/190
K 1
🎉 27
j
Will there be conversion extensions in stdlib-jdk8 to/from java.time?
i
Yes, most likely in kotlin-stdlib-jdk8
m
To clarify - this is only about durations (mostly for measuring/timeouts etc.) and not groundwork for a full time API à la
java.time
, isn't it?
s
From what I understand @Marc Knaup, this is working towards a full time API, as JB has stated in here before that a kotlinx time lib is in the design phase
m
s
Copy code
but we don’t currently plan to have full blown date-time (with time-zones, etc) for stdlib (too heavy).
for stdlib
it won't be in the stdlib, like I said, it's a kotlinx time lib
it's been mentioned in here before, several times in fact
m
Yeah but my question was about date/time MPP lib in general and that was the answer. I'll try to find the other indications because that's new to me (and good news then) 🙂
I can't find it. Can you please point me somewhere where I could find it? E.g. what channel?
s
If you search for "kotlinx time" the last mention was last November, when they were planning it but had yet to start on development. I believe it has been brought up since then but I can't find any additional indication of it
🙏 1
s
Is
TimedValue
really needed if this gets merged? https://youtrack.jetbrains.com/issue/KT-27856
l
I have some doubts with the duration constructs
Copy code
(...)e.g. 1.5.minutes, 30.seconds, 500.milliseconds. Otherwise the extension function numericValue.toDuration(unit) can be used.
Wouldn't 1.5.minutes, for example, pollute the namespace?
We already have a very big amount of extension functions in that namespace, and perhaps adding more and more will make that namespace way too big?
i
@LeoColman These extensions are in
kotlin.time
package, which isn't imported by default.
@spand Even despite
measureTime
has contract, still
val (result, elapsed) = measureTimedValue { ... }
is more convenient than
Copy code
val result: SomeType
val elapsed = measureTime { result = .... }
l
@ilya.gorbunov but when IntelliJ is autocompleting, they will show up, right?
i
Yes, they do.
l
That's what I'm afraid of. That list of functions will keep growing and growing. Do you see that as a possible issue?
m
Agree! It's annoying to have too many suggestions in autocompletion for things you rarely care about. That's a problem Xcode has right now with Swift where it became quite hard to find the right method sometimes. It would be great though if there was a feature for extensions which only show up for literals. E.g.
1.milliseconds
is okay but for variables it won't show up 🙂
Copy code
val errors = 1
errors.milliseconds // nope, not possible
j
That would potentially allow the language to remove its special-casing for unsigned literals
i
@jw I don't think that would help specifically unsigned literals because the literal handling depends on
u
suffix.
👍 1
m
Then like C++?
1ms
custom suffixes (at some point in the future)? Or
1.unsigned
😂
Copy code
suffix fun <http://Int.ms|Int.ms>() = Milliseconds(this)
suffix fun Int.u() = UInt(this)