@@ -26,17 +26,17 @@ private fun systemDateByLocalDate(zone: NSTimeZone, localDate: NSDate): NSDate?
26
26
return iso8601.dateFromComponents(dateComponents)
27
27
}
28
28
29
- internal actual class PlatformTimeZoneImpl (private val value : NSTimeZone , override val id : String ): TimeZoneImpl {
29
+ internal actual class RegionTimeZone (private val value : NSTimeZone , actual override val id : String ): TimeZone() {
30
30
actual companion object {
31
- actual fun of (zoneId : String ): PlatformTimeZoneImpl {
31
+ actual fun of (zoneId : String ): RegionTimeZone {
32
32
val abbreviations = NSTimeZone .abbreviationDictionary
33
33
val trueZoneId = abbreviations[zoneId] as String? ? : zoneId
34
34
val zone = NSTimeZone .timeZoneWithName(trueZoneId)
35
35
? : throw IllegalTimeZoneException (" No timezone found with zone ID '$zoneId '" )
36
- return PlatformTimeZoneImpl (zone, zoneId)
36
+ return RegionTimeZone (zone, zoneId)
37
37
}
38
38
39
- actual fun currentSystemDefault (): PlatformTimeZoneImpl {
39
+ actual fun currentSystemDefault (): RegionTimeZone {
40
40
/* The framework has its own cache of the system timezone. Calls to
41
41
[NSTimeZone systemTimeZone] do not reflect changes to the system timezone
42
42
and instead just return the cached value. Thus, to acquire the current
@@ -86,7 +86,7 @@ internal actual class PlatformTimeZoneImpl(private val value: NSTimeZone, overri
86
86
*/
87
87
NSTimeZone .resetSystemTimeZone()
88
88
val zone = NSTimeZone .systemTimeZone
89
- return PlatformTimeZoneImpl (zone, zone.name)
89
+ return RegionTimeZone (zone, zone.name)
90
90
}
91
91
92
92
actual val availableZoneIds: Set <String >
@@ -110,7 +110,7 @@ internal actual class PlatformTimeZoneImpl(private val value: NSTimeZone, overri
110
110
}
111
111
}
112
112
113
- override fun atStartOfDay (date : LocalDate ): Instant {
113
+ actual override fun atStartOfDay (date : LocalDate ): Instant {
114
114
val ldt = LocalDateTime (date, LocalTime .MIN )
115
115
val epochSeconds = ldt.toEpochSecond(UtcOffset .ZERO )
116
116
// timezone
@@ -132,15 +132,15 @@ internal actual class PlatformTimeZoneImpl(private val value: NSTimeZone, overri
132
132
return Instant (midnight.timeIntervalSince1970.toLong(), 0 )
133
133
}
134
134
135
- override fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? ): ZonedDateTime {
135
+ actual override fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? ): ZonedDateTime {
136
136
val epochSeconds = dateTime.toEpochSecond(UtcOffset .ZERO )
137
137
var offset = preferred?.totalSeconds ? : Int .MAX_VALUE
138
138
val transitionDuration = run {
139
139
/* a date in an unspecified timezone, defined by the number of seconds since
140
140
the start of the epoch in *that* unspecified timezone */
141
141
val date = dateWithTimeIntervalSince1970Saturating(epochSeconds)
142
142
val newDate = systemDateByLocalDate(value, date)
143
- ? : throw RuntimeException (" Unable to acquire the offset at $dateTime for zone ${this @PlatformTimeZoneImpl } " )
143
+ ? : throw RuntimeException (" Unable to acquire the offset at $dateTime for zone ${this @RegionTimeZone } " )
144
144
// we now know the offset of that timezone at this time.
145
145
offset = value.secondsFromGMTForDate(newDate).toInt()
146
146
/* `dateFromComponents` automatically corrects the date to avoid gaps. We
@@ -155,23 +155,14 @@ internal actual class PlatformTimeZoneImpl(private val value: NSTimeZone, overri
155
155
} catch (e: ArithmeticException ) {
156
156
throw RuntimeException (" Anomalously long timezone transition gap reported" , e)
157
157
}
158
- return ZonedDateTime (correctedDateTime, RegionTimeZone ( this ) , UtcOffset .ofSeconds(offset))
158
+ return ZonedDateTime (correctedDateTime, this @RegionTimeZone , UtcOffset .ofSeconds(offset))
159
159
}
160
160
161
- override fun offsetAt (instant : Instant ): UtcOffset {
161
+ actual override fun offsetAtImpl (instant : Instant ): UtcOffset {
162
162
val date = dateWithTimeIntervalSince1970Saturating(instant.epochSeconds)
163
163
return UtcOffset .ofSeconds(value.secondsFromGMTForDate(date).toInt())
164
164
}
165
165
166
- // org.threeten.bp.ZoneId#equals
167
- override fun equals (other : Any? ): Boolean =
168
- this == = other || other is PlatformTimeZoneImpl && this .id == other.id
169
-
170
- // org.threeten.bp.ZoneId#hashCode
171
- override fun hashCode (): Int = id.hashCode()
172
-
173
- // org.threeten.bp.ZoneId#toString
174
- override fun toString (): String = id
175
166
}
176
167
177
168
internal actual fun currentTime (): Instant = NSDate .date().toKotlinInstant()
0 commit comments