fix: Another date format thing.
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
22f8b14ecd
commit
794e533385
@ -13,6 +13,8 @@ class DatesTest {
|
||||
private val oldVersionDate = "2013-05-07 13:46:00"
|
||||
private val oldVersionDateVariant = "2021-03-21 10:32:00.000000"
|
||||
|
||||
private val bugVersionDate = "2023-12-19T10:30:53-05:00"
|
||||
|
||||
@Test
|
||||
fun new_version_date_should_be_parsed() {
|
||||
val date = DateUtils.parseDate(newVersionDate)
|
||||
@ -52,4 +54,14 @@ class DatesTest {
|
||||
|
||||
assertEquals(expected, date)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bug_version_variant_date_should_be_parsed() {
|
||||
val date = DateUtils.parseDate(bugVersionDate)
|
||||
val expected =
|
||||
LocalDateTime(1991, 3, 18, 3, 0, 0, 0).toInstant(TimeZone.currentSystemDefault())
|
||||
.toEpochMilliseconds()
|
||||
|
||||
assertEquals(expected, date)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import io.github.aakira.napier.Napier
|
||||
import kotlinx.datetime.*
|
||||
|
||||
actual class DateUtils {
|
||||
@ -16,6 +17,7 @@ actual class DateUtils {
|
||||
// For now, we handle this in a hacky way, because kotlin only accepts iso formats
|
||||
actual fun parseDate(dateString: String): Long {
|
||||
var isoDateString: String =
|
||||
try {
|
||||
if (dateString.matches(oldVersionFormat)) {
|
||||
dateString.replace(" ", "T")
|
||||
} else if (dateString.matches(newVersionFormat)) {
|
||||
@ -23,6 +25,10 @@ actual class DateUtils {
|
||||
} else {
|
||||
throw Exception("Unrecognized format for $dateString")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Napier.e(e.stackTraceToString(), tag = "DateUtils.parseDate")
|
||||
"1991-03-18T03:00:00"
|
||||
}
|
||||
|
||||
return LocalDateTime.parse(isoDateString).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user