From fc6c59bc107f1295520860cd7d2a9515e8f1df85 Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Thu, 7 May 2026 15:45:22 +0200 Subject: [PATCH] fix(deadline-banner): count calendar days, not 24h windows daysLeft used Math.ceil(ms/24h) which counted partial 24h windows: 30h before a midnight event tomorrow showed "Noch 2 Tage" instead of "Morgen". Compare midnight-to-midnight day-keys instead, same approach as CalendarBlock relativeDays(). Also adds data-block="DeadlineBanner" identifier. Co-Authored-By: Claude Opus 4.7 --- .../blocks/DeadlineBannerBlock.svelte | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/components/blocks/DeadlineBannerBlock.svelte b/src/lib/components/blocks/DeadlineBannerBlock.svelte index bf2b5b8..a0478cc 100644 --- a/src/lib/components/blocks/DeadlineBannerBlock.svelte +++ b/src/lib/components/blocks/DeadlineBannerBlock.svelte @@ -61,11 +61,20 @@ }); }); + /** Kalendertage zwischen heute und Ziel — über Mitternacht-zu- + * Mitternacht-Diff, nicht roh per ms. Sonst zählt z. B. 30 h vor + * Termin als „2 Tage" obwohl der Termin morgen ist. */ const daysLeft = $derived.by(() => { if (!dateObj) return null; - const ms = dateObj.getTime() - Date.now(); - if (ms < 0) return null; - return Math.ceil(ms / (1000 * 60 * 60 * 24)); + const today = new Date(); + today.setHours(0, 0, 0, 0); + const target = new Date(dateObj); + target.setHours(0, 0, 0, 0); + const diffDays = Math.round( + (target.getTime() - today.getTime()) / (1000 * 60 * 60 * 24), + ); + if (diffDays < 0) return null; + return diffDays; }); const countdownStr = $derived.by(() => { @@ -103,7 +112,7 @@ {#if hasContent && !dismissed}