diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivityDialogs.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivityDialogs.kt index e00b00b3754..5c85033f8b5 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivityDialogs.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivityDialogs.kt @@ -43,7 +43,7 @@ import com.wire.android.ui.joinConversation.JoinConversationViaCodeState import com.wire.android.ui.joinConversation.JoinConversationViaDeepLinkDialog import com.wire.android.ui.joinConversation.JoinConversationViaInviteLinkError import com.wire.android.ui.theme.WireTheme -import com.wire.android.util.formatMediumDateTime +import com.wire.android.util.deviceDateTimeFormat import com.wire.android.util.ui.PreviewMultipleThemes import com.wire.android.util.ui.UIText import com.wire.kalium.logic.configuration.server.ServerConfig @@ -319,7 +319,7 @@ fun NewClientDialog( val devicesList = data.clientsInfo.map { stringResource( R.string.new_device_dialog_message_defice_info, - it.date.formatMediumDateTime() ?: "", + it.date.deviceDateTimeFormat() ?: "", it.deviceInfo.asString() ) }.joinToString("") diff --git a/app/src/main/kotlin/com/wire/android/ui/authentication/devices/DeviceItem.kt b/app/src/main/kotlin/com/wire/android/ui/authentication/devices/DeviceItem.kt index 486c28eec2a..2b19ebb5c43 100644 --- a/app/src/main/kotlin/com/wire/android/ui/authentication/devices/DeviceItem.kt +++ b/app/src/main/kotlin/com/wire/android/ui/authentication/devices/DeviceItem.kt @@ -64,7 +64,7 @@ import com.wire.android.ui.theme.wireDimensions import com.wire.android.ui.theme.wireTypography import com.wire.android.util.extension.formatAsFingerPrint import com.wire.android.util.extension.formatAsString -import com.wire.android.util.formatMediumDateTime +import com.wire.android.util.deviceDateTimeFormat import com.wire.android.util.ui.PreviewMultipleThemes import com.wire.android.util.ui.UIText @@ -227,14 +227,14 @@ private fun DeviceItemTexts( stringResource( R.string.remove_device_id_and_time_label_active_label, device.clientId.formatAsString(), - device.registrationTime.formatMediumDateTime() ?: "", + device.registrationTime.deviceDateTimeFormat() ?: "", device.lastActiveDescription() ?: "" ) } else { stringResource( R.string.remove_device_id_and_time_label, device.clientId.formatAsString(), - device.registrationTime.formatMediumDateTime() ?: "" + device.registrationTime.deviceDateTimeFormat() ?: "" ) } } else { diff --git a/app/src/main/kotlin/com/wire/android/ui/authentication/devices/remove/RemoveDeviceDialog.kt b/app/src/main/kotlin/com/wire/android/ui/authentication/devices/remove/RemoveDeviceDialog.kt index 817ec16122b..bcd7afae6c4 100644 --- a/app/src/main/kotlin/com/wire/android/ui/authentication/devices/remove/RemoveDeviceDialog.kt +++ b/app/src/main/kotlin/com/wire/android/ui/authentication/devices/remove/RemoveDeviceDialog.kt @@ -41,7 +41,7 @@ import com.wire.android.ui.common.button.WireButtonState import com.wire.android.ui.common.textfield.WirePasswordTextField import com.wire.android.ui.common.textfield.WireTextFieldState import com.wire.android.ui.theme.wireDimensions -import com.wire.android.util.formatMediumDateTime +import com.wire.android.util.deviceDateTimeFormat @OptIn(ExperimentalComposeUiApi::class) @Composable @@ -63,7 +63,7 @@ fun RemoveDeviceDialog( stringResource( R.string.remove_device_id_and_time_label, state.device.clientId.value, - state.device.registrationTime?.formatMediumDateTime() ?: "" + state.device.registrationTime?.deviceDateTimeFormat() ?: "" ), onDismiss = onDialogDismissHideKeyboard, dismissButtonProperties = WireDialogButtonProperties( diff --git a/app/src/main/kotlin/com/wire/android/ui/settings/devices/DeviceDetailsScreen.kt b/app/src/main/kotlin/com/wire/android/ui/settings/devices/DeviceDetailsScreen.kt index ed2de9da14b..31f87c3dd7c 100644 --- a/app/src/main/kotlin/com/wire/android/ui/settings/devices/DeviceDetailsScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/settings/devices/DeviceDetailsScreen.kt @@ -86,7 +86,7 @@ import com.wire.android.util.CustomTabsHelper import com.wire.android.util.dialogErrorStrings import com.wire.android.util.extension.formatAsFingerPrint import com.wire.android.util.extension.formatAsString -import com.wire.android.util.formatMediumDateTime +import com.wire.android.util.deviceDateTimeFormat import com.wire.android.util.ui.UIText import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.conversation.ClientId @@ -216,7 +216,7 @@ fun DeviceDetailsContent( Divider(color = MaterialTheme.wireColorScheme.background) } - state.device.registrationTime?.formatMediumDateTime()?.let { + state.device.registrationTime?.deviceDateTimeFormat()?.let { item { DeviceDetailSectionContent( stringResource(id = R.string.label_client_added_time), diff --git a/app/src/main/kotlin/com/wire/android/util/DateTimeUtil.kt b/app/src/main/kotlin/com/wire/android/util/DateTimeUtil.kt index a642e6635b7..b719ed1005a 100644 --- a/app/src/main/kotlin/com/wire/android/util/DateTimeUtil.kt +++ b/app/src/main/kotlin/com/wire/android/util/DateTimeUtil.kt @@ -34,6 +34,8 @@ private val serverDateTimeFormat = SimpleDateFormat( ).apply { timeZone = TimeZone.getTimeZone("UTC") } private val mediumDateTimeFormat = DateFormat .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM) +private val longDateShortTimeFormat = DateFormat + .getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT) private val mediumOnlyDateTimeFormat = DateFormat .getDateInstance(DateFormat.MEDIUM) private val messageTimeFormatter = DateFormat @@ -61,6 +63,13 @@ fun String.formatMediumDateTime(): String? = null } +fun String.deviceDateTimeFormat(): String? = + try { + this.serverDate()?.let { longDateShortTimeFormat.format(it) } + } catch (e: ParseException) { + null + } + fun String.formatFullDateShortTime(): String? = try { this.serverDate()?.let { fullDateShortTimeFormatter.format(it) } diff --git a/app/src/test/kotlin/com/wire/android/util/DateTimeUtilKtTest.kt b/app/src/test/kotlin/com/wire/android/util/DateTimeUtilKtTest.kt index 79e7ad4c0e1..17c9bfd0108 100644 --- a/app/src/test/kotlin/com/wire/android/util/DateTimeUtilKtTest.kt +++ b/app/src/test/kotlin/com/wire/android/util/DateTimeUtilKtTest.kt @@ -25,10 +25,16 @@ class DateTimeUtilKtTest { @Test fun `given a invalid date, when performing a transformation, then return null`() { - val result = "NOT_VALID".formatMediumDateTime() + val result = "NOT_VALID".deviceDateTimeFormat() assertEquals(null, result) } + @Test + fun `given a valid date, when performing a transformation for device, then return with medium format`() { + val result = "2022-03-24T18:02:30.360Z".deviceDateTimeFormat() + assertEquals("March 24, 2022, 6:02 PM", result) + } + @Test fun `given a valid date, when performing a transformation, then return with medium format`() { val result = "2022-03-24T18:02:30.360Z".formatMediumDateTime() diff --git a/kalium b/kalium index 072542fc5c8..f972e7fda4e 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit 072542fc5c84a3a4fd26d675a2cee16489163ae5 +Subproject commit f972e7fda4ecb0ab1c72992b5d009cefeb1b834b