fooddelivery: format order dates and times via DateString
- Commit
7c4104c4415873c94fafd857a2247af6dac6e306- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-10 19:05 UTC (3 months ago)
- Parents
563f5da
Diff
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.ktindex 97025e1f92..feed24b786 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrderTrackingScreen.kt@@ -63,8 +63,8 @@ import com.vayunmathur.fooddelivery.api.BitesApi import com.vayunmathur.fooddelivery.data.Order import com.vayunmathur.fooddelivery.data.OrderStage import kotlinx.coroutines.delay-import java.text.SimpleDateFormat-import java.util.Date+import kotlin.time.Instant+import com.vayunmathur.library.ui.DateString import kotlin.math.max import kotlin.math.min @@ -266,7 +266,7 @@ private fun StageHeader(order: Order) { Spacer(Modifier.height(4.dp)) Text( if (minutes > 0) stringResource(R.string.eta_minutes, minutes,- SimpleDateFormat("h:mm a", locale).format(Date(eta)))+ DateString.time(Instant.fromEpochMilliseconds(eta), is24Hour = false, locale = locale)) else stringResource(R.string.eta_any_moment), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.primary,
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.ktindex 68003e3418..744a87b722 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/ui/OrdersScreen.kt@@ -52,10 +52,13 @@ import com.vayunmathur.library.ui.TextButton import com.vayunmathur.fooddelivery.api.BitesApi import com.vayunmathur.fooddelivery.data.FeedbackRequest import com.vayunmathur.fooddelivery.data.Order-import java.text.SimpleDateFormat-import kotlinx.coroutines.launch import java.util.Locale-import java.util.TimeZone+import kotlinx.coroutines.launch+import kotlinx.datetime.LocalDateTime+import kotlinx.datetime.TimeZone+import kotlinx.datetime.toInstant+import kotlinx.datetime.toLocalDateTime+import com.vayunmathur.library.ui.DateString @Composable fun OrdersScreen(onTrackOrder: (Int) -> Unit = {}) {@@ -162,11 +165,11 @@ fun OrdersScreen(onTrackOrder: (Int) -> Unit = {}) { private fun formatDate(iso: String?): String { if (iso.isNullOrEmpty()) return "" return try {- val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)- parser.timeZone = TimeZone.getTimeZone("UTC")- val date = parser.parse(iso.substringBefore(".").substringBefore("Z")) ?: return iso- val formatter = SimpleDateFormat("MMM d, yyyy, h:mm a", Locale.US)- formatter.format(date)+ val ldt = LocalDateTime.parse(iso.substringBefore(".").substringBefore("Z"))+ .toInstant(TimeZone.UTC)+ .toLocalDateTime(TimeZone.currentSystemDefault())+ DateString.monthDayYear(ldt.date, Locale.US) + ", " ++ DateString.time(ldt.time, is24Hour = false, locale = Locale.US) } catch (_: Exception) { iso } }