Kotlin doesn’t provide in the stdlib any support for datetime operations, even if in most real-world applications this datatype is very much used. To perform computations, you need to download an external dependency and import kotlinx.datetime
.
The name of the basic DateTime object is LocalDateTime, which is a reference to the name Java used to fix Java’s broken Date
/Calendar
API. However, it doesn’t behave the same and requires manual casting to convert them. This leads to serialization quirks when using Hibernate/Spring/Quarkus applications and Kotlin libraries (i.e. kotlinx.serialization). Being an opaque casting, it will also break composability and portability.
Kotlin already transparently maps String
, List
, Map
, etc., to platform-native types. Why can’t we do the same with LocalDateTime
, bringing it in the kotlin-stdlib
(and maybe calling it just DateTime
or KDateTime
to express it is a native type)?