Kotlin has a Duration class that is usable in JVM and JS. But how to serialize it between the two? I know how to write a serializer, so I’m really asking: how to round trip a Duration with some other primitive value(s).
Does this always pass?
val dur: Duration = ...
assertEquals(dur.inSeconds.seconds, dur)
The class has toIsoString() but it appears I have to write the inverse (the parser) myself. It shouldn’t be too hard, but once I have the components, as ints or doubles, there is no obvious API to construct a Duration from components. Yes, I can do something like
val d: Duration = dayPart.days + hourPart.hours + ...
But depending on the class internals, I might get floating point rounding and not get the exact same Duration after a round trip.