Modern Apps git

← Modern-Apps.git

travel: date pickers gate on the traveller's local today, not UTC's

Commit
23864e20b82a192c5f0bac099a28d26d7bf390f0
Author
Vayun Mathur <[email protected]>
When
2026-11-30 22:18 UTC (5 days ago)
Parents
b1ef26a
The shared todayUtc() helper fed both search forms' picker
minDate and validity gates. West of UTC, every evening the UTC
date is already tomorrow locally, so tonight's departure or
check-in was disabled and Search stayed greyed out; east of UTC
the gate admitted yesterday. The range calendar even ringed the
device-local today while disabling that same cell.

todayLocal() (system default zone) replaces it, computed from a
pure todayIn(zone, instant) core. New deterministic tests pin
Denver evening, Tokyo morning, Kolkata half-hour rollover and a
UTC baseline. Itinerary times, booking polling, currency handling
and offline reads were audited and cleared. Verified:
:travel:testDevUnitTest 415 tests pass; lint errors are
pre-existing on untouched files.

Diff

travel/src/main/java/com/vayunmathur/travel/ui/DateField.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/ui/DateField.kt b/travel/src/main/java/com/vayunmathur/travel/ui/DateField.ktindex 92824e14eb..34279c64c8 100644--- a/travel/src/main/java/com/vayunmathur/travel/ui/DateField.kt+++ b/travel/src/main/java/com/vayunmathur/travel/ui/DateField.kt@@ -115,5 +115,13 @@ internal fun isoToUtcMillis(iso: String): Long? = internal fun utcMillisToIso(ms: Long): String =     Instant.fromEpochMilliseconds(ms).toLocalDateTime(TimeZone.UTC).date.toString() -/** Today in UTC as a [LocalDate], for clamping pickers to no-past-dates. */-fun todayUtc(): LocalDate = Clock.System.now().toLocalDateTime(TimeZone.UTC).date+/** The calendar date of [instant] in [zone] (pure, for tests). */+fun todayIn(zone: TimeZone, instant: Instant): LocalDate = instant.toLocalDateTime(zone).date++/**+ * Today in the device's local zone as a [LocalDate], for clamping pickers to+ * no-past-dates. Departure/check-in dates are calendar dates, so "today" is+ * the traveller's local date — not the UTC date, which is already tomorrow+ * in the evening west of UTC (and still yesterday in the morning east of it).+ */+fun todayLocal(): LocalDate = todayIn(TimeZone.currentSystemDefault(), Clock.System.now())
travel/src/main/java/com/vayunmathur/travel/ui/FlightSearchForm.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/ui/FlightSearchForm.kt b/travel/src/main/java/com/vayunmathur/travel/ui/FlightSearchForm.ktindex 2852ebc1b9..a66f81c7b4 100644--- a/travel/src/main/java/com/vayunmathur/travel/ui/FlightSearchForm.kt+++ b/travel/src/main/java/com/vayunmathur/travel/ui/FlightSearchForm.kt@@ -71,7 +71,7 @@ fun FlightSearchForm(     // (they own their editing text internally).     var swapNonce by remember { mutableIntStateOf(0) } -    val today = remember { todayUtc() }+    val today = remember { todayLocal() }     val departDate = remember(state.depart) { runCatching { LocalDate.parse(state.depart) }.getOrNull() }     val returnLocalDate = remember(state.returnDate) { runCatching { LocalDate.parse(state.returnDate) }.getOrNull() } 
travel/src/main/java/com/vayunmathur/travel/ui/StaySearchForm.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/ui/StaySearchForm.kt b/travel/src/main/java/com/vayunmathur/travel/ui/StaySearchForm.ktindex f71d83cd4c..075dfcf135 100644--- a/travel/src/main/java/com/vayunmathur/travel/ui/StaySearchForm.kt+++ b/travel/src/main/java/com/vayunmathur/travel/ui/StaySearchForm.kt@@ -44,7 +44,7 @@ fun StaySearchForm(     modifier: Modifier = Modifier,     onSearch: (place: String, checkIn: String, checkOut: String, rooms: Int, adults: Int, latitude: Double?, longitude: Double?) -> Unit, ) {-    val today = remember { todayUtc() }+    val today = remember { todayLocal() }     val checkInDate = remember(state.checkIn) { runCatching { LocalDate.parse(state.checkIn) }.getOrNull() }     val checkOutDate = remember(state.checkOut) { runCatching { LocalDate.parse(state.checkOut) }.getOrNull() } 
travel/src/test/java/com/vayunmathur/travel/pure/LocalTodayTest.kt
diff --git a/travel/src/test/java/com/vayunmathur/travel/pure/LocalTodayTest.kt b/travel/src/test/java/com/vayunmathur/travel/pure/LocalTodayTest.ktnew file mode 100644index 0000000000..4576d481dc--- /dev/null+++ b/travel/src/test/java/com/vayunmathur/travel/pure/LocalTodayTest.kt@@ -0,0 +1,57 @@+package com.vayunmathur.travel.pure++import com.vayunmathur.travel.ui.todayIn+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import kotlin.time.Instant+import kotlinx.datetime.LocalDate+import kotlinx.datetime.TimeZone++/**+ * Pins the "no past dates" gate: the search forms clamp departure /+ * check-in dates against the traveller's local today ([todayIn] behind+ * `todayLocal()`), not the UTC date. Fixed instants keep the host JVM+ * deterministic; the old UTC rule is asserted inline where it differs.+ */+class LocalTodayTest {++    @Test+    fun eveningWestOfUtcKeepsLocalToday() {+        // 2026-11-30 19:30 in Denver (MST, UTC-7) is already Dec 1 in UTC.+        val instant = Instant.parse("2026-12-01T02:30:00Z")+        val denver = TimeZone.of("America/Denver")+        assertEquals(LocalDate(2026, 11, 30), todayIn(denver, instant))+        // The old UTC gate used Dec 1, disabling today (Nov 30) in the picker+        // and failing `depart >= today`, so tonight's flight was unbookable.+        assertEquals(LocalDate(2026, 12, 1), todayIn(TimeZone.UTC, instant))+        assertTrue(LocalDate(2026, 11, 30) >= todayIn(denver, instant))+        assertFalse(LocalDate(2026, 11, 30) >= todayIn(TimeZone.UTC, instant))+    }++    @Test+    fun morningEastOfUtcUsesLocalToday() {+        // 2026-12-01 00:30 in Tokyo (UTC+9) is still Nov 30 in UTC; the UTC+        // gate let yesterday's (Nov 30) departure pass as "not past".+        val instant = Instant.parse("2026-11-30T15:30:00Z")+        val tokyo = TimeZone.of("Asia/Tokyo")+        assertEquals(LocalDate(2026, 12, 1), todayIn(tokyo, instant))+        assertEquals(LocalDate(2026, 11, 30), todayIn(TimeZone.UTC, instant))+        assertFalse(LocalDate(2026, 11, 30) >= todayIn(tokyo, instant))+    }++    @Test+    fun halfHourZoneRollsAtLocalMidnight() {+        // 19:00Z is 00:30 the next day in Kolkata (UTC+5:30).+        val instant = Instant.parse("2026-11-30T19:00:00Z")+        assertEquals(LocalDate(2026, 12, 1), todayIn(TimeZone.of("Asia/Kolkata"), instant))+        assertEquals(LocalDate(2026, 11, 30), todayIn(TimeZone.UTC, instant))+    }++    @Test+    fun utcZoneMatchesUtcDate() {+        val instant = Instant.parse("2026-12-01T02:30:00Z")+        assertEquals(LocalDate(2026, 12, 1), todayIn(TimeZone.UTC, instant))+    }+}