fix: Another date format thing.

This commit is contained in:
aminecmi
2024-01-03 23:07:33 +01:00
parent 22f8b14ecd
commit 750c7758bd
2 changed files with 24 additions and 6 deletions

View File

@ -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,12 +17,17 @@ 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 =
if (dateString.matches(oldVersionFormat)) {
dateString.replace(" ", "T")
} else if (dateString.matches(newVersionFormat)) {
dateString.split("+")[0]
} else {
throw Exception("Unrecognized format for $dateString")
try {
if (dateString.matches(oldVersionFormat)) {
dateString.replace(" ", "T")
} else if (dateString.matches(newVersionFormat)) {
dateString.split("+")[0]
} 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()