fix: use UTC date components to prevent timezone off-by-one in due dates

This commit is contained in:
2026-01-28 19:09:05 +00:00
parent f9145f6a46
commit a20a5c5054
2 changed files with 10 additions and 7 deletions

View File

@@ -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 {