diff --git a/assets/js/weather_map_hook.ts b/assets/js/weather_map_hook.ts index 8b41484a..9999ac16 100644 --- a/assets/js/weather_map_hook.ts +++ b/assets/js/weather_map_hook.ts @@ -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` } })