@@ -11,15 +11,11 @@ import kotlinx.cinterop.*
11
11
import kotlinx.datetime.internal.*
12
12
import platform.Foundation.*
13
13
14
- internal actual class RegionTimeZone ( private val tzid : TimeZoneRules , actual override val id : String ) : TimeZone() {
14
+ internal actual class TimeZoneDatabase : TimeZone () {
15
15
actual companion object {
16
- actual fun of (zoneId : String ): RegionTimeZone = try {
17
- RegionTimeZone (tzdbOnFilesystem.rulesForId(zoneId), zoneId)
18
- } catch (e: Exception ) {
19
- throw IllegalTimeZoneException (" Invalid zone ID: $zoneId " , e)
20
- }
16
+ actual fun rulesForId (id : String ): TimeZoneRules = tzdbOnFilesystem.rulesForId(id)
21
17
22
- actual fun currentSystemDefault (): RegionTimeZone {
18
+ actual fun currentSystemDefault (): Pair < String , TimeZoneRules ?> {
23
19
/* The framework has its own cache of the system timezone. Calls to
24
20
[NSTimeZone systemTimeZone] do not reflect changes to the system timezone
25
21
and instead just return the cached value. Thus, to acquire the current
@@ -70,41 +66,12 @@ internal actual class RegionTimeZone(private val tzid: TimeZoneRules, actual ove
70
66
NSTimeZone .resetSystemTimeZone()
71
67
val zone = NSTimeZone .systemTimeZone
72
68
val zoneId = zone.name
73
- return RegionTimeZone (tzdbOnFilesystem.rulesForId( zoneId), zoneId)
69
+ return zoneId to null
74
70
}
75
71
76
72
actual val availableZoneIds: Set <String >
77
73
get() = tzdbOnFilesystem.availableTimeZoneIds()
78
74
}
79
-
80
- actual override fun atStartOfDay (date : LocalDate ): Instant = memScoped {
81
- val ldt = LocalDateTime (date, LocalTime .MIN )
82
- when (val info = tzid.infoAtDatetime(ldt)) {
83
- is OffsetInfo .Regular -> ldt.toInstant(info.offset)
84
- is OffsetInfo .Gap -> info.start
85
- is OffsetInfo .Overlap -> ldt.toInstant(info.offsetBefore)
86
- }
87
- }
88
-
89
- actual override fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? ): ZonedDateTime =
90
- when (val info = tzid.infoAtDatetime(dateTime)) {
91
- is OffsetInfo .Regular -> ZonedDateTime (dateTime, this , info.offset)
92
- is OffsetInfo .Gap -> {
93
- try {
94
- ZonedDateTime (dateTime.plusSeconds(info.transitionDurationSeconds), this , info.offsetAfter)
95
- } catch (e: IllegalArgumentException ) {
96
- throw DateTimeArithmeticException (
97
- " Overflow whet correcting the date-time to not be in the transition gap" ,
98
- e
99
- )
100
- }
101
- }
102
-
103
- is OffsetInfo .Overlap -> ZonedDateTime (dateTime, this ,
104
- if (info.offsetAfter == preferred) info.offsetAfter else info.offsetBefore)
105
- }
106
-
107
- actual override fun offsetAtImpl (instant : Instant ): UtcOffset = tzid.infoAtInstant(instant)
108
75
}
109
76
110
77
internal actual fun currentTime (): Instant = NSDate .date().toKotlinInstant()
0 commit comments