@@ -11,15 +11,11 @@ import kotlinx.cinterop.*
1111import kotlinx.datetime.internal.*
1212import platform.Foundation.*
1313
14- internal actual class RegionTimeZone ( private val tzid : TimeZoneRules , actual override val id : String ) : TimeZone() {
14+ internal actual class TimeZoneDatabase : TimeZone () {
1515 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)
2117
22- actual fun currentSystemDefault (): RegionTimeZone {
18+ actual fun currentSystemDefault (): Pair < String , TimeZoneRules ?> {
2319 /* The framework has its own cache of the system timezone. Calls to
2420 [NSTimeZone systemTimeZone] do not reflect changes to the system timezone
2521 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
7066 NSTimeZone .resetSystemTimeZone()
7167 val zone = NSTimeZone .systemTimeZone
7268 val zoneId = zone.name
73- return RegionTimeZone (tzdbOnFilesystem.rulesForId( zoneId), zoneId)
69+ return zoneId to null
7470 }
7571
7672 actual val availableZoneIds: Set <String >
7773 get() = tzdbOnFilesystem.availableTimeZoneIds()
7874 }
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)
10875}
10976
11077internal actual fun currentTime (): Instant = NSDate .date().toKotlinInstant()
0 commit comments