diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/DateExtensions.kt | 12 |
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() |
