Skip to content

Commit 68471b9

Browse files
committed
Use the "UTC" identifier for the TimeZone.UTC time zone
Fixes #474
1 parent 7380325 commit 68471b9

File tree

7 files changed

+12
-7
lines changed

7 files changed

+12
-7
lines changed

core/common/src/TimeZone.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public expect open class TimeZone {
7575
/**
7676
* Returns the time zone with the fixed UTC+0 offset.
7777
*
78-
* The [id] of this time zone is `"Z"`.
78+
* The [id] of this time zone is `"UTC"`.
7979
*
8080
* @sample kotlinx.datetime.test.samples.TimeZoneSamples.utc
8181
*/

core/common/test/TimeZoneTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TimeZoneTest {
1616
fun utc() {
1717
val utc: FixedOffsetTimeZone = TimeZone.UTC
1818
println(utc)
19-
assertEquals("Z", utc.id)
19+
assertEquals("UTC", utc.id)
2020
assertEquals(UtcOffset.ZERO, utc.offset)
2121
assertEquals(0, utc.offset.totalSeconds)
2222
assertEquals(utc.offset, utc.offsetAt(Clock.System.now()))

core/commonKotlin/src/TimeZone.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ public actual open class TimeZone internal constructor() {
2424
return zone ?: of(name)
2525
}
2626

27-
public actual val UTC: FixedOffsetTimeZone = UtcOffset.ZERO.asTimeZone()
27+
public actual val UTC: FixedOffsetTimeZone = FixedOffsetTimeZone(UtcOffset.ZERO, "UTC")
2828

2929
// org.threeten.bp.ZoneId#of(java.lang.String)
3030
public actual fun of(zoneId: String): TimeZone {
3131
// TODO: normalize aliases?
32-
if (zoneId == "Z") {
32+
if (zoneId == "UTC") {
3333
return UTC
3434
}
35+
if (zoneId == "Z") {
36+
return UtcOffset.ZERO.asTimeZone()
37+
}
3538
if (zoneId == "SYSTEM") {
3639
return currentSystemDefault()
3740
}

core/jvm/src/TimeZoneJvm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public actual open class TimeZone internal constructor(internal val zoneId: Zone
3232

3333
public actual companion object {
3434
public actual fun currentSystemDefault(): TimeZone = ofZone(ZoneId.systemDefault())
35-
public actual val UTC: FixedOffsetTimeZone = UtcOffset(jtZoneOffset.UTC).asTimeZone()
35+
public actual val UTC: FixedOffsetTimeZone =
36+
FixedOffsetTimeZone(UtcOffset.ZERO, ZoneId.of("UTC"))
3637

3738
public actual fun of(zoneId: String): TimeZone = try {
3839
ofZone(ZoneId.of(zoneId))

core/jvm/test/ConvertersTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class ConvertersTest {
147147
}
148148

149149
test("Z")
150+
test("UTC")
150151
test("Etc/UTC")
151152
test("+00")
152153
test("+0000")

core/linux/src/internal/TimeZoneNative.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal actual fun currentSystemDefaultZone(): Pair<String, TimeZone?> {
4848
// According to https://www.man7.org/linux/man-pages/man5/localtime.5.html, UTC is used when /etc/localtime is missing.
4949
// If /etc/localtime exists but isn't a symlink, we check if it's a copy of a timezone file by examining /etc/timezone
5050
// (which is a Debian-specific approach used in older distributions).
51-
val zonePath = currentSystemTimeZonePath ?: return "Z" to null
51+
val zonePath = currentSystemTimeZonePath ?: return "UTC" to null
5252

5353
zonePath.splitTimeZonePath()?.second?.toString()?.let { zoneId ->
5454
return zoneId to null

js-without-timezones/common/test/TimezonesWithoutDatabaseTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TimezonesWithoutDatabaseTest {
2929
fun utc() {
3030
val utc: FixedOffsetTimeZone = TimeZone.UTC
3131
println(utc)
32-
assertEquals("Z", utc.id)
32+
assertEquals("UTC", utc.id)
3333
assertEquals(UtcOffset.ZERO, utc.offset)
3434
assertEquals(0, utc.offset.totalSeconds)
3535
assertEquals(utc.offset, utc.offsetAt(Clock.System.now()))

0 commit comments

Comments
 (0)