Hello, What is the preferred way to map between `J...
# kotlinx-datetime
d
Hello, What is the preferred way to map between
JSJoda.Instant
and
Instant
?
1
Copy code
private fun Instant.toJsInstant() = InstantJs.ofEpochMilli(toEpochMilliseconds())

private fun InstantJs.toInstant() = Instant.fromEpochMilliseconds(toEpochMilli().toLong())
I created two extension functions but I’m wondering if there is a better way to do that.
d
Copy code
private fun Instant.toJsInstant() = InstantJs.ofEpochSecond(epochSeconds, nanosecondsOfSecond)

private fun InstantJs.toInstant() = Instant.fromEpochSeconds(epochSecond().toLong(), nano().toInt())
This will also preserve the nanosecond portion.