Skip to content

Commit 2197a75

Browse files
committed
Re-enable testSigningKey after fixing Native's fromIso8601 implementation
1 parent eb971de commit 2197a75

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

runtime/auth/aws-signing-default/common/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultSignatureCalculatorTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class DefaultSignatureCalculatorTest {
3333
}
3434

3535
// Test adapted from https://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
36-
@IgnoreNative // FIXME Re-enable after Kotlin/Native Implementation. Need to fix parsing ISO 8601 to try all possible formats
3736
@Test
3837
fun testSigningKey() = runTest {
3938
val config = AwsSigningConfig {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class InstantTest {
5656

5757
// leap second - dropped to: 2020-12-31T23:59:59
5858
FromTest("2020-12-31T23:59:60Z", 1609459199, 0),
59+
60+
// condensed, date only
61+
FromTest("20250205", 1738713600, 0),
62+
FromTest("20231127", 1701043200, 0),
5963
)
6064

6165
@Test

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package aws.smithy.kotlin.runtime.time
88
import kotlinx.datetime.LocalDate
99
import kotlinx.datetime.UtcOffset
1010
import kotlinx.datetime.format.DateTimeComponents
11+
import kotlinx.datetime.format.DateTimeFormat
1112
import kotlinx.datetime.format.DayOfWeekNames
1213
import kotlinx.datetime.format.MonthNames
1314
import kotlinx.datetime.format.Padding
@@ -131,3 +132,14 @@ internal object DateTimeFormats {
131132
}
132133
}
133134
}
135+
136+
/**
137+
* ISO8601 condensed, date only. Corresponds to [TimestampFormat.ISO_8601_CONDENSED_DATE].
138+
* Used only for _parsing_ ISO8601 condensed strings. Instant.parse() will fail if using [DateTimeFormats.ISO_8601_CONDENSED_DATE]
139+
* because that is a [DateTimeFormat] which requires a time component to be present.
140+
*/
141+
internal val ISO_8601_CONDENSED_DATE_LOCALDATE = LocalDate.Format {
142+
year()
143+
monthNumber()
144+
dayOfMonth()
145+
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
package aws.smithy.kotlin.runtime.time
77

88
import kotlinx.datetime.Clock
9+
import kotlinx.datetime.LocalDate
10+
import kotlinx.datetime.LocalDateTime
11+
import kotlinx.datetime.LocalTime
12+
import kotlinx.datetime.TimeZone
13+
import kotlinx.datetime.atStartOfDayIn
914
import kotlinx.datetime.format
15+
import kotlinx.datetime.toInstant
1016
import kotlin.time.Duration
1117
import kotlinx.datetime.Instant as KtInstant
1218

@@ -62,17 +68,22 @@ public actual class Instant(internal val delegate: KtInstant) : Comparable<Insta
6268
/**
6369
* Parse an ISO-8601 formatted string into an [Instant]
6470
*/
65-
public actual fun fromIso8601(ts: String): Instant = try {
66-
var parsed = DateTimeFormats.ISO_8601.parse(ts).apply {
67-
// Handle leap seconds (23:59:60 becomes 23:59:59)
68-
if (second == 60) {
69-
second = 59
71+
public actual fun fromIso8601(ts: String): Instant {
72+
val parseException = lazy { ParseException(ts, "Failed to parse $ts into an ISO-8601 timestamp", 0) }
73+
74+
listOf(
75+
{ DateTimeFormats.ISO_8601.parse(ts).apply { if (second == 60) second = 59 }.toInstantUsingOffset() },
76+
{ KtInstant.parse(ts, DateTimeFormats.ISO_8601_CONDENSED) },
77+
{ LocalDate.parse(ts, ISO_8601_CONDENSED_DATE_LOCALDATE).atStartOfDayIn(TimeZone.UTC) },
78+
).forEach { parseFn ->
79+
try {
80+
return Instant(parseFn())
81+
} catch (e: IllegalArgumentException) {
82+
parseException.value.addSuppressed(e)
7083
}
7184
}
7285

73-
Instant(parsed.toInstantUsingOffset())
74-
} catch (e: IllegalArgumentException) {
75-
throw ParseException(ts, "Failed to parse $ts into an ISO-8601 timestamp", 0)
86+
throw parseException.value
7687
}
7788

7889
/**

0 commit comments

Comments
 (0)