Raphael TEYSSANDIER
10/23/2024, 9:09 AMDmitry Khalanskiy [JB]
10/23/2024, 9:10 AMRaphael TEYSSANDIER
10/23/2024, 9:17 AMDmitry Khalanskiy [JB]
10/23/2024, 9:19 AMRaphael TEYSSANDIER
10/23/2024, 9:24 AMInstantIso8601Serializer
doesn't support all format of the ISO 8601 ?Dmitry Khalanskiy [JB]
10/23/2024, 9:30 AMkotlinx.datetime.Instant
. It would be meaningless to try to parse P15DT12H
as an Instant
(DateTimePeriod
should be used for this format); likewise, 2024-01-16
is not an Instant
(it's a LocalDate
), and neither is something like 2024-10-23T21:59/2025-01-16T12:00
(which is a time interval, we don't provide those, as there doesn't seem to be any demand).Dmitry Khalanskiy [JB]
10/23/2024, 9:33 AMInstant
is @Serializable
by default, and it uses the ISO 8601 strings as the format. Please see https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/kotlinx.datetime.format[…]omponents/-formats/-i-s-o_-d-a-t-e_-t-i-m-e_-o-f-f-s-e-t.htmlRaphael TEYSSANDIER
10/23/2024, 9:36 AM--01-13T12:00
. Thank you very muchDmitry Khalanskiy [JB]
10/23/2024, 9:40 AMMonthDay
in the library, everything includes the year), but you can still define it:
import kotlinx.datetime.format.*
import kotlinx.datetime.*
fun main() {
val format = DateTimeComponents.Format {
chars("--"); monthNumber(); char('-'); dayOfMonth()
alternativeParsing({ char('t') }) { char('T') }
time(LocalTime.Formats.ISO)
}
format.parse("--01-13T12:00").let {
println("Month is ${it.month}")
println("Day is ${it.dayOfMonth}")
println("Time is ${it.toLocalTime()}")
}
}
Prints
Month is JANUARY
Day is 13
Time is 12:00
Runnable: https://pl.kotl.in/_Lo55HPq8Raphael TEYSSANDIER
10/23/2024, 9:43 AM