@@ -8,15 +8,16 @@ package kotlinx.datetime
88import kotlin.math.abs
99import kotlin.native.concurrent.ThreadLocal
1010
11- public actual class UtcOffset internal constructor(public actual val totalSeconds : Int , internal val id : String ) {
11+ public actual class UtcOffset internal constructor(public actual val totalSeconds : Int ) {
12+ private val id: String = zoneIdByOffset(totalSeconds)
1213
1314 override fun hashCode (): Int = totalSeconds
1415 override fun equals (other : Any? ): Boolean = other is UtcOffset && this .totalSeconds == other.totalSeconds
1516 override fun toString (): String = id
1617
1718 public actual companion object {
1819
19- internal val ZERO : UtcOffset = UtcOffset (0 , " Z " )
20+ internal val ZERO : UtcOffset = UtcOffset (0 )
2021
2122 public actual fun parse (offsetString : String ): UtcOffset {
2223 if (offsetString == " Z" ) {
@@ -59,8 +60,7 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
5960 val first: Char = offsetString[0 ]
6061 if (first != ' +' && first != ' -' ) {
6162 throw IllegalTimeZoneException (
62- " Invalid ID for UtcOffset, plus/minus not found when expected: $offsetString "
63- )
63+ " Invalid ID for UtcOffset, plus/minus not found when expected: $offsetString " )
6464 }
6565 return if (first == ' -' ) {
6666 ofHoursMinutesSeconds(- hours, - minutes, - seconds)
@@ -72,10 +72,8 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
7272 // org.threeten.bp.ZoneOffset#validate
7373 private fun validate (hours : Int , minutes : Int , seconds : Int ) {
7474 if (hours < - 18 || hours > 18 ) {
75- throw IllegalTimeZoneException (
76- " Zone offset hours not in valid range: value " + hours +
77- " is not in the range -18 to 18"
78- )
75+ throw IllegalTimeZoneException (" Zone offset hours not in valid range: value " + hours +
76+ " is not in the range -18 to 18" )
7977 }
8078 if (hours > 0 ) {
8179 if (minutes < 0 || seconds < 0 ) {
@@ -89,16 +87,12 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
8987 throw IllegalTimeZoneException (" Zone offset minutes and seconds must have the same sign" )
9088 }
9189 if (abs(minutes) > 59 ) {
92- throw IllegalTimeZoneException (
93- " Zone offset minutes not in valid range: abs(value) " +
94- abs(minutes) + " is not in the range 0 to 59"
95- )
90+ throw IllegalTimeZoneException (" Zone offset minutes not in valid range: abs(value) " +
91+ abs(minutes) + " is not in the range 0 to 59" )
9692 }
9793 if (abs(seconds) > 59 ) {
98- throw IllegalTimeZoneException (
99- " Zone offset seconds not in valid range: abs(value) " +
100- abs(seconds) + " is not in the range 0 to 59"
101- )
94+ throw IllegalTimeZoneException (" Zone offset seconds not in valid range: abs(value) " +
95+ abs(seconds) + " is not in the range 0 to 59" )
10296 }
10397 if (abs(hours) == 18 && (abs(minutes) > 0 || abs(seconds) > 0 )) {
10498 throw IllegalTimeZoneException (" Zone offset not in valid range: -18:00 to +18:00" )
@@ -115,9 +109,9 @@ public actual class UtcOffset internal constructor(public actual val totalSecond
115109 // org.threeten.bp.ZoneOffset#ofTotalSeconds
116110 internal fun ofSeconds (seconds : Int ): UtcOffset =
117111 if (seconds % (15 * SECONDS_PER_MINUTE ) == 0 ) {
118- utcOffsetCache[seconds] ? : UtcOffset (seconds, zoneIdByOffset(seconds) ).also { utcOffsetCache[seconds] = it }
112+ utcOffsetCache[seconds] ? : UtcOffset (seconds).also { utcOffsetCache[seconds] = it }
119113 } else {
120- UtcOffset (seconds, zoneIdByOffset(seconds) )
114+ UtcOffset (seconds)
121115 }
122116
123117 // org.threeten.bp.ZoneOffset#parseNumber
0 commit comments