Skip to content

Commit 4e1aab0

Browse files
committed
Fix a failing test
1 parent 43a9dfb commit 4e1aab0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/time/InstantTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class InstantTest {
7373
Iso8601FmtTest(1604604157, 0, "2020-11-05T19:22:37Z", "20201105T192237Z", "20201105"),
7474
Iso8601FmtTest(1604604157, 422_000_000, "2020-11-05T19:22:37.422Z", "20201105T192237Z", "20201105"),
7575
Iso8601FmtTest(1604604157, 422_000, "2020-11-05T19:22:37.000422Z", "20201105T192237Z", "20201105"),
76-
// Iso8601FmtTest(1604604157, 1, "2020-11-05T19:22:37Z", "20201105T192237Z", "20201105"),
77-
// Iso8601FmtTest(1604604157, 999, "2020-11-05T19:22:37Z", "20201105T192237Z", "20201105"),
76+
Iso8601FmtTest(1604604157, 1, "2020-11-05T19:22:37Z", "20201105T192237Z", "20201105"),
77+
Iso8601FmtTest(1604604157, 999, "2020-11-05T19:22:37Z", "20201105T192237Z", "20201105"),
7878
Iso8601FmtTest(1604604157, 1_000, "2020-11-05T19:22:37.000001Z", "20201105T192237Z", "20201105"),
7979
Iso8601FmtTest(1604602957, 0, "2020-11-05T19:02:37Z", "20201105T190237Z", "20201105"),
8080
Iso8601FmtTest(1604605357, 0, "2020-11-05T19:42:37Z", "20201105T194237Z", "20201105"),

runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/time/InstantNative.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ package aws.smithy.kotlin.runtime.time
77

88
import kotlinx.datetime.Clock
99
import kotlinx.datetime.format
10-
import kotlinx.datetime.format.DateTimeComponents
1110
import kotlinx.datetime.format.FormatStringsInDatetimeFormats
1211
import kotlin.time.Duration
1312
import kotlin.time.Duration.Companion.days
14-
import kotlinx.datetime.Instant as ktInstant
13+
import kotlinx.datetime.Instant as KtInstant
1514

1615
private 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

Comments
 (0)