Date format issue.
This commit is contained in:
parent
9ed9bf07fc
commit
813e0707d8
@ -11,6 +11,7 @@ class DatesTest {
|
||||
|
||||
private val v3Date = "2013-04-07T13:43:00+01:00"
|
||||
private val v4Date = "2013-04-07 13:43:00"
|
||||
private val bug1Date = "2022-12-24T17:00:08+00"
|
||||
|
||||
@Test
|
||||
fun v3_date_should_be_parsed() {
|
||||
@ -30,4 +31,14 @@ class DatesTest {
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ actual class DateUtils {
|
||||
return try {
|
||||
Instant.parse(dateString).toEpochMilliseconds()
|
||||
} 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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user