Date format issue.

This commit is contained in:
aminecmi 2022-12-25 22:41:34 +01:00
parent 9ed9bf07fc
commit 813e0707d8
2 changed files with 16 additions and 1 deletions

View File

@ -11,6 +11,7 @@ class DatesTest {
private val v3Date = "2013-04-07T13:43:00+01:00" private val v3Date = "2013-04-07T13:43:00+01:00"
private val v4Date = "2013-04-07 13:43:00" private val v4Date = "2013-04-07 13:43:00"
private val bug1Date = "2022-12-24T17:00:08+00"
@Test @Test
fun v3_date_should_be_parsed() { fun v3_date_should_be_parsed() {
@ -30,4 +31,14 @@ class DatesTest {
assertEquals(date, expected) assertEquals(date, expected)
} }
@Test
fun bug1_date_should_be_parsed() {
val date = DateUtils.parseDate(bug1Date)
val expected =
LocalDateTime(2022, 12, 24, 18, 0, 8, 0).toInstant(TimeZone.currentSystemDefault())
.toEpochMilliseconds()
assertEquals(date, expected)
}
} }

View File

@ -10,7 +10,11 @@ actual class DateUtils {
return try { return try {
Instant.parse(dateString).toEpochMilliseconds() Instant.parse(dateString).toEpochMilliseconds()
} catch (e: Exception) { } catch (e: Exception) {
LocalDateTime.parse(dateString.replace(" ", "T")).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() var str = dateString.replace(" ", "T")
if (str.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}".toRegex())) {
str = str.split("+")[0]
}
LocalDateTime.parse(str).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds()
} }
} }