From d069f1147a1a1ccbb3f20928c5f6b4769c2f2c2a Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Mon, 31 Aug 2026 11:33:01 +0000 Subject: [PATCH] Drop very-early-morning slots from the +1/+2 day 3-hourly cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was showing every 3-hourly point the provider returns (8/day, including ~1am/~4am). Now filters to hour >= 6 London-local for both providers, leaving 6 daytime-through-evening slots per day — currently 7/10/13/16/ 19/22 on Met Office's BST-aligned feed. Threshold rather than a hardcoded hour set so it keeps working once the clocks change to GMT and Met Office's fixed UTC cadence shifts by an hour locally. Co-Authored-By: Claude Sonnet 5 --- backend/src/lib/weather-fetch.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/src/lib/weather-fetch.js b/backend/src/lib/weather-fetch.js index 349e522..862c36f 100644 --- a/backend/src/lib/weather-fetch.js +++ b/backend/src/lib/weather-fetch.js @@ -42,6 +42,14 @@ function londonDateKey(isoTime) { function londonHour(isoTime) { return parseInt(new Date(isoTime).toLocaleString('en-GB', { timeZone: 'Europe/London', hour: '2-digit', hour12: false })) } +// The 3-hourly tier (tomorrow/day-after "Coming up" cards) drops the very early +// morning slots nobody's checking the display for. A threshold rather than an +// exact hour set — Met Office's feed is a fixed UTC-aligned 3-hour cadence, so +// its London-local hours shift by 1 across the BST/GMT change (right now, BST, +// that's 1/4/7/10/13/16/19/22; in winter it's 0/3/6/9/12/15/18/21). ">= 6" drops +// the same two earliest slots either way instead of matching zero points once +// the clocks change. +const THREE_HOURLY_MIN_HOUR = 6 // Pure date math, not derived from any provider response — "tomorrow"/"day after" // are always just today+1/+2 regardless of source, which is what lets each tier // below be fetched (and fall back) fully independently of the others. @@ -100,7 +108,7 @@ async function fetchMetOfficeHourly(lat, lon, apiKey) { async function fetchMetOfficeThreeHourly(lat, lon, apiKey, dayKeys) { const series = await fetchMetOfficeTimestep('three-hourly', lat, lon, apiKey) - const dayRows = series.filter(p => dayKeys.includes(londonDateKey(p.time))) + const dayRows = series.filter(p => dayKeys.includes(londonDateKey(p.time)) && londonHour(p.time) >= THREE_HOURLY_MIN_HOUR) const points = dayRows .map(p => ({ resolution: '3hourly', @@ -208,7 +216,7 @@ function openMeteoHourlyPoints(hourlyRows) { } function openMeteoThreeHourlyPoints(hourlyRows, dayKeys) { return hourlyRows - .filter(r => dayKeys.includes(r.dateKey) && r.hour % 3 === 0) + .filter(r => dayKeys.includes(r.dateKey) && r.hour % 3 === 0 && r.hour >= THREE_HOURLY_MIN_HOUR) .map(r => ({ resolution: '3hourly', ts: r.time,