Skip to content

Commit b8f563f

Browse files
#485: Replace TimeZoneRulesImpl with TimeZoneRules for some return values
1 parent ebbb869 commit b8f563f

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

core/androidNative/src/internal/TzdbBionic.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
package kotlinx.datetime.internal
1111

1212
private class TzdbBionic(private val rules: Map<String, Entry>) : TimeZoneDatabase {
13-
override fun rulesForId(id: String): TimeZoneRulesImpl =
13+
override fun rulesForId(id: String): TimeZoneRules =
1414
rules[id]?.readRules() ?: throw IllegalStateException("Unknown time zone $id")
1515

1616
override fun availableTimeZoneIds(): Set<String> = rules.keys
1717

1818
class Entry(val file: ByteArray, val offset: Int, val length: Int) {
19-
fun readRules(): TimeZoneRulesImpl = readTzFile(file.copyOfRange(offset, offset + length)).toTimeZoneRules()
19+
fun readRules(): TimeZoneRules = readTzFile(file.copyOfRange(offset, offset + length)).toTimeZoneRules()
2020
}
2121
}
2222

core/commonJs/src/internal/Platform.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private val tzdb: Result<TimeZoneDatabase?> = runCatching {
6060
return (wholeMinutes * SECONDS_PER_MINUTE + seconds) * sign
6161
}
6262

63-
val zones = mutableMapOf<String, TimeZoneRulesImpl>()
63+
val zones = mutableMapOf<String, TimeZoneRules>()
6464
val (zonesPacked, linksPacked) = readTzdb() ?: return@runCatching null
6565
for (zone in zonesPacked) {
6666
val components = zone.split('|')
@@ -84,7 +84,7 @@ private val tzdb: Result<TimeZoneDatabase?> = runCatching {
8484
}
8585
}
8686
object : TimeZoneDatabase {
87-
override fun rulesForId(id: String): TimeZoneRulesImpl =
87+
override fun rulesForId(id: String): TimeZoneRules =
8888
zones[id] ?: throw IllegalTimeZoneException("Unknown time zone: $id")
8989

9090
override fun availableTimeZoneIds(): Set<String> = zones.keys
@@ -134,7 +134,7 @@ internal actual fun timeZoneById(zoneId: String): TimeZone {
134134
throw IllegalTimeZoneException("js-joda timezone database is not available")
135135
}
136136

137-
internal fun rulesForId(zoneId: String): TimeZoneRulesImpl? = tzdb.getOrThrow()?.rulesForId(zoneId)
137+
internal fun rulesForId(zoneId: String): TimeZoneRules? = tzdb.getOrThrow()?.rulesForId(zoneId)
138138

139139
internal actual fun getAvailableZoneIds(): Set<String> =
140140
tzdb.getOrThrow()?.availableTimeZoneIds() ?: setOf("UTC")

core/commonKotlin/src/internal/RegionTimeZone.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package kotlinx.datetime.internal
77

88
import kotlinx.datetime.*
99

10-
internal class RegionTimeZone(private val tzid: TimeZoneRulesImpl, override val id: String) : TimeZone() {
10+
internal class RegionTimeZone(private val tzid: TimeZoneRules, override val id: String) : TimeZone() {
1111

1212
override fun atStartOfDay(date: LocalDate): Instant {
1313
val ldt = LocalDateTime(date, LocalTime.MIN)

core/commonKotlin/src/internal/TimeZoneDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
package kotlinx.datetime.internal
77

88
internal interface TimeZoneDatabase {
9-
fun rulesForId(id: String): TimeZoneRulesImpl
9+
fun rulesForId(id: String): TimeZoneRules
1010
fun availableTimeZoneIds(): Set<String>
1111
}

core/commonKotlin/src/internal/Tzfile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class TzFileData(
4040
}
4141

4242
internal class TzFile(val data: TzFileData, val rules: PosixTzString?) {
43-
fun toTimeZoneRules(): TimeZoneRulesImpl {
43+
fun toTimeZoneRules(): TimeZoneRules {
4444
val tzOffsets = buildList {
4545
add(data.states[0].offset)
4646
data.transitions.forEach { add(data.states[it.stateIndex].offset) }

core/commonKotlin/test/TimeZoneRulesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlin.test.*
1212
class TimeZoneRulesTest {
1313
@Test
1414
fun ruleStrings() {
15-
val rules = readTzFile(EuropeBerlinTzFile2023c).toTimeZoneRules()
15+
val rules = readTzFile(EuropeBerlinTzFile2023c).toTimeZoneRules() as TimeZoneRulesImpl
1616
// first, check that for the future, there are no explicitly defined transitions
1717
assertTrue(rules.transitionEpochSeconds.all {
1818
Instant.fromEpochSeconds(it) < LocalDateTime(2038, 1, 1, 0, 0).toInstant(UtcOffset.ZERO)

core/tzdbOnFilesystem/src/internal/TzdbOnFilesystem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class TzdbOnFilesystem(defaultTzdbPath: Path? = null): TimeZoneDatabase
1111
tabPaths.any { path.containsFile(it) }
1212
} ?: throw IllegalStateException("Could not find the path to the timezone database")
1313

14-
override fun rulesForId(id: String): TimeZoneRulesImpl {
14+
override fun rulesForId(id: String): TimeZoneRules {
1515
val idAsPath = Path.fromString(id)
1616
require(!idAsPath.isAbsolute) { "Timezone ID '$idAsPath' must not begin with a '/'" }
1717
require(idAsPath.components.none { it == ".." }) { "'$idAsPath' must not contain '..' as a component" }

core/windows/src/internal/TzdbInRegistry.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class TzdbInRegistry: TimeZoneDatabase {
1414

1515
// TODO: starting version 1703 of Windows 10, the ICU library is also bundled, with more accurate/ timezone information.
1616
// When Kotlin/Native drops support for Windows 7, we should investigate moving to the ICU.
17-
private val windowsToRules: Map<String, TimeZoneRulesImpl> = buildMap {
17+
private val windowsToRules: Map<String, TimeZoneRules> = buildMap {
1818
processTimeZonesInRegistry { name, recurring, historic ->
1919
val recurringRules = RecurringZoneRules(recurring.transitions)
2020
val rules = run {
@@ -76,7 +76,7 @@ internal class TzdbInRegistry: TimeZoneDatabase {
7676
}
7777
}
7878

79-
override fun rulesForId(id: String): TimeZoneRulesImpl {
79+
override fun rulesForId(id: String): TimeZoneRules {
8080
val standardName = standardToWindows[id] ?: throw IllegalTimeZoneException("Unknown time zone $id")
8181
return windowsToRules[standardName]
8282
?: throw IllegalTimeZoneException("The rules for time zone $id are absent in the Windows registry")

0 commit comments

Comments
 (0)