Skip to content

Commit 2cc6b6a

Browse files
committed
Cleanup
1 parent 7d8769f commit 2cc6b6a

File tree

13 files changed

+71
-80
lines changed

13 files changed

+71
-80
lines changed

core/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ tasks {
314314

315315
val downloadWindowsZonesMapping by tasks.registering {
316316
description = "Updates the mapping between Windows-specific and usual names for timezones"
317-
val output = "$projectDir/windows/src/WindowsZoneNames.kt"
317+
val output = "$projectDir/windows/src/internal/WindowsZoneNames.kt"
318318
outputs.file(output)
319319
doLast {
320320
val initialFileContents = try { File(output).readBytes() } catch(e: Throwable) { ByteArray(0) }
@@ -348,7 +348,7 @@ val downloadWindowsZonesMapping by tasks.registering {
348348
val bos = ByteArrayOutputStream()
349349
PrintWriter(bos).use { out ->
350350
out.println("""// generated with gradle task `$name`""")
351-
out.println("""package kotlinx.datetime""")
351+
out.println("""package kotlinx.datetime.internal""")
352352
out.println("""internal val standardToWindows: Map<String, String> = mutableMapOf(""")
353353
for ((usualName, windowsName) in sortedMapping) {
354354
out.println(" \"$usualName\" to \"$windowsName\",")

core/common/test/TimeZoneTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class TimeZoneTest {
4747
@Test
4848
fun availableZonesAreAvailable() {
4949
val availableZones = mutableListOf<String>()
50-
val nonAvailableZones = mutableListOf<Pair<String, Exception>>()
50+
val nonAvailableZones = mutableListOf<Exception>()
5151
for (zoneName in TimeZone.availableZoneIds) {
5252
val timezone = try {
5353
TimeZone.of(zoneName)
5454
} catch (e: Exception) {
55-
nonAvailableZones.add(zoneName to e)
55+
nonAvailableZones.add(e)
5656
continue
5757
}
5858
availableZones.add(zoneName)
@@ -62,7 +62,7 @@ class TimeZoneTest {
6262
if (nonAvailableZones.isNotEmpty()) {
6363
println("Available zones: $availableZones")
6464
println("Non-available zones: $nonAvailableZones")
65-
throw nonAvailableZones[0].second
65+
throw nonAvailableZones[0]
6666
}
6767
}
6868

core/darwin/src/TimeZoneNative.kt renamed to core/darwin/src/internal/TimeZoneNative.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* Copyright 2019-2020 JetBrains s.r.o.
2+
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
@file:OptIn(kotlinx.cinterop.UnsafeNumber::class, kotlinx.cinterop.ExperimentalForeignApi::class)
7-
8-
package kotlinx.datetime
6+
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
7+
package kotlinx.datetime.internal
98

109
import platform.Foundation.*
1110

core/darwinDevices/src/TimeZoneNative.kt renamed to core/darwinDevices/src/internal/TimeZoneNative.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.datetime
6+
package kotlinx.datetime.internal
77

8-
import kotlinx.datetime.internal.*
9-
10-
internal actual fun getTzdbPath(): Path = Path.fromString("/var/db/timezone/zoneinfo")
8+
internal actual fun getTzdbPath(): Path = Path.fromString("/var/db/timezone/zoneinfo")

core/darwinSimulator/src/TimeZoneNative.kt renamed to core/darwinSimulator/src/internal/TimeZoneNative.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.datetime
6+
package kotlinx.datetime.internal
77

8-
import kotlinx.datetime.internal.*
9-
10-
internal actual fun getTzdbPath(): Path = Path.fromString("/usr/share/zoneinfo.default")
8+
internal actual fun getTzdbPath(): Path = Path.fromString("/usr/share/zoneinfo.default")

core/linux/src/TimeZoneNative.kt renamed to core/linux/src/internal/TimeZoneNative.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*
2-
* Copyright 2019-2023 JetBrains s.r.o.
2+
* Copyright 2019-2023 JetBrains s.r.o. and contributors.
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.datetime
7-
8-
import kotlinx.datetime.internal.*
6+
package kotlinx.datetime.internal
97

108
internal actual fun currentSystemDefaultZone(): RegionTimeZone {
119
val zoneId = pathToSystemDefault()?.second?.toString()

core/native/src/Instant.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
77
*/
88

9-
@file:OptIn(ExperimentalForeignApi::class)
10-
119
package kotlinx.datetime
1210

1311
import kotlinx.cinterop.*
@@ -132,6 +130,8 @@ private const val MAX_SECOND = 31494816403199L // +1000000-12-31T23:59:59
132130

133131
private fun isValidInstantSecond(second: Long) = second >= MIN_SECOND && second <= MAX_SECOND
134132

133+
134+
@OptIn(ExperimentalForeignApi::class)
135135
internal fun currentTime(): Instant = memScoped {
136136
val tm = alloc<timespec>()
137137
val error = clock_gettime(CLOCK_REALTIME.convert(), tm.ptr)

core/native/src/TimeZone.kt

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
77
*/
88

9-
@file:OptIn(ExperimentalForeignApi::class)
10-
119
package kotlinx.datetime
1210

13-
import kotlinx.cinterop.ExperimentalForeignApi
14-
import kotlinx.cinterop.memScoped
1511
import kotlinx.datetime.internal.*
1612
import kotlinx.datetime.serializers.*
1713
import kotlinx.serialization.Serializable
@@ -103,48 +99,6 @@ public actual open class TimeZone internal constructor() {
10399
override fun toString(): String = id
104100
}
105101

106-
internal interface TimezoneDatabase {
107-
fun rulesForId(id: String): TimeZoneRules
108-
fun availableTimeZoneIds(): Set<String>
109-
}
110-
111-
internal expect val systemTzdb: TimezoneDatabase
112-
113-
internal expect fun currentSystemDefaultZone(): RegionTimeZone
114-
115-
internal class RegionTimeZone(private val tzid: TimeZoneRules, override val id: String) : TimeZone() {
116-
117-
override fun atStartOfDay(date: LocalDate): Instant = memScoped {
118-
val ldt = LocalDateTime(date, LocalTime.MIN)
119-
when (val info = tzid.infoAtDatetime(ldt)) {
120-
is OffsetInfo.Regular -> ldt.toInstant(info.offset)
121-
is OffsetInfo.Gap -> info.start
122-
is OffsetInfo.Overlap -> ldt.toInstant(info.offsetBefore)
123-
}
124-
}
125-
126-
override fun atZone(dateTime: LocalDateTime, preferred: UtcOffset?): ZonedDateTime =
127-
when (val info = tzid.infoAtDatetime(dateTime)) {
128-
is OffsetInfo.Regular -> ZonedDateTime(dateTime, this, info.offset)
129-
is OffsetInfo.Gap -> {
130-
try {
131-
ZonedDateTime(dateTime.plusSeconds(info.transitionDurationSeconds), this, info.offsetAfter)
132-
} catch (e: IllegalArgumentException) {
133-
throw DateTimeArithmeticException(
134-
"Overflow whet correcting the date-time to not be in the transition gap",
135-
e
136-
)
137-
}
138-
}
139-
140-
is OffsetInfo.Overlap -> ZonedDateTime(dateTime, this,
141-
if (info.offsetAfter == preferred) info.offsetAfter else info.offsetBefore)
142-
}
143-
144-
override fun offsetAtImpl(instant: Instant): UtcOffset = tzid.infoAtInstant(instant)
145-
}
146-
147-
148102
@Serializable(with = FixedOffsetTimeZoneSerializer::class)
149103
public actual class FixedOffsetTimeZone internal constructor(public actual val offset: UtcOffset, override val id: String) : TimeZone() {
150104

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019-2023 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.*
9+
10+
internal interface TimezoneDatabase {
11+
fun rulesForId(id: String): TimeZoneRules
12+
fun availableTimeZoneIds(): Set<String>
13+
}
14+
15+
internal expect val systemTzdb: TimezoneDatabase
16+
17+
internal expect fun currentSystemDefaultZone(): RegionTimeZone
18+
19+
internal class RegionTimeZone(private val tzid: TimeZoneRules, override val id: String) : TimeZone() {
20+
21+
override fun atStartOfDay(date: LocalDate): Instant {
22+
val ldt = LocalDateTime(date, LocalTime.MIN)
23+
return when (val info = tzid.infoAtDatetime(ldt)) {
24+
is OffsetInfo.Regular -> ldt.toInstant(info.offset)
25+
is OffsetInfo.Gap -> info.start
26+
is OffsetInfo.Overlap -> ldt.toInstant(info.offsetBefore)
27+
}
28+
}
29+
30+
override fun atZone(dateTime: LocalDateTime, preferred: UtcOffset?): ZonedDateTime =
31+
when (val info = tzid.infoAtDatetime(dateTime)) {
32+
is OffsetInfo.Regular -> ZonedDateTime(dateTime, this, info.offset)
33+
is OffsetInfo.Gap -> {
34+
try {
35+
ZonedDateTime(dateTime.plusSeconds(info.transitionDurationSeconds), this, info.offsetAfter)
36+
} catch (e: IllegalArgumentException) {
37+
throw DateTimeArithmeticException(
38+
"Overflow whet correcting the date-time to not be in the transition gap",
39+
e
40+
)
41+
}
42+
}
43+
44+
is OffsetInfo.Overlap -> ZonedDateTime(dateTime, this,
45+
if (info.offsetAfter == preferred) info.offsetAfter else info.offsetBefore)
46+
}
47+
48+
override fun offsetAtImpl(instant: Instant): UtcOffset = tzid.infoAtInstant(instant)
49+
}
50+

core/nix/src/TimeZoneNative.kt renamed to core/nix/src/internal/TimeZoneNative.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
package kotlinx.datetime
7-
8-
import kotlinx.datetime.internal.*
6+
package kotlinx.datetime.internal
97

108
internal expect fun getTzdbPath(): Path
119

12-
internal actual val systemTzdb: TimezoneDatabase = TzdbOnFilesystem(getTzdbPath())
10+
internal actual val systemTzdb: TimezoneDatabase = TzdbOnFilesystem(getTzdbPath())

0 commit comments

Comments
 (0)