1- @file:OptIn(InternalReadiumApi ::class )
1+ @file:OptIn(InternalReadiumApi ::class , kotlin.time. ExperimentalTime :: class )
22
33package org.readium.r2.shared.util
44
55import android.os.Parcel
66import android.os.Parcelable
7- import kotlinx.datetime .Clock
7+ import kotlin.time .Clock
88import kotlinx.datetime.LocalDate
99import kotlinx.datetime.LocalDateTime
1010import kotlinx.datetime.TimeZone
@@ -25,14 +25,16 @@ import kotlinx.serialization.encoding.Encoder
2525import org.readium.r2.shared.InternalReadiumApi
2626import 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 )
3436public 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