summaryrefslogtreecommitdiffhomepage
path: root/android/lib
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2025-08-19 13:57:15 +0200
committerKalle Lindström <karl.lindstrom@mullvad.net>2025-08-19 16:56:31 +0200
commit85793eacb60fa5f5c3c4e207f62278b70a774b12 (patch)
treee2034aa204cf50e3493c6d89ad56f161ffe28b13 /android/lib
parent6b0a55f459fa564aad851f7b99982714e999b3ac (diff)
downloadmullvadvpn-85793eacb60fa5f5c3c4e207f62278b70a774b12.tar.xz
mullvadvpn-85793eacb60fa5f5c3c4e207f62278b70a774b12.zip
Catch exception in toExpiryDateString()
Diffstat (limited to 'android/lib')
-rw-r--r--android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt12
1 files changed, 11 insertions, 1 deletions
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt
index 74fe9d6ba0..9aa1ae30a1 100644
--- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt
+++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt
@@ -1,5 +1,7 @@
package net.mullvad.mullvadvpn.lib.common.util
+import co.touchlab.kermit.Logger
+import java.time.DateTimeException
import java.time.Duration
import java.time.Instant
import java.time.ZonedDateTime
@@ -9,7 +11,15 @@ import java.time.format.FormatStyle
fun ZonedDateTime.formatDate(): String = DateTimeFormatter.ISO_LOCAL_DATE.format(this)
fun ZonedDateTime.toExpiryDateString(): String =
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(this)
+ try {
+ DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(this)
+ } catch (e: DateTimeException) {
+ // This should normally not happen, but we have seen some crashes in the play console
+ // where this exception is thrown, so fall back to ISO_LOCAL_DATE_TIME.
+ // See: droid-2142
+ Logger.e("Error formatting date with default locale: $e")
+ DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(this)
+ }
fun ZonedDateTime.millisFromNow(): Long = Duration.between(ZonedDateTime.now(), this).toMillis()