diff --git a/klock/src/commonMain/kotlin/com/soywiz/klock/DateFormat.kt b/klock/src/commonMain/kotlin/com/soywiz/klock/DateFormat.kt index a4ade17..5c99fc0 100644 --- a/klock/src/commonMain/kotlin/com/soywiz/klock/DateFormat.kt +++ b/klock/src/commonMain/kotlin/com/soywiz/klock/DateFormat.kt @@ -8,9 +8,10 @@ interface DateFormat { companion object { val DEFAULT_FORMAT = DateFormat("EEE, dd MMM yyyy HH:mm:ss z") val FORMAT1 = DateFormat("yyyy-MM-dd'T'HH:mm:ssXXX") + val FORMAT2 = DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") val FORMAT_DATE = DateFormat("yyyy-MM-dd") - val FORMATS = listOf(DEFAULT_FORMAT, FORMAT1) + val FORMATS = listOf(DEFAULT_FORMAT, FORMAT1, FORMAT2, FORMAT_DATE) fun parse(date: String): DateTimeTz { var lastError: Throwable? = null diff --git a/klock/src/commonTest/kotlin/com/soywiz/klock/DateTimeTest.kt b/klock/src/commonTest/kotlin/com/soywiz/klock/DateTimeTest.kt index 65ea99b..deebcf1 100644 --- a/klock/src/commonTest/kotlin/com/soywiz/klock/DateTimeTest.kt +++ b/klock/src/commonTest/kotlin/com/soywiz/klock/DateTimeTest.kt @@ -410,4 +410,12 @@ class DateTimeTest { assertEquals("Sat, 11 Aug -0027 08:00:00 UTC", DateTime.fromUnix(-63000000000000L).toString()) assertEquals("Sun, 31 Dec 0000 23:59:59 UTC", DateTime.fromUnix(-62135596800000L - 1L).toString()) } + + @Test + fun testBug123() { + val str1 = "1989-01-01T10:00:00Z" + val str2 = "1989-01-01T10:00:00.000Z" + assertEquals(str1, DateTime.parse(str1).format(DateFormat.FORMAT1)) + assertEquals(str2, DateTime.parse(str2).format(DateFormat.FORMAT2)) + } }