Modern Apps git

← Modern-Apps.git

maps: overnight opening hours now stay open past midnight

Commit
965f1aa1c674c5db40537f4c85f9ebc5541313f8
Author
Vayun Mathur <[email protected]>
When
2026-12-01 01:01 UTC (5 days ago)
Parents
2b13c0c
For a rule that names only its start day (Fr 22:00-02:00),
isOpen only consulted the queried day's rule, so at Saturday
01:00 โ€” inside Friday's interval until 02:00 โ€” the POI read
Closed. OSM assigns an interval to the day it starts; the
evaluator never looked at the previous day's wrapping
interval. The suite's overnight test used Mo-Su 22:00-02:00,
which masked it: Saturday's own copy of the rule matched.

isOpen now also accepts the previous day's rule when one of
its intervals spills past midnight and the time precedes its
end, and changeOnDay includes the spill end as a boundary so
nextStatusChangeTime returns Sat 02:00 instead of the
no-change sentinel. Weekly display is unchanged (Friday still
lists 22:00-02:00, as written). Three new tests cover the
tail, its composition with Saturday's own rule and the
no-restart/no-double-spill edges. POI search, saved places,
the navigation session and transit clocks were audited and
cleared. Verified: :maps:testDevUnitTest 945 tests pass;
lint errors are pre-existing on untouched files.

Diff

maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt b/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.ktindex dda48c975c..214d7b0b87 100644--- a/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt+++ b/maps/src/main/java/com/vayunmathur/maps/data/OpeningHours.kt@@ -175,8 +175,15 @@ class OpeningHours(val rawString: String) {     }      fun isOpen(dateTime: LocalDateTime): Boolean {-        val rule = rules.findLast { it.days.contains(dateTime.dayOfWeek) } ?: return false-        return rule.intervals.any { it.contains(dateTime.time) }+        val rule = rules.findLast { it.days.contains(dateTime.dayOfWeek) }+        if (rule != null && rule.intervals.any { it.contains(dateTime.time) }) return true+        // An overnight interval belongs to the day it starts on: `Fr 22:00-02:00`+        // is Friday's rule, but its tail runs into Saturday. Looking only at+        // today's rule closed every such place at midnight โ€” masked when the+        // interval was written `Mo-Su`, exposed as soon as it named one day.+        val previousDay = DayOfWeek.entries[(dateTime.dayOfWeek.ordinal + DAYS_PER_WEEK - 1) % DAYS_PER_WEEK]+        val previousRule = rules.findLast { it.days.contains(previousDay) } ?: return false+        return previousRule.intervals.any { it.spillsPastMidnight && dateTime.time < it.end }     }      /**@@ -205,9 +212,17 @@ class OpeningHours(val rawString: String) {         current: LocalDateTime,         currentlyOpen: Boolean,     ): LocalDateTime? {-        val rule = rules.findLast { it.days.contains(date.dayOfWeek) } ?: return null-        // Collect all relevant times for this day-        val changeTimes = rule.intervals.flatMap { listOf(it.start, it.end) }.distinct().sorted()+        val rule = rules.findLast { it.days.contains(date.dayOfWeek) }+        val previousDay = DayOfWeek.entries[(date.dayOfWeek.ordinal + DAYS_PER_WEEK - 1) % DAYS_PER_WEEK]+        val previousRule = rules.findLast { it.days.contains(previousDay) }+        // Collect all relevant times for this day, including the end of an+        // overnight interval that started yesterday (its start was yesterday's+        // boundary; only its end changes today's status).+        val changeTimes = (+            rule?.intervals.orEmpty().flatMap { listOf(it.start, it.end) } ++                previousRule?.intervals.orEmpty().filter { it.spillsPastMidnight }.map { it.end }+            ).distinct().sorted()+        if (changeTimes.isEmpty()) return null         for (time in changeTimes) {             val candidate = LocalDateTime(date, time)             if (candidate > current && isOpen(candidate) != currentlyOpen) {@@ -255,6 +270,9 @@ private data class TimeInterval(val start: LocalTime, val end: LocalTime) {      */     val isAllDay: Boolean get() = start == end +    /** An interval that runs past midnight into the next day (`22:00-02:00`). */+    val spillsPastMidnight: Boolean get() = !isAllDay && end < start+     fun contains(time: LocalTime): Boolean {         return when {             isAllDay -> true
maps/src/test/java/com/vayunmathur/maps/data/OpeningHoursTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/data/OpeningHoursTest.kt b/maps/src/test/java/com/vayunmathur/maps/data/OpeningHoursTest.ktindex 66199d9539..6add185619 100644--- a/maps/src/test/java/com/vayunmathur/maps/data/OpeningHoursTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/data/OpeningHoursTest.kt@@ -26,6 +26,9 @@ class OpeningHoursTest {     private fun wed(hour: Int, minute: Int = 0) =         LocalDateTime(2026, 8, 19, hour, minute) +    private fun fri(hour: Int, minute: Int = 0) =+        LocalDateTime(2026, 8, 21, hour, minute)+     private fun sat(hour: Int, minute: Int = 0) =         LocalDateTime(2026, 8, 22, hour, minute) @@ -70,6 +73,38 @@ class OpeningHoursTest {         assertFalse(hours.isOpen(sun(12)))     } +    /**+     * An overnight interval belongs to its start day, so the after-midnight+     * tail must survive on a day the rule never names. `Mo-Su 22:00-02:00`+     * masked this: Saturday's own rule also matched at 01:00.+     */+    @Test+    fun `an overnight interval stays open after midnight on the next day`() {+        val hours = OpeningHours.from("Fr 22:00-02:00")+        assertTrue(hours.isOpen(fri(23)), "open before midnight on Friday")+        assertTrue(hours.isOpen(sat(1)), "Friday's interval runs to 02:00 on Saturday")+        assertFalse(hours.isOpen(sat(2)), "closed at the interval's end")+        assertFalse(hours.isOpen(sat(12)), "no Saturday rule of its own")+        assertFalse(hours.isOpen(sat(23)), "the interval does not restart on Saturday")+        assertFalse(hours.isOpen(sun(1)), "and does not spill a second night")+    }++    /** Saturday's own hours compose with, rather than replace, Friday's tail. */+    @Test+    fun `an overnight tail composes with the next day's own rule`() {+        val hours = OpeningHours.from("Fr 22:00-02:00; Sa 09:00-17:00")+        assertTrue(hours.isOpen(sat(1)), "Friday's tail")+        assertFalse(hours.isOpen(sat(3)), "between the tail and Saturday's hours")+        assertTrue(hours.isOpen(sat(10)), "Saturday's own rule")+    }++    @Test+    fun `the next status change after midnight is the overnight interval's end`() {+        val hours = OpeningHours.from("Fr 22:00-02:00")+        assertEquals(LocalDateTime(2026, 8, 22, 2, 0), hours.nextStatusChangeTime(sat(1)))+        assertEquals(LocalDateTime(2026, 8, 22, 2, 0), hours.nextStatusChangeTime(fri(23)))+    }+     /** An interval that wraps midnight has to stay open on both sides of it. */     @Test     fun `an overnight interval spans midnight`() {