Skip to content

Commit

Permalink
Fail more gracefully if the tzdb failed to initialize
Browse files Browse the repository at this point in the history
Now, not everything will break, but only the calls to timezone
facilities.
  • Loading branch information
dkhalanskyjb committed Feb 21, 2024
1 parent 2ebd98a commit 0f05fdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion core/darwin/src/internal/TimeZoneNative.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import kotlinx.cinterop.*
import kotlinx.datetime.internal.*
import platform.Foundation.*

internal actual val systemTzdb: TimeZoneDatabase = TzdbOnFilesystem(Path.fromString(defaultTzdbPath()))
internal actual val systemTzdb: TimeZoneDatabase get() = tzdb.getOrThrow()

private val tzdb = runCatching { TzdbOnFilesystem(Path.fromString(defaultTzdbPath())) }

internal expect fun defaultTzdbPath(): String

Expand Down
4 changes: 3 additions & 1 deletion core/linux/src/internal/TimeZoneNative.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

package kotlinx.datetime.internal

internal actual val systemTzdb: TimeZoneDatabase = TzdbOnFilesystem()
internal actual val systemTzdb: TimeZoneDatabase get() = tzdb.getOrThrow()

private val tzdb = runCatching { TzdbOnFilesystem() }

internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> {
val zoneId = pathToSystemDefault()?.second?.toString()
Expand Down
7 changes: 4 additions & 3 deletions core/windows/src/internal/TimeZoneNative.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

package kotlinx.datetime.internal

internal actual val systemTzdb: TimeZoneDatabase get() = tzdbInRegistry
internal actual val systemTzdb: TimeZoneDatabase get() = tzdbInRegistry.getOrThrow()

internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> = tzdbInRegistry.currentSystemDefault()
internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> =
tzdbInRegistry.getOrThrow().currentSystemDefault()

private val tzdbInRegistry = TzdbInRegistry()
private val tzdbInRegistry = runCatching { TzdbInRegistry() }

0 comments on commit 0f05fdd

Please sign in to comment.