From a991642157379d8c0ccc6296b5e3798a98db0924 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Thu, 30 Jul 2026 09:39:20 +0100 Subject: [PATCH] fix: show only differing days in scheduled hours change section Replace unreactive @const with for the changed-days filter. Normalize PostgreSQL microsecond times before comparing (TIME::text produces '17:00:00.000000' but staged hours are '17:00'). Change header text to 'These opening hours will change from' when fewer than 7 days differ. --- .../components/layout/BusinessHours.svelte | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/layout/BusinessHours.svelte b/frontend/src/lib/components/layout/BusinessHours.svelte index 9f12327..55e117c 100644 --- a/frontend/src/lib/components/layout/BusinessHours.svelte +++ b/frontend/src/lib/components/layout/BusinessHours.svelte @@ -47,6 +47,21 @@ hours: Array<{ weekday: number; startTime: string; endTime: string; isOpen: boolean }>; }; + let scheduledChangeDays = $derived( + scheduledChange + ? scheduledChange.hours.filter((h) => { + const current = defaultHours.find((dh) => dh.weekday === h.weekday); + if (!current) return true; + if (h.isOpen !== current.isOpen) return true; + // Normalize time strings before comparing — the current hours + // may include microsecond precision ("17:00:00.000000") from + // PostgreSQL's ::text cast, while staged hours are plain "17:00". + const norm = (t: string) => t.replace(/\.\d+$/, '').replace(/^(\d{2}:\d{2}).*$/, '$1'); + return norm(h.startTime) !== norm(current.startTime) || norm(h.endTime) !== norm(current.endTime); + }) + : [] + ); + let loading = $state(true); let error = $state(false); @@ -290,10 +305,10 @@ {/if} - {#if scheduledChange} + {#if scheduledChange && scheduledChangeDays.length > 0}

- Opening hours will change from + {scheduledChangeDays.length === 7 ? 'Opening hours will change from' : 'These opening hours will change from'} {new Date(scheduledChange.effective_date + 'T00:00:00').toLocaleDateString('en-GB', { day: 'numeric', month: 'short', @@ -301,7 +316,7 @@ timeZone: 'UTC' })}

- {#each scheduledChange.hours as h} + {#each scheduledChangeDays as h (h.weekday)}
{['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][