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

Renaud

03/21/2023, 4:17 PM
I'm looking for an exhaustive list of why using kotlinx.datetime instead of java.time api. • Multi-platform? • TZ Data up-to-date ? Edit:Decoupled from language release
k

kevin.cianfarini

03/21/2023, 4:20 PM
Natively serializable by kotlinx serialization
k

kenkyee

03/21/2023, 4:20 PM
Does it use tzdata now? Used to not...
r

Renaud

03/21/2023, 4:24 PM
True, so how can we get an up-to-date timezone dataset then?
k

kenkyee

03/21/2023, 4:25 PM
That's why we use threetenabp on Android...
r

Renaud

03/21/2023, 4:27 PM
But ThreeTenAbp says:
Attention: Development on this library is winding down. Please consider switching to Android Gradle plugin 4.0,
java.time.*
, and its core library desugaring feature in the coming months.
So basically saying: "use java.time", right?
But
kotlinx.datatime
uses
java.time
under the wood or I am missing something?
To update
java.time
, this library was developped https://github.com/ZacSweers/ticktock
k

kenkyee

03/21/2023, 4:41 PM
Yep, on Android at least, just use the desugaring libs
r

Renaud

03/21/2023, 4:41 PM
What do you think make the kotlinx.datetime library useful then?
k

kevin.cianfarini

03/21/2023, 4:42 PM
MPP is the biggest one for me with serialization in a close second
If you’re doing Android only then it’s not worth the dep. There will be more samples online for java time than kotlinx
It would be fantastic if it had a way to natively update tz info, but I suppose that’s less of a concern with kotlinx since it’s decoupled from the language
m

mbonnin

03/21/2023, 5:38 PM
+1 on MPP. Also usage is a bit more idiomatic if you're used to Kotlin and extension functions:
Copy code
// kotlinx
someIsoStr.toLocalDateTime().date
vs
Copy code
// java.time
LocalDateTime.parse(someIsoStr).toLocalDate()
k

kevin.cianfarini

03/21/2023, 5:40 PM
The more I think about it the more I also like that it's decoupled from the language release cadence
r

Renaud

03/21/2023, 5:48 PM
That's a valid point indeed
11 Views