@@ -12,11 +12,13 @@ import kotlinx.datetime.serializers.*
12
12
import kotlinx.serialization.Serializable
13
13
14
14
@Serializable(with = TimeZoneSerializer ::class )
15
- public actual open class TimeZone internal constructor(internal val value : TimeZoneImpl ) {
15
+ public actual open class TimeZone internal constructor() {
16
16
17
17
public actual companion object {
18
18
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()
20
22
21
23
public actual val UTC : FixedOffsetTimeZone = UtcOffset .ZERO .asTimeZone()
22
24
@@ -56,23 +58,24 @@ public actual open class TimeZone internal constructor(internal val value: TimeZ
56
58
} catch (e: DateTimeFormatException ) {
57
59
throw IllegalTimeZoneException (e)
58
60
}
59
- return TimeZone ( PlatformTimeZoneImpl .of(zoneId) )
61
+ return RegionTimeZone .of(zoneId)
60
62
}
61
63
62
64
public actual val availableZoneIds: Set <String >
63
- get() = PlatformTimeZoneImpl .availableZoneIds
65
+ get() = RegionTimeZone .availableZoneIds
64
66
}
65
67
66
- public actual val id: String
67
- get() = value.id
68
+ public actual open val id: String
69
+ get() = error( " Should be overridden " )
68
70
69
71
public actual fun Instant.toLocalDateTime (): LocalDateTime = instantToLocalDateTime(this )
70
72
public actual fun LocalDateTime.toInstant (): Instant = localDateTimeToInstant(this )
71
73
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" )
73
76
74
77
internal open fun instantToLocalDateTime (instant : Instant ): LocalDateTime = try {
75
- instant.toLocalDateTimeImpl(offsetAt (instant))
78
+ instant.toLocalDateTimeImpl(offsetAtImpl (instant))
76
79
} catch (e: IllegalArgumentException ) {
77
80
throw DateTimeArithmeticException (" Instant $instant is not representable as LocalDateTime." , e)
78
81
}
@@ -81,32 +84,53 @@ public actual open class TimeZone internal constructor(internal val value: TimeZ
81
84
atZone(dateTime).toInstant()
82
85
83
86
internal open fun atZone (dateTime : LocalDateTime , preferred : UtcOffset ? = null): ZonedDateTime =
84
- value.atZone(dateTime, preferred )
87
+ error( " Should be overridden " )
85
88
86
89
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
88
91
89
- override fun hashCode (): Int = value .hashCode()
92
+ override fun hashCode (): Int = id .hashCode()
90
93
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
+ }
92
108
}
93
109
94
110
95
111
@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() {
97
113
98
114
public actual constructor (offset: UtcOffset ) : this (offset, offset.toString())
99
115
100
116
@Deprecated(" Use offset.totalSeconds" , ReplaceWith (" offset.totalSeconds" ))
101
117
public actual val totalSeconds: Int get() = offset.totalSeconds
102
118
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
+
103
127
override fun instantToLocalDateTime (instant : Instant ): LocalDateTime = instant.toLocalDateTime(offset)
104
128
override fun localDateTimeToInstant (dateTime : LocalDateTime ): Instant = dateTime.toInstant(offset)
105
129
}
106
130
107
131
108
132
public actual fun TimeZone.offsetAt (instant : Instant ): UtcOffset =
109
- value.offsetAt (instant)
133
+ offsetAtImpl (instant)
110
134
111
135
public actual fun Instant.toLocalDateTime (timeZone : TimeZone ): LocalDateTime =
112
136
timeZone.instantToLocalDateTime(this )
0 commit comments