diff --git a/src/components/board/CardThumbnail.tsx b/src/components/board/CardThumbnail.tsx index c615563..f03dc1a 100644 --- a/src/components/board/CardThumbnail.tsx +++ b/src/components/board/CardThumbnail.tsx @@ -3,7 +3,7 @@ import { createPortal } from "react-dom"; import { format } from "date-fns"; import { motion, useReducedMotion, AnimatePresence } from "framer-motion"; import { fadeSlideUp, springs } from "@/lib/motion"; -import { parseDueDate } from "@/lib/due-date"; +import { dueDaysFromToday, parseDueDate } from "@/lib/due-date"; import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import type { Card, Label, Priority } from "@/types/board"; @@ -27,11 +27,9 @@ import { useBoardStore } from "@/stores/board-store"; function getDueDateStatus(dueDate: string | null): { color: string; bgColor: string; label: string } | null { if (!dueDate) return null; - const dueDay = parseDueDate(dueDate); - if (!dueDay) return null; - const now = new Date(); - const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); - const diffDays = Math.ceil((dueDay.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); + const due = parseDueDate(dueDate); + if (!due) return null; + const diffDays = dueDaysFromToday(due); if (diffDays < 0) { return { color: "text-pylon-danger", bgColor: "bg-pylon-danger/10", label: "Overdue" }; diff --git a/src/lib/due-date.ts b/src/lib/due-date.ts index aebffc2..b4ac2fe 100644 --- a/src/lib/due-date.ts +++ b/src/lib/due-date.ts @@ -8,3 +8,10 @@ export function parseDueDate(value: string): Date | null { const fallback = new Date(value); return isValid(fallback) ? fallback : null; } + +// whole days between local midnights; round because DST makes the gap 23 or 25 hours +export function dueDaysFromToday(due: Date, now: Date = new Date()): number { + const dueDay = new Date(due.getFullYear(), due.getMonth(), due.getDate()); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + return Math.round((dueDay.getTime() - today.getTime()) / 86_400_000); +}