Skip to content

Commit 07d3270

Browse files
committed
Fail more gracefully if the tzdb failed to initialize
Now, not everything will break, but only the calls to timezone facilities.
1 parent 38650e6 commit 07d3270

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

core/darwin/src/internal/TimeZoneNative.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import kotlinx.cinterop.*
1010
import kotlinx.datetime.internal.*
1111
import platform.Foundation.*
1212

13-
internal actual val systemTzdb: TimeZoneDatabase = TzdbOnFilesystem(Path.fromString(defaultTzdbPath()))
13+
internal actual val systemTzdb: TimeZoneDatabase get() = tzdb.getOrThrow()
14+
15+
private val tzdb = runCatching { TzdbOnFilesystem(Path.fromString(defaultTzdbPath())) }
1416

1517
internal expect fun defaultTzdbPath(): String
1618

core/linux/src/internal/TimeZoneNative.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
package kotlinx.datetime.internal
77

8-
internal actual val systemTzdb: TimeZoneDatabase = TzdbOnFilesystem()
8+
internal actual val systemTzdb: TimeZoneDatabase get() = tzdb.getOrThrow()
9+
10+
private val tzdb = runCatching { TzdbOnFilesystem() }
911

1012
internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> {
1113
val zoneId = pathToSystemDefault()?.second?.toString()

core/windows/src/internal/TimeZoneNative.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
package kotlinx.datetime.internal
77

8-
internal actual val systemTzdb: TimeZoneDatabase get() = tzdbInRegistry
8+
internal actual val systemTzdb: TimeZoneDatabase get() = tzdbInRegistry.getOrThrow()
99

10-
internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> = tzdbInRegistry.currentSystemDefault()
10+
internal actual fun currentSystemDefaultZone(): Pair<String, TimeZoneRules?> =
11+
tzdbInRegistry.getOrThrow().currentSystemDefault()
1112

12-
private val tzdbInRegistry = TzdbInRegistry()
13+
private val tzdbInRegistry = runCatching { TzdbInRegistry() }

0 commit comments

Comments
 (0)