Skip to content

Commit 03cdf17

Browse files
authored
Work around a crash on older Android versions (#150)
Fixes #149
1 parent 1709b81 commit 03cdf17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/jvm/src/TimeZoneJvm.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public actual open class TimeZone internal constructor(internal val zoneId: Zone
4444
internal fun ofZone(zoneId: ZoneId): TimeZone = when {
4545
zoneId is jtZoneOffset ->
4646
FixedOffsetTimeZone(UtcOffset(zoneId))
47-
zoneId.rules.isFixedOffset ->
47+
zoneId.isFixedOffset ->
4848
FixedOffsetTimeZone(UtcOffset(zoneId.normalized() as jtZoneOffset), zoneId)
4949
else ->
5050
TimeZone(zoneId)
@@ -54,6 +54,15 @@ public actual open class TimeZone internal constructor(internal val zoneId: Zone
5454
}
5555
}
5656

57+
// Workaround for https://issuetracker.google.com/issues/203956057
58+
private val ZoneId.isFixedOffset: Boolean
59+
get() = try {
60+
// On older Android versions, this can throw even though it shouldn't
61+
rules.isFixedOffset
62+
} catch (e: ArrayIndexOutOfBoundsException) {
63+
false // Happens for America/Costa_Rica, Africa/Cairo, Egypt
64+
}
65+
5766
@Serializable(with = FixedOffsetTimeZoneSerializer::class)
5867
public actual class FixedOffsetTimeZone
5968
internal constructor(public actual val offset: UtcOffset, zoneId: ZoneId): TimeZone(zoneId) {

0 commit comments

Comments
 (0)