@@ -11,10 +11,10 @@ import kotlinx.datetime.internal.format.parser.Copyable
11
11
import kotlin.math.*
12
12
13
13
internal interface UtcOffsetFieldContainer {
14
- var isNegative : Boolean?
15
- var totalHoursAbs : Int?
16
- var minutesOfHour : Int?
17
- var secondsOfMinute : Int?
14
+ var offsetIsNegative : Boolean?
15
+ var offsetHours : Int?
16
+ var offsetMinutesOfHour : Int?
17
+ var offsetSecondsOfMinute : Int?
18
18
}
19
19
20
20
internal interface AbstractWithOffsetBuilder : DateTimeFormatBuilder .WithUtcOffset {
@@ -127,26 +127,26 @@ internal fun DateTimeFormatBuilder.WithUtcOffset.isoOffset(
127
127
128
128
private object OffsetFields {
129
129
private val sign = object : FieldSign <UtcOffsetFieldContainer > {
130
- override val isNegative = PropertyAccessor (UtcOffsetFieldContainer ::isNegative )
130
+ override val isNegative = PropertyAccessor (UtcOffsetFieldContainer ::offsetIsNegative )
131
131
override fun isZero (obj : UtcOffsetFieldContainer ): Boolean =
132
- (obj.totalHoursAbs ? : 0 ) == 0 && (obj.minutesOfHour ? : 0 ) == 0 && (obj.secondsOfMinute ? : 0 ) == 0
132
+ (obj.offsetHours ? : 0 ) == 0 && (obj.offsetMinutesOfHour ? : 0 ) == 0 && (obj.offsetSecondsOfMinute ? : 0 ) == 0
133
133
}
134
134
val totalHoursAbs = UnsignedFieldSpec (
135
- PropertyAccessor (UtcOffsetFieldContainer ::totalHoursAbs ),
135
+ PropertyAccessor (UtcOffsetFieldContainer ::offsetHours ),
136
136
defaultValue = 0 ,
137
137
minValue = 0 ,
138
138
maxValue = 18 ,
139
139
sign = sign,
140
140
)
141
141
val minutesOfHour = UnsignedFieldSpec (
142
- PropertyAccessor (UtcOffsetFieldContainer ::minutesOfHour ),
142
+ PropertyAccessor (UtcOffsetFieldContainer ::offsetMinutesOfHour ),
143
143
defaultValue = 0 ,
144
144
minValue = 0 ,
145
145
maxValue = 59 ,
146
146
sign = sign,
147
147
)
148
148
val secondsOfMinute = UnsignedFieldSpec (
149
- PropertyAccessor (UtcOffsetFieldContainer ::secondsOfMinute ),
149
+ PropertyAccessor (UtcOffsetFieldContainer ::offsetSecondsOfMinute ),
150
150
defaultValue = 0 ,
151
151
minValue = 0 ,
152
152
maxValue = 59 ,
@@ -155,39 +155,39 @@ private object OffsetFields {
155
155
}
156
156
157
157
internal class IncompleteUtcOffset (
158
- override var isNegative : Boolean? = null ,
159
- override var totalHoursAbs : Int? = null ,
160
- override var minutesOfHour : Int? = null ,
161
- override var secondsOfMinute : Int? = null ,
158
+ override var offsetIsNegative : Boolean? = null ,
159
+ override var offsetHours : Int? = null ,
160
+ override var offsetMinutesOfHour : Int? = null ,
161
+ override var offsetSecondsOfMinute : Int? = null ,
162
162
) : UtcOffsetFieldContainer, Copyable<IncompleteUtcOffset> {
163
163
164
164
fun toUtcOffset (): UtcOffset {
165
- val sign = if (isNegative == true ) - 1 else 1
165
+ val sign = if (offsetIsNegative == true ) - 1 else 1
166
166
return UtcOffset (
167
- totalHoursAbs ?.let { it * sign }, minutesOfHour ?.let { it * sign }, secondsOfMinute ?.let { it * sign }
167
+ offsetHours ?.let { it * sign }, offsetMinutesOfHour ?.let { it * sign }, offsetSecondsOfMinute ?.let { it * sign }
168
168
)
169
169
}
170
170
171
171
fun populateFrom (offset : UtcOffset ) {
172
- isNegative = offset.totalSeconds < 0
172
+ offsetIsNegative = offset.totalSeconds < 0
173
173
val totalSecondsAbs = offset.totalSeconds.absoluteValue
174
- totalHoursAbs = totalSecondsAbs / 3600
175
- minutesOfHour = (totalSecondsAbs / 60 ) % 60
176
- secondsOfMinute = totalSecondsAbs % 60
174
+ offsetHours = totalSecondsAbs / 3600
175
+ offsetMinutesOfHour = (totalSecondsAbs / 60 ) % 60
176
+ offsetSecondsOfMinute = totalSecondsAbs % 60
177
177
}
178
178
179
179
override fun equals (other : Any? ): Boolean =
180
- other is IncompleteUtcOffset && isNegative == other.isNegative && totalHoursAbs == other.totalHoursAbs &&
181
- minutesOfHour == other.minutesOfHour && secondsOfMinute == other.secondsOfMinute
180
+ other is IncompleteUtcOffset && offsetIsNegative == other.offsetIsNegative && offsetHours == other.offsetHours &&
181
+ offsetMinutesOfHour == other.offsetMinutesOfHour && offsetSecondsOfMinute == other.offsetSecondsOfMinute
182
182
183
183
override fun hashCode (): Int =
184
- isNegative .hashCode() + totalHoursAbs .hashCode() + minutesOfHour .hashCode() + secondsOfMinute .hashCode()
184
+ offsetIsNegative .hashCode() + offsetHours .hashCode() + offsetMinutesOfHour .hashCode() + offsetSecondsOfMinute .hashCode()
185
185
186
186
override fun copy (): IncompleteUtcOffset =
187
- IncompleteUtcOffset (isNegative, totalHoursAbs, minutesOfHour, secondsOfMinute )
187
+ IncompleteUtcOffset (offsetIsNegative, offsetHours, offsetMinutesOfHour, offsetSecondsOfMinute )
188
188
189
189
override fun toString (): String =
190
- " ${isNegative ?.let { if (it) " -" else " +" } ? : " " }${totalHoursAbs ? : " ??" } :${minutesOfHour ? : " ??" } :${secondsOfMinute ? : " ??" } "
190
+ " ${offsetIsNegative ?.let { if (it) " -" else " +" } ? : " " }${offsetHours ? : " ??" } :${offsetMinutesOfHour ? : " ??" } :${offsetSecondsOfMinute ? : " ??" } "
191
191
}
192
192
193
193
internal class UtcOffsetWholeHoursDirective (private val padding : Padding ) :
0 commit comments