From bc7780d494c85dbfce46bf0ad47d259de79dea5b Mon Sep 17 00:00:00 2001 From: hermes-explorigin Date: Sun, 16 Aug 2026 20:00:14 +0000 Subject: [PATCH] Fix 7-day forecast day labels shifted by UTC date parsing --- src/components/DailyForecast.svelte | 5 +++-- src/lib/dates.js | 13 +++++++++++++ src/lib/stores/notifications.svelte.js | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/lib/dates.js diff --git a/src/components/DailyForecast.svelte b/src/components/DailyForecast.svelte index 9b760b9..8a23a62 100644 --- a/src/components/DailyForecast.svelte +++ b/src/components/DailyForecast.svelte @@ -1,6 +1,7 @@ diff --git a/src/lib/dates.js b/src/lib/dates.js new file mode 100644 index 0000000..9807004 --- /dev/null +++ b/src/lib/dates.js @@ -0,0 +1,13 @@ +/** + * Date helpers for Open-Meteo strings. + * + * Open-Meteo returns calendar dates like "2026-08-19" (in the location's + * timezone). `new Date("2026-08-19")` parses that as UTC midnight, so in U.S. + * Central (UTC-5) it renders as the PREVIOUS weekday, shifting every day + * label one day back. Build the Date from its parts instead so it is a local + * calendar date with no offset/timezone shift. + */ +export function parseLocalDate(dateStr) { + const [y, m, d] = String(dateStr).split('-').map(Number) + return new Date(y, (m || 1) - 1, d || 1) +} diff --git a/src/lib/stores/notifications.svelte.js b/src/lib/stores/notifications.svelte.js index 984742f..aa13473 100644 --- a/src/lib/stores/notifications.svelte.js +++ b/src/lib/stores/notifications.svelte.js @@ -7,6 +7,7 @@ import { isSevereWeather } from '../api/weather-codes.js' import { app } from './app.svelte.js' import { saveSettings } from '../storage/db.js' +import { parseLocalDate } from '../dates.js' export class NotificationStore { /** @type {Array<{ id: string, type: string, severity: 'info'|'warning'|'danger', message: string, icon: string }>} */ @@ -66,7 +67,7 @@ export class NotificationStore { if (daily.time) { for (let i = 0; i < daily.time.length && i < 3; i++) { const day = daily.time[i] - const dateLabel = i === 0 ? 'Today' : i === 1 ? 'Tomorrow' : new Date(day).toLocaleDateString('en-US', { weekday: 'short' }) + const dateLabel = i === 0 ? 'Today' : i === 1 ? 'Tomorrow' : parseLocalDate(day).toLocaleDateString('en-US', { weekday: 'short' }) const precip = daily.precipitation_probability_max?.[i] || 0 if (precip >= t.precip) {