Skip to content

Work around a crash on older Android versions #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion core/jvm/src/TimeZoneJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reference here a bug in the Android issue tracker so that we know when to remove the workaround.

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) {
Expand Down