https://kotlinlang.org logo
#kotlinx-datetime
Title
# kotlinx-datetime
s

Sam Stone

11/06/2023, 12:14 AM
How can I tell in advanced when the clocks will change?
e

ephemient

11/06/2023, 1:19 AM
kotlinx-datetime doesn't support that as of now
you can use
java.time
APIs, for example
Copy code
ZoneRulesProvider.getRules("Canada/Newfoundland", false).nextTransition(Instant.now())
but note that the JVM's data may not be up to date, and these things do change with some frequency (e.g. https://www.timeanddate.com/news/time/greenland-change-timezone.html this year)
d

Dmitry Khalanskiy [JB]

11/06/2023, 9:20 AM
Would be interesting to know why you need this functionality.
r

rocketraman

11/06/2023, 1:07 PM
Also worthwhile to know about, if you can't update the JVM runtime for some reason: https://www.oracle.com/java/technologies/javase/tzupdater-readme.html (that assumes you are using the Oracle JDK of course, other JDKs might have similar tools).
k

kevin.cianfarini

11/14/2023, 1:29 PM
I've actually had some questions about a related concept in the past. If timezones change for whatever reason is the expectation that kotlinx datetime will release an update with the latest tzdb info? Or is there another mechanism to update that info?
d

Dmitry Khalanskiy [JB]

11/14/2023, 1:30 PM
Currently, the
kotlinx-datetime
library doesn't include its own tzdb, instead using the one provided by the operating system.
r

rocketraman

11/14/2023, 1:34 PM
"Operating system" there I think is meant loosely: for code running on the JVM, its the JVM. For code running on JavaScript, its Joda Date I believe, and for native, its the OS via https://github.com/HowardHinnant/date. https://github.com/Kotlin/kotlinx-datetime/blob/HEAD/README.md?plain=1#L287-L292
Is that right @Dmitry Khalanskiy [JB]?
k

kevin.cianfarini

11/14/2023, 1:36 PM
Is there any ambition to bundle an up-to-date tzdb with kotlinx datetime?
d

Dmitry Khalanskiy [JB]

11/14/2023, 1:36 PM
Yeah, sorry, I should have said "by the platform." On the JS, you specify the dependency manually, on Native, it's the OS database, on the JVM, it's whatever the JVM exposes.
👍 1
There is such an ambition, here's why this could be needed: https://github.com/Kotlin/kotlinx-datetime/issues/201
e

ephemient

11/14/2023, 1:38 PM
iirc the JVM does have a mechanism to change the tzdata provider. at least on JVM platform, I think that would be a better solution because it'll be consistent throughout others Java usages in the same application
👍 1
found it,
java.time.zone.DefaultZoneRulesProvider
👍 1
k

kevin.cianfarini

11/14/2023, 1:42 PM
Neat!
Thanks for the link
Would bundling our own tzdb get rid of the need to declare an additional dependency for JS?
d

Dmitry Khalanskiy [JB]

11/14/2023, 1:48 PM
It would just mean specifying a different dependency, our own, that's available is multiplatform projects.
👍 1
k

kevin.cianfarini

11/14/2023, 1:55 PM
Oh I see. So you're envisioning that the tzdb would ship as a different library altogether, and kotlinx datetime would depend on it?
d

Dmitry Khalanskiy [JB]

11/14/2023, 1:57 PM
No, it's this different library that would depend on kotlinx-datetime. This way, one would be able to use kotlinx-datetime with or without depending on a separate tzdb.
👍 1
k

kevin.cianfarini

11/14/2023, 1:58 PM
Oh I see. Thanks for entertaining my questions.