From 4a745f57e78e59fb0900e43409caa6a0099c5e24 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Mon, 6 Feb 2023 16:36:06 -0700 Subject: [PATCH] Fix date formatting on Transaction details Signed-off-by: William Brawner --- .../budget/ui/transaction/TransactionDetailsScreen.kt | 11 +++++++---- .../java/com/wbrawner/budget/ui/util/DatePicker.kt | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/wbrawner/budget/ui/transaction/TransactionDetailsScreen.kt b/android/src/main/java/com/wbrawner/budget/ui/transaction/TransactionDetailsScreen.kt index 1db9ee7..f2d5322 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/transaction/TransactionDetailsScreen.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/transaction/TransactionDetailsScreen.kt @@ -18,12 +18,11 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.wbrawner.budget.ui.TwigsScaffold import com.wbrawner.budget.ui.base.TwigsApp -import com.wbrawner.budget.ui.util.format +import com.wbrawner.budget.ui.util.formatWithTime import com.wbrawner.twigs.shared.Action import com.wbrawner.twigs.shared.Store import com.wbrawner.twigs.shared.budget.Budget @@ -96,9 +95,13 @@ fun TransactionDetails( text = transaction.title, style = MaterialTheme.typography.headlineMedium ) - Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { Text( - text = transaction.date.format(LocalContext.current), + text = transaction.date.formatWithTime(), style = MaterialTheme.typography.bodyMedium ) Text( diff --git a/android/src/main/java/com/wbrawner/budget/ui/util/DatePicker.kt b/android/src/main/java/com/wbrawner/budget/ui/util/DatePicker.kt index 52e9663..c323f8d 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/util/DatePicker.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/util/DatePicker.kt @@ -26,6 +26,7 @@ import kotlinx.datetime.TimeZone import kotlinx.datetime.atStartOfDayIn import kotlinx.datetime.toInstant import kotlinx.datetime.toLocalDateTime +import java.text.DateFormat.getDateTimeInstance @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -108,3 +109,5 @@ fun Instant.format(context: Context): String = this.toLocalDateTime(TimeZone.currentSystemDefault()).date.atStartOfDayIn(TimeZone.currentSystemDefault()) .toEpochMilliseconds() ) + +fun Instant.formatWithTime(): String = getDateTimeInstance().format(this.toEpochMilliseconds())