How can I tell in advanced when the clocks will ch...
# kotlinx-datetime
s
How can I tell in advanced when the clocks will change?
e
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
Would be interesting to know why you need this functionality.
r
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
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
Currently, the
kotlinx-datetime
library doesn't include its own tzdb, instead using the one provided by the operating system.
r
"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
Is there any ambition to bundle an up-to-date tzdb with kotlinx datetime?
d
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
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
Neat!
Thanks for the link
Would bundling our own tzdb get rid of the need to declare an additional dependency for JS?
d
It would just mean specifying a different dependency, our own, that's available is multiplatform projects.
👍 1
k
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
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
Oh I see. Thanks for entertaining my questions.