diff --git a/build.gradle.kts b/build.gradle.kts index ca581f3..34eff79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,10 +7,10 @@ buildscript { plugins { //trick: for the same plugin versions in all sub-modules - id("com.android.application").version("8.7.2").apply(false) - id("com.android.library").version("8.7.2").apply(false) - id("org.jetbrains.kotlin.android").version("1.9.10").apply(false) - kotlin("multiplatform").version("1.9.10").apply(false) + id("com.android.application").version("8.7.3").apply(false) + id("com.android.library").version("8.7.3").apply(false) + id("org.jetbrains.kotlin.android").version("2.1.0").apply(false) + kotlin("multiplatform").version("2.1.0").apply(false) id("com.mikepenz.aboutlibraries.plugin").version("10.5.1").apply(false) id("org.jetbrains.kotlinx.kover").version("0.6.1").apply(true) } @@ -25,7 +25,7 @@ allprojects { tasks.register("clean", Delete::class) { - delete(rootProject.buildDir) + delete(layout.buildDirectory) } koverMerged { diff --git a/gradle.properties b/gradle.properties index d40bc34..28fdf63 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,6 @@ kotlin.code.style=official #Android android.useAndroidX=true #android.nonTransitiveRClass=true -android.enableJetifier=true android.nonTransitiveRClass=false #MPP kotlin.mpp.enableCInteropCommonization=true diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 279f7f1..1e703a0 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -173,7 +173,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n"; + shellScript = "export JAVA_HOME=/Users/amine/.sdkman/candidates/java/17.0.8.1-jbr\ncd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode --stacktrace\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index a019f19..0af0d6f 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -52,6 +52,9 @@ kotlin { // Sql implementation(SqlDelight.runtime) + + // Sql + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1") } } val commonTest by getting { @@ -80,10 +83,6 @@ kotlin { val iosArm64Main by getting // val iosSimulatorArm64Main by getting val iosMain by creating { - dependsOn(commonMain) - iosX64Main.dependsOn(this) - iosArm64Main.dependsOn(this) - // iosSimulatorArm64Main.dependsOn(this) dependencies { implementation(SqlDelight.native) @@ -94,10 +93,6 @@ kotlin { val iosArm64Test by getting // val iosSimulatorArm64Test by getting val iosTest by creating { - dependsOn(commonTest) - iosX64Test.dependsOn(this) - iosArm64Test.dependsOn(this) - // iosSimulatorArm64Test.dependsOn(this) } } } diff --git a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 8c2b8e0..e5664fb 100644 --- a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -6,33 +6,8 @@ import kotlinx.datetime.* actual class DateUtils { actual companion object { - // Possible formats are - // yyyy-mm-dd hh:mm:ss format - private val oldVersionFormat = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.()\\d*)?".toRegex() - - // yyyy-MM-dd'T'HH:mm:ss[.SSS]XXX (RFC3339) - private val newVersionFormat = "(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})[+-](\\d{2}(:\\d{2})?)?".toRegex() - - // TODO: do not fix any more issues here. Move everything to plateform specific code. - actual fun parseDate(dateString: String): Long { - var isoDateString: String = - try { - if (dateString.matches(oldVersionFormat)) { - dateString.replace(" ", "T") - } else if (dateString.matches(newVersionFormat)) { - newVersionFormat.find(dateString)?.groups?.get(1)?.value ?: throw Exception("Couldn't parse $dateString") - } else { - throw Exception("Unrecognized format for $dateString") - } - } catch (e: Exception) { - throw Exception("parseDate failed for $dateString", e) - } - - return LocalDateTime.parse(isoDateString).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() - } - actual fun parseRelativeDate(dateString: String): String { - val date = parseDate(dateString) + val date = dateString.toParsedDate() return " " + DateUtils.getRelativeTimeSpanString( diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 5a7433c..f84df1f 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -74,7 +74,7 @@ class Repository( dbItems = dbItems.filter { it.sourcetitle == sourceFilter.value!!.title } } val itemsList = ArrayList(dbItems.map { it.toView() }) - itemsList.sortByDescending { DateUtils.parseDate(it.datetime) } + itemsList.sortByDescending { it.datetime.toParsedDate() } fetchedItems = StatusAndData.succes( itemsList, diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 0645a66..7cbcbbd 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -1,9 +1,35 @@ package bou.amine.apps.readerforselfossv2.utils +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toInstant + +fun String.toParsedDate(): Long { + // Possible formats are + // yyyy-mm-dd hh:mm:ss format + val oldVersionFormat = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.()\\d*)?".toRegex() + + // yyyy-MM-dd'T'HH:mm:ss[.SSS]XXX (RFC3339) + val newVersionFormat = "(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})[+-](\\d{2}(:\\d{2})?)?".toRegex() + + val isoDateString: String = + try { + if (this.matches(oldVersionFormat)) { + this.replace(" ", "T") + } else if (this.matches(newVersionFormat)) { + newVersionFormat.find(this)?.groups?.get(1)?.value ?: throw Exception("Couldn't parse $this") + } else { + throw Exception("Unrecognized format for $this") + } + } catch (e: Exception) { + throw Exception("parseDate failed for $this", e) + } + + return LocalDateTime.parse(isoDateString).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() +} + expect class DateUtils() { companion object { - fun parseDate(dateString: String): Long - fun parseRelativeDate(dateString: String): String } } diff --git a/shared/src/commonTest/kotlin/DatesTest.kt b/shared/src/commonTest/kotlin/DatesTest.kt new file mode 100644 index 0000000..e074d04 --- /dev/null +++ b/shared/src/commonTest/kotlin/DatesTest.kt @@ -0,0 +1,66 @@ +package bou.amine.apps.readerforselfossv2.repository + +import bou.amine.apps.readerforselfossv2.utils.toParsedDate +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toInstant +import kotlin.test.Test +import kotlin.test.assertEquals + +class DatesTest { + private val newVersionDateVariant = "2022-12-24T17:00:08+00" + private val newVersionDate = "2013-04-07T13:43:00+01:00" + private val newVersionDate2 = "2013-04-07T13:43:00-01:00" + private val oldVersionDate = "2013-05-07 13:46:00" + private val oldVersionDateVariant = "2021-03-21 10:32:00.000000" + + + @Test + fun new_version_date_should_be_parsed() { + val date = newVersionDate.toParsedDate() + val expected = + LocalDateTime(2013, 4, 7, 13, 43, 0, 0).toInstant(TimeZone.currentSystemDefault()) + .toEpochMilliseconds() + + assertEquals(expected, date) + } + @Test + fun new_version_date2_should_be_parsed() { + val date = newVersionDate2.toParsedDate() + val expected = + LocalDateTime(2013, 4, 7, 13, 43, 0, 0).toInstant(TimeZone.currentSystemDefault()) + .toEpochMilliseconds() + + assertEquals(expected, date) + } + + @Test + fun old_version_date_should_be_parsed() { + val date = oldVersionDate.toParsedDate() + val expected = + LocalDateTime(2013, 5, 7, 13, 46, 0, 0).toInstant(TimeZone.currentSystemDefault()) + .toEpochMilliseconds() + + assertEquals(expected, date) + } + + @Test + fun old_version_variant_date_should_be_parsed() { + val date = oldVersionDateVariant.toParsedDate() + val expected = + LocalDateTime(2021, 3, 21, 10, 32, 0, 0).toInstant(TimeZone.currentSystemDefault()) + .toEpochMilliseconds() + + assertEquals(expected, date) + } + + @Test + fun new_version_variant_date_should_be_parsed() { + val date = newVersionDateVariant.toParsedDate() + val expected = + LocalDateTime(2022, 12, 24, 17, 0, 8, 0).toInstant(TimeZone.currentSystemDefault()) + .toEpochMilliseconds() + + assertEquals(expected, date) + } +} diff --git a/shared/src/iosSimulatorArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.iosSimulatorArm64.kt b/shared/src/iosSimulatorArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.iosSimulatorArm64.kt new file mode 100644 index 0000000..ee78316 --- /dev/null +++ b/shared/src/iosSimulatorArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.iosSimulatorArm64.kt @@ -0,0 +1,9 @@ +package bou.amine.apps.readerforselfossv2.utils + +actual class DateUtils actual constructor() { + actual companion object { + actual fun parseRelativeDate(dateString: String): String { + TODO("Not yet implemented") + } + } +} \ No newline at end of file