fix(weather): anchor timeline offsets to the Now slot, not wall-clock

Same bug as the propagation map had in 9db9e6a. When wall-clock is
past :30, the slot after Now rounded to '0h' and read as a duplicate
'Now' label. Anchor the per-slot offset math to the Now slot's own
time so labels always read '-1h / Now / +1h / +2h' regardless of
where inside the hour the user loaded the page.
This commit is contained in:
Graham McIntire 2026-04-19 17:51:49 -05:00
parent 236108d433
commit 92c6ee349f
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -734,18 +734,22 @@ export const WeatherMap: WeatherMapHook = {
const dt = new Date(time)
const isSelected = time === this.selectedTime
const isPast = dt.getTime() < now.getTime() - 1800000
const offsetH = Math.round((dt.getTime() - now.getTime()) / 3600000)
return { time, dt, isSelected, isPast, offsetH, label: "" }
return { time, dt, isSelected, isPast, offsetH: 0, label: "" }
})
const closestIdx = items.reduce((best, item, i) =>
Math.abs(item.dt.getTime() - now.getTime()) < Math.abs(items[best].dt.getTime() - now.getTime()) ? i : best, 0)
// Label offsets relative to the "Now" slot, not wall-clock. If we
// round from wall-clock, the hour after "Now" rounds to "0h" when
// the clock is past the half-hour, which reads as a second "now".
const anchorMs = items[closestIdx].dt.getTime()
items.forEach((t, i) => {
const diff = Math.round((t.dt.getTime() - anchorMs) / 3600000)
t.offsetH = diff
if (i === closestIdx) {
t.label = "Now"
} else {
const diff = t.offsetH
t.label = diff > 0 ? `+${diff}h` : `${diff}h`
}
})