jvmMain.io.islandtime.internal.PlatformImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-metadata Show documentation
Show all versions of core-metadata Show documentation
A multiplatform library for working with dates and times
The newest version!
package io.islandtime.internal
import io.islandtime.*
import io.islandtime.jvm.toIslandInstant
import io.islandtime.jvm.toJavaInstant
internal actual fun systemDefaultTimeZone(): TimeZone = java.util.TimeZone.getDefault().toIslandTimeZone()
internal actual fun PlatformInstant.toIslandInstant(): Instant = this.toIslandInstant()
internal actual fun Instant.toPlatformInstant(): PlatformInstant = this.toJavaInstant()
private var lastDefaultTimeZone: Pair? = null
internal fun java.util.TimeZone.toIslandTimeZone(): TimeZone {
lastDefaultTimeZone?.let { (javaZone, islandZone) ->
if (this == javaZone) {
return islandZone
}
}
val id = id
val islandZone = if (id.startsWith("GMT")) {
if (id.length == 3) {
TimeZone.Region(id)
} else {
TimeZone.FixedOffset(id.substring(3))
}
} else {
TimeZone.Region(id)
}
lastDefaultTimeZone = this to islandZone
return islandZone
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy