@@ -7,22 +7,22 @@ package aws.smithy.kotlin.runtime.time
77
88import kotlinx.datetime.Clock
99import kotlinx.datetime.format
10- import kotlinx.datetime.format.DateTimeComponents
1110import kotlinx.datetime.format.FormatStringsInDatetimeFormats
1211import kotlin.time.Duration
1312import kotlin.time.Duration.Companion.days
14- import kotlinx.datetime.Instant as ktInstant
13+ import kotlinx.datetime.Instant as KtInstant
1514
1615private fun TimestampFormat.asDateTimeFormat () = when (this ) {
17- TimestampFormat .ISO_8601 -> DateTimeFormats .ISO_8601
1816 TimestampFormat .RFC_5322 -> DateTimeFormats .RFC_5322
19- TimestampFormat .ISO_8601_FULL -> DateTimeComponents . Format { }
17+ TimestampFormat .ISO_8601_FULL -> DateTimeFormats . ISO_8601
2018 TimestampFormat .ISO_8601_CONDENSED -> DateTimeFormats .ISO_8601_CONDENSED
2119 TimestampFormat .ISO_8601_CONDENSED_DATE -> DateTimeFormats .ISO_8601_CONDENSED_DATE
2220 else -> throw IllegalArgumentException (" TimestampFormat $this could not be converted to a DateTimeFormat" )
2321}
2422
25- public actual class Instant (internal val delegate : ktInstant) : Comparable<Instant> {
23+ private fun KtInstant.truncateToMicros (): KtInstant = KtInstant .fromEpochSeconds(epochSeconds, nanosecondsOfSecond / 1_000 * 1_000 )
24+
25+ public actual class Instant (internal val delegate : KtInstant ) : Comparable<Instant> {
2626
2727 actual override fun compareTo (other : Instant ): Int = delegate.compareTo(other.delegate)
2828
@@ -33,6 +33,7 @@ public actual class Instant(internal val delegate: ktInstant) : Comparable<Insta
3333 * Encode the [Instant] as a string into the format specified by [TimestampFormat]
3434 */
3535 public actual fun format (fmt : TimestampFormat ): String = when (fmt) {
36+ TimestampFormat .ISO_8601 -> delegate.truncateToMicros().format(DateTimeFormats .ISO_8601 )
3637 TimestampFormat .EPOCH_SECONDS -> {
3738 val s = delegate.epochSeconds.toString()
3839 val ns = if (delegate.nanosecondsOfSecond != 0 ) {
@@ -81,12 +82,12 @@ public actual class Instant(internal val delegate: ktInstant) : Comparable<Insta
8182 /* *
8283 * Parse an RFC5322/RFC-822 formatted string into an [Instant]
8384 */
84- public actual fun fromRfc5322 (ts : String ): Instant = Instant (ktInstant .parse(ts, DateTimeFormats .RFC_5322 ))
85+ public actual fun fromRfc5322 (ts : String ): Instant = Instant (KtInstant .parse(ts, DateTimeFormats .RFC_5322 ))
8586
8687 /* *
8788 * Create an [Instant] from its parts
8889 */
89- public actual fun fromEpochSeconds (seconds : Long , ns : Int ): Instant = Instant (ktInstant .fromEpochSeconds(seconds, ns))
90+ public actual fun fromEpochSeconds (seconds : Long , ns : Int ): Instant = Instant (KtInstant .fromEpochSeconds(seconds, ns))
9091
9192 /* *
9293 * Parse a string formatted as epoch-seconds into an [Instant]
@@ -102,12 +103,12 @@ public actual class Instant(internal val delegate: ktInstant) : Comparable<Insta
102103 /* *
103104 * Create an [Instant] with the minimum possible value
104105 */
105- public actual val MIN_VALUE : Instant = Instant (ktInstant .DISTANT_PAST )
106+ public actual val MIN_VALUE : Instant = Instant (KtInstant .DISTANT_PAST )
106107
107108 /* *
108109 * Create an [Instant] with the maximum possible value
109110 */
110- public actual val MAX_VALUE : Instant = Instant (ktInstant .DISTANT_FUTURE )
111+ public actual val MAX_VALUE : Instant = Instant (KtInstant .DISTANT_FUTURE )
111112 }
112113
113114 public override fun equals (other : Any? ): Boolean = other is Instant && delegate == other.delegate
0 commit comments