Skip to content

Commit 6fbcf61

Browse files
#485: Implement TimeZoneRules interface and update TimeZoneRulesCommon to conform
1 parent 84dbaa9 commit 6fbcf61

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.datetime.internal
7+
8+
import kotlinx.datetime.Instant
9+
import kotlinx.datetime.LocalDateTime
10+
import kotlinx.datetime.UtcOffset
11+
12+
internal interface TimeZoneRules {
13+
14+
fun infoAtInstant(instant: Instant): UtcOffset
15+
16+
fun infoAtDatetime(localDateTime: LocalDateTime): OffsetInfo
17+
}

core/commonKotlin/src/internal/TimeZoneRulesCommon.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal class TimeZoneRulesCommon(
2828
* [recurringZoneRules].
2929
*/
3030
val recurringZoneRules: RecurringZoneRules?,
31-
) {
31+
) : TimeZoneRules {
3232
init {
3333
require(offsets.size == transitionEpochSeconds.size + 1) {
3434
"offsets.size must be one more than transitionEpochSeconds.size"
@@ -65,7 +65,7 @@ internal class TimeZoneRulesCommon(
6565
}
6666
}
6767

68-
fun infoAtInstant(instant: Instant): UtcOffset {
68+
override fun infoAtInstant(instant: Instant): UtcOffset {
6969
val epochSeconds = instant.epochSeconds
7070
// good: no transitions, or instant is after the last transition
7171
if (recurringZoneRules != null && transitionEpochSeconds.lastOrNull()?.let { epochSeconds >= it } != false) {
@@ -81,7 +81,7 @@ internal class TimeZoneRulesCommon(
8181
return offsets[index]
8282
}
8383

84-
fun infoAtDatetime(localDateTime: LocalDateTime): OffsetInfo {
84+
override fun infoAtDatetime(localDateTime: LocalDateTime): OffsetInfo {
8585
if (recurringZoneRules != null && transitionLocalDateTimes.lastOrNull()?.let { localDateTime > it } != false) {
8686
return recurringZoneRules.infoAtLocalDateTime(localDateTime, offsets.last())
8787
}

0 commit comments

Comments
 (0)