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:
parent
236108d433
commit
92c6ee349f
1 changed files with 7 additions and 3 deletions
|
|
@ -734,18 +734,22 @@ export const WeatherMap: WeatherMapHook = {
|
||||||
const dt = new Date(time)
|
const dt = new Date(time)
|
||||||
const isSelected = time === this.selectedTime
|
const isSelected = time === this.selectedTime
|
||||||
const isPast = dt.getTime() < now.getTime() - 1800000
|
const isPast = dt.getTime() < now.getTime() - 1800000
|
||||||
const offsetH = Math.round((dt.getTime() - now.getTime()) / 3600000)
|
return { time, dt, isSelected, isPast, offsetH: 0, label: "" }
|
||||||
return { time, dt, isSelected, isPast, offsetH, label: "" }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const closestIdx = items.reduce((best, item, i) =>
|
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)
|
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) => {
|
items.forEach((t, i) => {
|
||||||
|
const diff = Math.round((t.dt.getTime() - anchorMs) / 3600000)
|
||||||
|
t.offsetH = diff
|
||||||
if (i === closestIdx) {
|
if (i === closestIdx) {
|
||||||
t.label = "Now"
|
t.label = "Now"
|
||||||
} else {
|
} else {
|
||||||
const diff = t.offsetH
|
|
||||||
t.label = diff > 0 ? `+${diff}h` : `${diff}h`
|
t.label = diff > 0 ? `+${diff}h` : `${diff}h`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue