From ca9e8bca981cbce4a957bd54e7f3296a4e0f25ae Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 18 Jun 2024 15:15:37 +0900 Subject: [PATCH] Fixing accessDate string not being parsed correctly if it only consisted of yyyy-MM-dd and had no time component. Closes #135 Upping versionCode to 76 --- .../org/zotero/android/helpers/formatter/DateTimeFormat.kt | 5 +++++ .../java/org/zotero/android/sync/ItemDetailDataCreator.kt | 7 ++++++- buildSrc/src/main/kotlin/BuildConfig.kt | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/zotero/android/helpers/formatter/DateTimeFormat.kt b/app/src/main/java/org/zotero/android/helpers/formatter/DateTimeFormat.kt index f12a4d90..db9068af 100644 --- a/app/src/main/java/org/zotero/android/helpers/formatter/DateTimeFormat.kt +++ b/app/src/main/java/org/zotero/android/helpers/formatter/DateTimeFormat.kt @@ -25,6 +25,11 @@ val iso8601DateFormatV2: SimpleDateFormat timeZone = TimeZone.getTimeZone("UTC") } +val fullDateWithDashesUtc: SimpleDateFormat + get() = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).apply { + timeZone = TimeZone.getTimeZone("UTC") + } + val deadlineTimeFormat: SimpleDateFormat get() = SimpleDateFormat("EEEE MMM d, h:mm a", Locale.getDefault()) diff --git a/app/src/main/java/org/zotero/android/sync/ItemDetailDataCreator.kt b/app/src/main/java/org/zotero/android/sync/ItemDetailDataCreator.kt index 5570981a..c1bc4171 100644 --- a/app/src/main/java/org/zotero/android/sync/ItemDetailDataCreator.kt +++ b/app/src/main/java/org/zotero/android/sync/ItemDetailDataCreator.kt @@ -8,6 +8,7 @@ import org.zotero.android.database.objects.RItem import org.zotero.android.database.requests.items import org.zotero.android.files.FileStore import org.zotero.android.helpers.formatter.dateFormatItemDetails +import org.zotero.android.helpers.formatter.fullDateWithDashesUtc import org.zotero.android.helpers.formatter.iso8601DateFormatV2 import org.zotero.android.helpers.formatter.sqlFormat import org.zotero.android.screens.itemdetails.data.ItemDetailCreator @@ -260,7 +261,11 @@ object ItemDetailDataCreator { if (key == FieldKeys.Item.accessDate) { if (value.isNotEmpty()) { - val date = iso8601DateFormatV2.parse(value)!! + val date: Date = try { + iso8601DateFormatV2.parse(value)!! + } catch (e: Exception) { + fullDateWithDashesUtc.parse(value)!! + } additionalInfo = mapOf( ItemDetailField.AdditionalInfoKey.formattedDate to dateFormatItemDetails().format(date), ItemDetailField.AdditionalInfoKey.formattedEditDate to sqlFormat.format(date)) diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 82e9a3d9..53153745 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -4,7 +4,7 @@ object BuildConfig { const val compileSdkVersion = 34 const val targetSdk = 33 - val versionCode = 75 // Must be updated on every build + val versionCode = 76 // Must be updated on every build val version = Version( major = 1, minor = 0,