From ea42d478cf05d00a49cd7fa787a922cc9d3e7a4a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:11:32 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20time=20not=20displayed=20correctly=20on?= =?UTF-8?q?=20Samsung=20devices=20[WPB-10598]=20=F0=9F=8D=92=20(#3361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mohamad Jaara Co-authored-by: Yamil Medina --- .../wire/android/util/DateAndTimeParsers.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/util/DateAndTimeParsers.kt b/app/src/main/kotlin/com/wire/android/util/DateAndTimeParsers.kt index 45ef8b2eb5b..32fee5383eb 100644 --- a/app/src/main/kotlin/com/wire/android/util/DateAndTimeParsers.kt +++ b/app/src/main/kotlin/com/wire/android/util/DateAndTimeParsers.kt @@ -71,8 +71,12 @@ class DateAndTimeParsers private constructor() { companion object { private val dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("UTC")) - private val longDateShortTimeFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT) - .withZone(ZoneId.systemDefault()).withLocale(Locale.getDefault()) + + private val longDateShortTimeFormat = + java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.LONG, java.text.DateFormat.SHORT, Locale.getDefault()).apply { + this.timeZone = java.util.TimeZone.getDefault() + } + private val mediumDateTimeFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM) .withZone(ZoneId.systemDefault()).withLocale(Locale.getDefault()) private val fullDateShortTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.SHORT) @@ -83,8 +87,9 @@ class DateAndTimeParsers private constructor() { DateTimeFormatter.ofPattern("MMM dd yyyy, hh:mm a", Locale.getDefault()).withZone(ZoneId.systemDefault()) private val mediumOnlyDateTimeFormat = DateTimeFormatter.ofPattern("MMM dd, yyyy", Locale.getDefault()).withZone(ZoneId.systemDefault()) - private val messageTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) - .withZone(ZoneId.systemDefault()).withLocale(Locale.getDefault()) + private val messageTimeFormatter = java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT, Locale.getDefault()).apply { + this.timeZone = java.util.TimeZone.getDefault() + } @Deprecated("Date String parsing is discouraged and will be removed soon for direct Instant/DateTime versions") fun serverDate(stringDate: String): Date? { @@ -98,7 +103,7 @@ class DateAndTimeParsers private constructor() { @Deprecated("Date String parsing is discouraged and will be removed soon for direct Instant/DateTime versions") fun deviceDateTimeFormat(stringDate: String): String? = try { - stringDate.serverDate()?.let { longDateShortTimeFormat.format(it.toInstant()) } + longDateShortTimeFormat.format(Date.from(java.time.Instant.parse(stringDate))) } catch (e: Exception) { null } @@ -126,9 +131,11 @@ class DateAndTimeParsers private constructor() { fun toMediumOnlyDateTime(date: Date): String = mediumOnlyDateTimeFormat.format(date.toInstant()) @Deprecated("Date String parsing is discouraged and will be removed soon for direct Instant/DateTime versions") - fun uiMessageDateTime(stringDate: String): String? = stringDate - .serverDate()?.let { serverDate -> - messageTimeFormatter.format(serverDate.toInstant()) + fun uiMessageDateTime(stringDate: String): String? = + try { + messageTimeFormatter.format(Date.from(java.time.Instant.parse(stringDate))) + } catch (e: Exception) { + null } } }