Skip to content

Commit b2b26e1

Browse files
authored
Upgrade to kotlinx-datetime 0.7.1 (#697)
1 parent 8992657 commit b2b26e1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ junit = "4.13.2"
4545

4646
kotlinx-coroutines = "1.10.2"
4747
kotlinx-coroutines-test = "1.10.2"
48-
kotlinx-datetime = "0.6.2"
48+
kotlinx-datetime = "0.7.1"
4949
kotlinx-serialization-json = "1.8.1"
5050

5151
# Make sure to align with the Kotlin version.

readium/shared/src/main/java/org/readium/r2/shared/util/Instant.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@file:OptIn(InternalReadiumApi::class)
1+
@file:OptIn(InternalReadiumApi::class, kotlin.time.ExperimentalTime::class)
22

33
package org.readium.r2.shared.util
44

55
import android.os.Parcel
66
import android.os.Parcelable
7-
import kotlinx.datetime.Clock
7+
import kotlin.time.Clock
88
import kotlinx.datetime.LocalDate
99
import kotlinx.datetime.LocalDateTime
1010
import kotlinx.datetime.TimeZone
@@ -25,14 +25,16 @@ import kotlinx.serialization.encoding.Encoder
2525
import org.readium.r2.shared.InternalReadiumApi
2626
import org.readium.r2.shared.extensions.tryOrNull
2727

28+
private typealias KotlinInstant = kotlin.time.Instant
29+
2830
/**
2931
* A moment in time.
3032
*/
3133
@Parcelize
32-
@TypeParceler<kotlinx.datetime.Instant, InstantParceler>()
34+
@TypeParceler<KotlinInstant, InstantParceler>()
3335
@Serializable(with = InstantSerializer::class)
3436
public class Instant private constructor(
35-
private val value: kotlinx.datetime.Instant,
37+
private val value: KotlinInstant,
3638
) : Parcelable, Comparable<Instant> {
3739
public companion object {
3840
/**
@@ -41,28 +43,28 @@ public class Instant private constructor(
4143
* Returns null if it can't be parsed.
4244
*/
4345
public fun parse(input: String): Instant? {
44-
val instant = tryOrNull { kotlinx.datetime.Instant.parse(input) }
46+
val instant = tryOrNull { KotlinInstant.parse(input) }
4547
?: tryOrNull { LocalDateTime.parse(input).toInstant(TimeZone.UTC) }
4648
?: tryOrNull { LocalDate.parse(input).atStartOfDayIn(TimeZone.UTC) }
4749

4850
return instant?.let { Instant(it) }
4951
}
5052

51-
public fun fromKotlinInstant(value: kotlinx.datetime.Instant): Instant = Instant(value)
53+
public fun fromKotlinInstant(value: KotlinInstant): Instant = Instant(value)
5254

5355
public fun fromJavaDate(date: java.util.Date): Instant =
54-
Instant(kotlinx.datetime.Instant.fromEpochMilliseconds(date.time))
56+
Instant(KotlinInstant.fromEpochMilliseconds(date.time))
5557

5658
public fun fromEpochMilliseconds(milliseconds: Long): Instant =
57-
Instant(kotlinx.datetime.Instant.fromEpochMilliseconds(milliseconds))
59+
Instant(KotlinInstant.fromEpochMilliseconds(milliseconds))
5860

5961
/**
6062
* Returns an [Instant] representing the current moment in time.
6163
*/
6264
public fun now(): Instant = Instant(Clock.System.now())
6365
}
6466

65-
public fun toKotlinInstant(): kotlinx.datetime.Instant = value
67+
public fun toKotlinInstant(): KotlinInstant = value
6668

6769
public fun toJavaDate(): java.util.Date = java.util.Date(value.toEpochMilliseconds())
6870

@@ -83,12 +85,12 @@ public class Instant private constructor(
8385
}
8486

8587
@InternalReadiumApi
86-
private object InstantParceler : Parceler<kotlinx.datetime.Instant> {
88+
private object InstantParceler : Parceler<KotlinInstant> {
8789

88-
override fun create(parcel: Parcel): kotlinx.datetime.Instant =
89-
kotlinx.datetime.Instant.fromEpochMilliseconds(parcel.readLong())
90+
override fun create(parcel: Parcel): KotlinInstant =
91+
KotlinInstant.fromEpochMilliseconds(parcel.readLong())
9092

91-
override fun kotlinx.datetime.Instant.write(parcel: Parcel, flags: Int) {
93+
override fun KotlinInstant.write(parcel: Parcel, flags: Int) {
9294
parcel.writeLong(toEpochMilliseconds())
9395
}
9496
}

0 commit comments

Comments
 (0)