@@ -12,11 +12,13 @@ import kotlinx.datetime.serializers.*
1212import kotlinx.serialization.Serializable
1313
1414@Serializable(with = TimeZoneSerializer ::class )
15- public actual open class TimeZone internal constructor(internal val value : TimeZoneImpl ) {
15+ public actual open class TimeZone internal constructor() {
1616
1717 public actual companion object {
1818
19- public actual fun currentSystemDefault (): TimeZone = PlatformTimeZoneImpl .currentSystemDefault().let (::TimeZone )
19+ public actual fun currentSystemDefault (): TimeZone =
20+ // TODO: probably check if currentSystemDefault name is parseable as FixedOffsetTimeZone?
21+ RegionTimeZone .currentSystemDefault()
2022
2123 public actual val UTC : FixedOffsetTimeZone = UtcOffset .ZERO .asTimeZone()
2224
@@ -56,23 +58,24 @@ public actual open class TimeZone internal constructor(internal val value: TimeZ
5658 } catch (e: DateTimeFormatException ) {
5759 throw IllegalTimeZoneException (e)
5860 }
59- return TimeZone ( PlatformTimeZoneImpl .of(zoneId) )
61+ return RegionTimeZone .of(zoneId)
6062 }
6163
6264 public actual val availableZoneIds: Set <String >
63- get() = PlatformTimeZoneImpl .availableZoneIds
65+ get() = RegionTimeZone .availableZoneIds
6466 }
6567
66- public actual val id: String
67- get() = value.id
68+ public actual open val id: String
69+ get() = error( " Should be overridden " )
6870
6971 public actual fun Instant.toLocalDateTime (): LocalDateTime = instantToLocalDateTime(this )
7072 public actual fun LocalDateTime.toInstant (): Instant = localDateTimeToInstant(this )
7173
72- internal open fun atStartOfDay (date : LocalDate ): Instant = value.atStartOfDay(date)
74+ internal open fun atStartOfDay (date : LocalDate ): Instant = error(" Should be overridden" ) // value.atStartOfDay(date)
75+ internal open fun offsetAtImpl (instant : Instant ): UtcOffset = error(" Should be overridden" )
7376
7477 internal open fun instantToLocalDateTime (instant : Instant ): LocalDateTime = try {
75- instant.toLocalDateTimeImpl(offsetAt (instant))
78+ instant.toLocalDateTimeImpl(offsetAtImpl (instant))
7679 } catch (e: IllegalArgumentException ) {
7780 throw DateTimeArithmeticException (" Instant $instant is not representable as LocalDateTime." , e)
7881 }
@@ -81,32 +84,53 @@ public actual open class TimeZone internal constructor(internal val value: TimeZ
8184 atZone(dateTime).toInstant()
8285
8386 internal open fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? = null): ZonedDateTime =
84- value.atZone(dateTime, preferred )
87+ error( " Should be overridden " )
8588
8689 override fun equals (other : Any? ): Boolean =
87- this == = other || other is TimeZone && this .value == other.value
90+ this == = other || other is TimeZone && this .id == other.id
8891
89- override fun hashCode (): Int = value .hashCode()
92+ override fun hashCode (): Int = id .hashCode()
9093
91- override fun toString (): String = value.toString()
94+ override fun toString (): String = id
95+ }
96+
97+ internal expect class RegionTimeZone : TimeZone {
98+ override val id: String
99+ override fun atStartOfDay (date : LocalDate ): Instant
100+ override fun offsetAtImpl (instant : Instant ): UtcOffset
101+ override fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? ): ZonedDateTime
102+
103+ companion object {
104+ fun of (zoneId : String ): RegionTimeZone
105+ fun currentSystemDefault (): RegionTimeZone
106+ val availableZoneIds: Set <String >
107+ }
92108}
93109
94110
95111@Serializable(with = FixedOffsetTimeZoneSerializer ::class )
96- public actual class FixedOffsetTimeZone internal constructor(public actual val offset : UtcOffset , id : String ) : TimeZone(ZoneOffsetImpl (offset, id) ) {
112+ public actual class FixedOffsetTimeZone internal constructor(public actual val offset : UtcOffset , override val id : String ) : TimeZone() {
97113
98114 public actual constructor (offset: UtcOffset ) : this (offset, offset.toString())
99115
100116 @Deprecated(" Use offset.totalSeconds" , ReplaceWith (" offset.totalSeconds" ))
101117 public actual val totalSeconds: Int get() = offset.totalSeconds
102118
119+ override fun atStartOfDay (date : LocalDate ): Instant =
120+ LocalDateTime (date, LocalTime .MIN ).toInstant(offset)
121+
122+ override fun offsetAtImpl (instant : Instant ): UtcOffset = offset
123+
124+ override fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? ): ZonedDateTime =
125+ ZonedDateTime (dateTime, this , offset)
126+
103127 override fun instantToLocalDateTime (instant : Instant ): LocalDateTime = instant.toLocalDateTime(offset)
104128 override fun localDateTimeToInstant (dateTime : LocalDateTime ): Instant = dateTime.toInstant(offset)
105129}
106130
107131
108132public actual fun TimeZone.offsetAt (instant : Instant ): UtcOffset =
109- value.offsetAt (instant)
133+ offsetAtImpl (instant)
110134
111135public actual fun Instant.toLocalDateTime (timeZone : TimeZone ): LocalDateTime =
112136 timeZone.instantToLocalDateTime(this )
0 commit comments