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:
@@ -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" };
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user