diff --git a/core/jvm/src/TimeZoneJvm.kt b/core/jvm/src/TimeZoneJvm.kt index 5a5846382..6ec4b9c8a 100644 --- a/core/jvm/src/TimeZoneJvm.kt +++ b/core/jvm/src/TimeZoneJvm.kt @@ -44,7 +44,7 @@ public actual open class TimeZone internal constructor(internal val zoneId: Zone internal fun ofZone(zoneId: ZoneId): TimeZone = when { zoneId is jtZoneOffset -> FixedOffsetTimeZone(UtcOffset(zoneId)) - zoneId.rules.isFixedOffset -> + zoneId.isFixedOffset -> FixedOffsetTimeZone(UtcOffset(zoneId.normalized() as jtZoneOffset), zoneId) else -> TimeZone(zoneId) @@ -54,6 +54,15 @@ public actual open class TimeZone internal constructor(internal val zoneId: Zone } } +// Workaround for https://issuetracker.google.com/issues/203956057 +private val ZoneId.isFixedOffset: Boolean + get() = try { + // On older Android versions, this can throw even though it shouldn't + rules.isFixedOffset + } catch (e: ArrayIndexOutOfBoundsException) { + false // Happens for America/Costa_Rica, Africa/Cairo, Egypt + } + @Serializable(with = FixedOffsetTimeZoneSerializer::class) public actual class FixedOffsetTimeZone internal constructor(public actual val offset: UtcOffset, zoneId: ZoneId): TimeZone(zoneId) {