From 7ef555e377d46b583f6b499e63dcda210550445b Mon Sep 17 00:00:00 2001 From: atsunatsu Date: Mon, 14 Sep 2026 14:13:16 +0800 Subject: [PATCH] fix(time): respect UTC toggle for AOS filter window and sunrise/sunset day anchor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PassesViewModel: use the DEVICE timezone for the natural-day anchor in findTodaySunRiseSet instead of the display timezone. With UTC enabled the anchor was UTC midnight = 08:00 local for UTC+8 stations, when the sun is already up — tripping the white-night guard and rendering '--:--'. - SatelliteRepo.isAosInRange: follow the UTC display toggle so the pass time window is interpreted in UTC when UTC mode is on. Previously the list showed UTC times while the filter silently used local time, off by the timezone offset (8h for China). --- .../look4sat/core/data/repository/SatelliteRepo.kt | 11 ++++++++++- .../look4sat/feature/passes/PassesViewModel.kt | 9 ++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt index bdbea85b..b9a27927 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SatelliteRepo.kt @@ -175,7 +175,16 @@ class SatelliteRepo( aosEndMinute: Int, invertAosTimeWindow: Boolean ): Boolean { - val offsetMillis = TimeZone.getDefault().getOffset(aosTime).toLong() + // Follow the UTC display toggle: with UTC enabled the window is interpreted + // in UTC, otherwise in the device's local timezone. Otherwise the pass list + // shows UTC times while the filter silently uses local time — the two + // disagree by the timezone offset (e.g. 8h for China). + val tz = if (settingsRepo.otherSettings.value.stateOfUtc) { + TimeZone.getTimeZone("UTC") + } else { + TimeZone.getDefault() + } + val offsetMillis = tz.getOffset(aosTime).toLong() val localMillis = Math.floorMod(aosTime + offsetMillis, 24L * 60L * 60L * 1000L) val aosMinute = (localMillis / 60_000L).toInt() val inRange = if (aosStartMinute <= aosEndMinute) { diff --git a/feature/passes/src/main/java/com/rtbishop/look4sat/feature/passes/PassesViewModel.kt b/feature/passes/src/main/java/com/rtbishop/look4sat/feature/passes/PassesViewModel.kt index e7468801..14f410d3 100644 --- a/feature/passes/src/main/java/com/rtbishop/look4sat/feature/passes/PassesViewModel.kt +++ b/feature/passes/src/main/java/com/rtbishop/look4sat/feature/passes/PassesViewModel.kt @@ -175,9 +175,12 @@ class PassesViewModel( val sdfDate = dateFormat(tz) val sdfTime = SimpleDateFormat("HH:mm", Locale.getDefault()).also { it.timeZone = tz } val result = LinkedHashMap>() - // DeepSpace group always shows today's sun times + // DeepSpace group always shows today's sun times. + // The natural-day anchor is the DEVICE timezone, not the display timezone: + // UTC midnight is 08:00 local for UTC+8 stations, when the sun is already + // up — that would trip the white-night guard and render "--:--". if (passes.any { it.isDeepSpace }) { - val riseSet = findTodaySunRiseSet(stationPos, startOfDayMillis(System.currentTimeMillis(), tz)) + val riseSet = findTodaySunRiseSet(stationPos, startOfDayMillis(System.currentTimeMillis(), TimeZone.getDefault())) val rise = if (riseSet.riseTimeMillis > 0) sdfTime.format(Date(riseSet.riseTimeMillis)) else "--:--" val set = if (riseSet.setTimeMillis > 0) sdfTime.format(Date(riseSet.setTimeMillis)) else "--:--" result["DeepSpace (period >225min)"] = rise to set @@ -186,7 +189,7 @@ class PassesViewModel( if (pass.isDeepSpace) continue val label = sdfDate.format(Date(pass.aosTime)) if (label in result) continue - val riseSet = findTodaySunRiseSet(stationPos, startOfDayMillis(pass.aosTime, tz)) + val riseSet = findTodaySunRiseSet(stationPos, startOfDayMillis(pass.aosTime, TimeZone.getDefault())) val rise = if (riseSet.riseTimeMillis > 0) sdfTime.format(Date(riseSet.riseTimeMillis)) else "--:--" val set = if (riseSet.setTimeMillis > 0) sdfTime.format(Date(riseSet.setTimeMillis)) else "--:--" result[label] = rise to set