From a20a5c5054bc5e8ea11d83e6c1a11a33ebdaec3b Mon Sep 17 00:00:00 2001 From: Hammer Date: Wed, 28 Jan 2026 19:09:05 +0000 Subject: [PATCH] fix: use UTC date components to prevent timezone off-by-one in due dates --- dist/index.html | 2 +- src/lib/utils.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dist/index.html b/dist/index.html index c43abbb8..40e9d2e6 100644 --- a/dist/index.html +++ b/dist/index.html @@ -6,7 +6,7 @@ Todo App - + diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 9d7756f4..6b8674df 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -8,12 +8,13 @@ export function cn(...inputs: ClassValue[]) { export function formatDate(date: string | Date | undefined): string { if (!date) return ''; + // Parse as UTC to avoid timezone shift (due dates are date-only values stored as midnight UTC) const d = new Date(date); const now = new Date(); const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); - const taskDate = new Date(d.getFullYear(), d.getMonth(), d.getDate()); + const taskDate = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()); if (taskDate.getTime() === today.getTime()) { return 'Today'; @@ -32,23 +33,25 @@ export function formatDate(date: string | Date | undefined): string { const weekFromNow = new Date(today); weekFromNow.setDate(weekFromNow.getDate() + 7); if (taskDate > today && taskDate < weekFromNow) { - return d.toLocaleDateString('en-US', { weekday: 'long' }); + return taskDate.toLocaleDateString('en-US', { weekday: 'long' }); } // Same year - if (d.getFullYear() === now.getFullYear()) { - return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }); + if (taskDate.getFullYear() === now.getFullYear()) { + return taskDate.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }); } - return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); + return taskDate.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); } export function isOverdue(date: string | Date | undefined): boolean { if (!date) return false; + // Parse as UTC to avoid timezone shift const d = new Date(date); + const taskDate = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()); const today = new Date(); today.setHours(0, 0, 0, 0); - return d < today; + return taskDate < today; } export function getPriorityColor(priority: string): string {