From 3f2e32dcc256d050d648506f893e9cb76fbbe9c0 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 29 Dec 2023 05:06:35 +0530 Subject: [PATCH] Revert to Java 8 --- app/build.gradle | 6 +++--- .../org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt | 4 +++- .../main/kotlin/org/koitharu/kotatsu/core/util/ext/Date.kt | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 29d97e6d9..649b199a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,11 +48,11 @@ android { } compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { - jvmTarget = JavaVersion.VERSION_17 + jvmTarget = JavaVersion.VERSION_1_8.toString() freeCompilerArgs += [ '-opt-in=kotlin.ExperimentalStdlibApi', '-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi', diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt index cbee580f3..ea731925c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt @@ -75,7 +75,7 @@ sealed class DateTimeAgo { data class Absolute(private val date: LocalDate) : DateTimeAgo() { override fun format(resources: Resources): String { - return if (date == LocalDate.EPOCH) { + return if (date == EPOCH_DATE) { resources.getString(R.string.unknown) } else { date.format(formatter) @@ -85,6 +85,8 @@ sealed class DateTimeAgo { override fun toString() = "abs_${date.toEpochDay()}" companion object { + // TODO: Use Java 9's LocalDate.EPOCH. + private val EPOCH_DATE = LocalDate.of(1970, 1, 1) private val formatter = DateTimeFormatter.ofPattern("d MMMM") } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Date.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Date.kt index b738cbac0..be2f2e04d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Date.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Date.kt @@ -3,11 +3,13 @@ package org.koitharu.kotatsu.core.util.ext import org.koitharu.kotatsu.core.ui.model.DateTimeAgo import java.time.Instant import java.time.LocalDate +import java.time.LocalDateTime import java.time.ZoneId import java.time.temporal.ChronoUnit fun calculateTimeAgo(instant: Instant, showMonths: Boolean = false): DateTimeAgo { - val localDate = LocalDate.ofInstant(instant, ZoneId.systemDefault()) + // TODO: Use Java 9's LocalDate.ofInstant(). + val localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate() val now = LocalDate.now() val diffDays = localDate.until(now, ChronoUnit.DAYS)