44 */
55package aws.smithy.kotlin.runtime.time
66
7- import aws.smithy.kotlin.runtime.IgnoreNative
87import kotlin.test.Test
98import kotlin.test.assertEquals
109import kotlin.test.assertTrue
@@ -18,7 +17,6 @@ import kotlin.time.Duration.Companion.seconds
1817// tests for conversion from a parsed representation into an Instant instance
1918
2019class InstantTest {
21-
2220 /* *
2321 * Conversion from a string to epoch sec/ns
2422 */
@@ -58,11 +56,8 @@ class InstantTest {
5856
5957 // leap second - dropped to: 2020-12-31T23:59:59
6058 FromTest (" 2020-12-31T23:59:60Z" , 1609459199 , 0 ),
61- // midnight - should be 11/5 12AM
62- FromTest (" 2020-11-04T24:00:00Z" , 1604534400 , 0 ),
6359 )
6460
65- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
6661 @Test
6762 fun testFromIso8601 () {
6863 for ((idx, test) in iso8601Tests.withIndex()) {
@@ -101,7 +96,6 @@ class InstantTest {
10196 TimestampFormat .ISO_8601_CONDENSED_DATE to Iso8601FmtTest ::expectedIso8601CondDate,
10297 )
10398
104- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
10599 @Test
106100 fun testFormatAsIso8601 () {
107101 for ((idx, test) in iso8601FmtTests.withIndex()) {
@@ -110,7 +104,7 @@ class InstantTest {
110104 .fromEpochSeconds(test.sec, test.ns)
111105 .format(format)
112106 val expected = getter(test)
113- assertEquals(expected, actual, " test[$idx ]: failed to correctly format Instant as $format " )
107+ assertEquals(expected, actual, " test[$idx ]: failed to correctly format Instant.fromEpochSeconds( ${test.sec} , ${test.ns} ) as $format " )
114108 }
115109 }
116110 }
@@ -125,7 +119,6 @@ class InstantTest {
125119 FromTest (" Thu, 05 Nov 2020 19:22:37 -1245" , 1604650057 , 0 ),
126120 )
127121
128- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
129122 @Test
130123 fun testFromRfc5322 () {
131124 for ((idx, test) in rfc5322Tests.withIndex()) {
@@ -143,7 +136,6 @@ class InstantTest {
143136 FmtTest (1604650057 , 0 , " Fri, 06 Nov 2020 08:07:37 GMT" ),
144137 )
145138
146- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
147139 @Test
148140 fun testFormatAsRfc5322 () {
149141 for ((idx, test) in rfc5322FmtTests.withIndex()) {
@@ -162,7 +154,6 @@ class InstantTest {
162154 FmtTest (1604604157 , 345_006_000 , " 1604604157.345006" ),
163155 )
164156
165- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
166157 @Test
167158 fun testFormatAsEpochSeconds () {
168159 for ((idx, test) in epochFmtTests.withIndex()) {
@@ -173,7 +164,6 @@ class InstantTest {
173164 }
174165 }
175166
176- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
177167 @Test
178168 fun testToEpochDouble () {
179169 val sec = 1604604157L
@@ -184,7 +174,6 @@ class InstantTest {
184174 assertTrue(kotlin.math.abs(0.012345 - fracSecs) < 0.00001 )
185175 }
186176
187- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
188177 @Test
189178 fun testGetCurrentTime () {
190179 val currentTime = Instant .now()
@@ -194,7 +183,6 @@ class InstantTest {
194183 assertTrue(currentTime.epochSeconds > pastInstant)
195184 }
196185
197- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
198186 @Test
199187 fun testGetEpochMilliseconds () {
200188 val instant = Instant .fromEpochSeconds(1602878160 , 200_000 )
@@ -206,7 +194,6 @@ class InstantTest {
206194 assertEquals(expected2, instantWithMilli.epochMilliseconds)
207195 }
208196
209- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
210197 @Test
211198 fun testFromEpochMilliseconds () {
212199 val ts1 = 1602878160000L
@@ -218,54 +205,34 @@ class InstantTest {
218205 assertEquals(expected2, Instant .fromEpochMilliseconds(ts2))
219206 }
220207
221- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
222208 @Test
223209 fun testNegativeFromEpochSeconds () {
224210 val timestamp = Instant .fromEpochSeconds(- 806976000L )
225211 assertEquals(" 1944-06-06T00:00:00Z" , timestamp.toString())
226212 }
227213
228- // Select tests pulled from edge cases/tickets in the V2 Java SDK.
229- // Always good to learn from others...
230- class V2JavaSdkTests {
231- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
232- @Test
233- fun v2JavaSdkTt0031561767 () {
234- val input = " Fri, 16 May 2014 23:56:46 GMT"
235- val instant: Instant = Instant .fromRfc5322(input)
236- assertEquals(input, instant.format(TimestampFormat .RFC_5322 ))
237- }
214+ @Test
215+ fun testUntil () {
216+ val untilTests = mapOf (
217+ (" 2013-01-01T00:00:00+00:00" to " 2014-01-01T00:00:00+00:00" ) to 365 .days,
218+ (" 2020-01-01T00:00:00+00:00" to " 2021-01-01T00:00:00+00:00" ) to 366 .days, // leap year!
219+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:00:00+00:00" ) to Duration .ZERO ,
220+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-07T00:00:00+00:00" ) to 1 .days,
221+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T01:00:00+00:00" ) to 1 .hours,
222+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:01:00+00:00" ) to 1 .minutes,
223+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:00:01+00:00" ) to 1 .seconds,
224+ (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T12:12:12+00:00" ) to 12 .hours + 12 .minutes + 12 .seconds,
225+ )
238226
239- /* *
240- * Tests the Date marshalling and unmarshalling. Asserts that the value is
241- * same before and after marshalling/unmarshalling
242- */
243- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
244- @Test
245- fun v2JavaSdkUnixTimestampRoundtrip () {
246- // v2 sdk used currentTimeMillis(), instead we just hard code a value here
247- // otherwise that would be a JVM specific test since since we do not (yet) have
248- // a Kotlin MPP way of getting current timestamp. Also obviously not using epoch mill
249- // but instead just epoch sec. Spirit of the test is the same though
250- longArrayOf(1595016457 , 1L , 0L )
251- .map { Instant .fromEpochSeconds(0 , 0 ) }
252- .forEach { instant ->
253- val serverSpecificDateFormat: String = instant.format(TimestampFormat .EPOCH_SECONDS )
254- val parsed: Instant = parseEpoch(serverSpecificDateFormat)
255- assertEquals(instant.epochSeconds, parsed.epochSeconds)
256- }
257- }
227+ for ((times, expectedDuration) in untilTests) {
228+ val start = Instant .fromIso8601(times.first)
229+ val end = Instant .fromIso8601(times.second)
258230
259- // NOTE: There is additional set of edge case tests related to a past issue
260- // in DateUtilsTest.java in the v2 sdk. Specifically around
261- // issue 223: https://github.com/aws/aws-sdk-java/issues/233
262- //
263- // (1) - That issue is about round tripping values between SDK versions
264- // (2) - The input year in those tests is NOT valid and should never have
265- // been accepted by the parser.
231+ assertEquals(expectedDuration, start.until(end))
232+ assertEquals(end.until(start), - expectedDuration)
233+ }
266234 }
267235
268- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
269236 @Test
270237 fun testPlusMinusDuration () {
271238 val start = Instant .fromEpochSeconds(1000 , 1000 )
@@ -275,7 +242,6 @@ class InstantTest {
275242 assertEquals(Instant .fromEpochSeconds(990 , 0 ), start - offset)
276243 }
277244
278- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
279245 @Test
280246 fun testRoundTripUtcOffset () {
281247 // sanity check we only ever emit UTC timestamps (e.g. round trip a response with UTC offset)
@@ -293,27 +259,42 @@ class InstantTest {
293259 assertEquals(test.second, actual, " test[$idx ]: failed to format offset timestamp in UTC" )
294260 }
295261 }
262+ }
296263
297- @IgnoreNative // FIXME Re-enable after Kotlin/Native implementation
264+ // Select tests pulled from edge cases/tickets in the V2 Java SDK.
265+ // Always good to learn from others...
266+ class V2JavaSdkTests {
298267 @Test
299- fun testUntil () {
300- val untilTests = mapOf (
301- (" 2013-01-01T00:00:00+00:00" to " 2014-01-01T00:00:00+00:00" ) to 365 .days,
302- (" 2020-01-01T00:00:00+00:00" to " 2021-01-01T00:00:00+00:00" ) to 366 .days, // leap year!
303- (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:00:00+00:00" ) to Duration .ZERO ,
304- (" 2023-10-06T00:00:00+00:00" to " 2023-10-07T00:00:00+00:00" ) to 1 .days,
305- (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T01:00:00+00:00" ) to 1 .hours,
306- (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:01:00+00:00" ) to 1 .minutes,
307- (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T00:00:01+00:00" ) to 1 .seconds,
308- (" 2023-10-06T00:00:00+00:00" to " 2023-10-06T12:12:12+00:00" ) to 12 .hours + 12 .minutes + 12 .seconds,
309- )
310-
311- for ((times, expectedDuration) in untilTests) {
312- val start = Instant .fromIso8601(times.first)
313- val end = Instant .fromIso8601(times.second)
268+ fun v2JavaSdkTt0031561767 () {
269+ val input = " Fri, 16 May 2014 23:56:46 GMT"
270+ val instant: Instant = Instant .fromRfc5322(input)
271+ assertEquals(input, instant.format(TimestampFormat .RFC_5322 ))
272+ }
314273
315- assertEquals(expectedDuration, start.until(end))
316- assertEquals(end.until(start), - expectedDuration)
317- }
274+ /* *
275+ * Tests the Date marshalling and unmarshalling. Asserts that the value is
276+ * same before and after marshalling/unmarshalling
277+ */
278+ @Test
279+ fun v2JavaSdkUnixTimestampRoundtrip () {
280+ // v2 sdk used currentTimeMillis(), instead we just hard code a value here
281+ // otherwise that would be a JVM specific test since since we do not (yet) have
282+ // a Kotlin MPP way of getting current timestamp. Also obviously not using epoch mill
283+ // but instead just epoch sec. Spirit of the test is the same though
284+ longArrayOf(1595016457 , 1L , 0L )
285+ .map { Instant .fromEpochSeconds(0 , 0 ) }
286+ .forEach { instant ->
287+ val serverSpecificDateFormat: String = instant.format(TimestampFormat .EPOCH_SECONDS )
288+ val parsed: Instant = parseEpoch(serverSpecificDateFormat)
289+ assertEquals(instant.epochSeconds, parsed.epochSeconds)
290+ }
318291 }
292+
293+ // NOTE: There is additional set of edge case tests related to a past issue
294+ // in DateUtilsTest.java in the v2 sdk. Specifically around
295+ // issue 223: https://github.com/aws/aws-sdk-java/issues/233
296+ //
297+ // (1) - That issue is about round tripping values between SDK versions
298+ // (2) - The input year in those tests is NOT valid and should never have
299+ // been accepted by the parser.
319300}
0 commit comments