count due days by calendar day, not elapsed hours

a date two hours in the past read as due soon, and DST days were a day out
This commit is contained in:
2026-11-16 19:18:37 +02:00
parent 44d7637034
commit 867f7e5e37
2 changed files with 11 additions and 6 deletions
+4 -6
View File
@@ -3,7 +3,7 @@ import { createPortal } from "react-dom";
import { format } from "date-fns"; import { format } from "date-fns";
import { motion, useReducedMotion, AnimatePresence } from "framer-motion"; import { motion, useReducedMotion, AnimatePresence } from "framer-motion";
import { fadeSlideUp, springs } from "@/lib/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 { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities"; import { CSS } from "@dnd-kit/utilities";
import type { Card, Label, Priority } from "@/types/board"; 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 { function getDueDateStatus(dueDate: string | null): { color: string; bgColor: string; label: string } | null {
if (!dueDate) return null; if (!dueDate) return null;
const dueDay = parseDueDate(dueDate); const due = parseDueDate(dueDate);
if (!dueDay) return null; if (!due) return null;
const now = new Date(); const diffDays = dueDaysFromToday(due);
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const diffDays = Math.ceil((dueDay.getTime() - today.getTime()) / (1000 * 60 * 60 * 24));
if (diffDays < 0) { if (diffDays < 0) {
return { color: "text-pylon-danger", bgColor: "bg-pylon-danger/10", label: "Overdue" }; return { color: "text-pylon-danger", bgColor: "bg-pylon-danger/10", label: "Overdue" };
+7
View File
@@ -8,3 +8,10 @@ export function parseDueDate(value: string): Date | null {
const fallback = new Date(value); const fallback = new Date(value);
return isValid(fallback) ? fallback : null; 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);
}