Fix MAL error when list entries have partial dates (#3573)
This has the side effect of forcing the date to something concrete. For Year-only: 1st of January that year Ex: 2025 -> 2025-01-01 For Year+Month: 1st of said month Ex: 2024-11 -> 2024-11-01 MAL allows setting Day+Month and Day+Year, but both of those are sent as `null` in the API, which means Mihon will not show a date at all. This has the side effect of Mihon sending up the date as `null` the next time info is sent to MAL, which will clear the date fields completely. Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -245,7 +245,13 @@ class MyAnimeListApi(
|
||||
}
|
||||
|
||||
private fun parseDate(isoDate: String): Long {
|
||||
return SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(isoDate)?.time ?: 0L
|
||||
val pattern = when (isoDate.length) {
|
||||
10 -> "yyyy-MM-dd"
|
||||
7 -> "yyyy-MM"
|
||||
4 -> "yyyy"
|
||||
else -> throw IllegalArgumentException("Unsupported date format: \"$isoDate\"")
|
||||
}
|
||||
return SimpleDateFormat(pattern, Locale.US).parse(isoDate)?.time ?: 0L
|
||||
}
|
||||
|
||||
private fun convertToIsoDate(epochTime: Long): String? {
|
||||
|
||||
Reference in New Issue
Block a user