diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index 94e9b21839..f907fe90d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt @@ -87,11 +87,13 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { val response = responseToJson(netResponse) try { val media = response["data"]["SaveMediaListEntry"].asJsonObject - if (track.started_reading_date <= 0L) { - track.started_reading_date = parseDate(media, "startedAt") + val startedDate = parseDate(media, "startedAt") + if (track.started_reading_date <= 0L || startedDate > 0) { + track.started_reading_date = startedDate } - if (track.finished_reading_date <= 0L) { - track.finished_reading_date = parseDate(media, "completedAt") + val finishedDate = parseDate(media, "completedAt") + if (track.finished_reading_date <= 0L || finishedDate > 0) { + track.finished_reading_date = finishedDate } } catch (e: Exception) { } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index 6f3d953f82..a9cb749300 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -208,17 +208,23 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI status = if (isRereading) MyAnimeList.REREADING else getStatus(obj["status"]!!.jsonPrimitive.content) last_chapter_read = obj["num_chapters_read"]!!.jsonPrimitive.int score = obj["score"]!!.jsonPrimitive.int.toFloat() - obj["start_date"]?.let { - started_reading_date = parseDate(it.jsonPrimitive.content) + val startedDate = parseDate(obj["start_date"]?.jsonPrimitive?.content ?: "") + if (track.started_reading_date <= 0L || startedDate > 0) { + track.started_reading_date = startedDate } - obj["finish_date"]?.let { - finished_reading_date = parseDate(it.jsonPrimitive.content) + val finishedDate = parseDate(obj["finish_date"]?.jsonPrimitive?.content ?: "") + if (track.finished_reading_date <= 0L || finishedDate > 0) { + track.finished_reading_date = finishedDate } } } private fun parseDate(isoDate: String): Long { - return SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(isoDate)?.time ?: 0L + return try { + SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(isoDate)?.time ?: 0L + } catch (_: Exception) { + 0L + } } private fun convertToIsoDate(epochTime: Long): String? {