fix due date off-by-one west of UTC

all six reads now go through one helper, which also handles the ISO stamps Trello imports keep
This commit is contained in:
2026-11-16 19:15:30 +02:00
parent 26c66c5555
commit 44d7637034
6 changed files with 27 additions and 12 deletions
+2 -3
View File
@@ -1,6 +1,6 @@
import React, { useState, useRef, useEffect, useCallback } from "react";
import { Plus } from "lucide-react";
import { parse } from "date-fns";
import { parseDueDate } from "@/lib/due-date";
import { AnimatePresence, motion } from "framer-motion";
import { OverlayScrollbarsComponent, type OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
import { staggerContainer } from "@/lib/motion";
@@ -97,8 +97,7 @@ export function BoardView() {
if (filters.dueDate !== "all") {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
// dueDate is 'yyyy-MM-dd', which new Date() reads as UTC midnight
const due = card.dueDate ? parse(card.dueDate, "yyyy-MM-dd", now) : null;
const due = card.dueDate ? parseDueDate(card.dueDate) : null;
if (filters.dueDate === "none" && due != null) return false;
if (filters.dueDate === "overdue" && (!due || due >= today)) return false;
if (filters.dueDate === "today") {
+8 -6
View File
@@ -1,8 +1,9 @@
import { useState, useRef, useEffect } from "react";
import { createPortal } from "react-dom";
import { format, parse } from "date-fns";
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 { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import type { Card, Label, Priority } from "@/types/board";
@@ -26,10 +27,10 @@ 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());
// dueDate is 'yyyy-MM-dd', which new Date() reads as UTC midnight
const dueDay = parse(dueDate, "yyyy-MM-dd", now);
const diffDays = Math.ceil((dueDay.getTime() - today.getTime()) / (1000 * 60 * 60 * 24));
if (diffDays < 0) {
@@ -92,6 +93,7 @@ export function CardThumbnail({ card, boardLabels, columnId, onCardClick, isFocu
}, [isFocused]);
const hasDueDate = card.dueDate != null;
const dueDate = card.dueDate ? parseDueDate(card.dueDate) : null;
const dueDateStatus = getDueDateStatus(card.dueDate);
function handleClick() {
@@ -179,12 +181,12 @@ export function CardThumbnail({ card, boardLabels, columnId, onCardClick, isFocu
role="img"
/>
)}
{dueDateStatus && card.dueDate && (
{dueDateStatus && dueDate && (
<span
className={`font-mono text-xs rounded px-1 py-0.5 ${dueDateStatus.color} ${dueDateStatus.bgColor}`}
aria-label={`Due: ${format(new Date(card.dueDate), "MMM d")} - ${dueDateStatus.label}`}
aria-label={`Due: ${format(dueDate, "MMM d")} - ${dueDateStatus.label}`}
>
{format(new Date(card.dueDate), "MMM d")}
{format(dueDate, "MMM d")}
</span>
)}
{card.checklist.length > 0 && (
+2 -1
View File
@@ -5,6 +5,7 @@ import { LabelDots } from "@/components/board/LabelDots";
import { ChecklistBar } from "@/components/board/ChecklistBar";
import { format, isPast, isToday } from "date-fns";
import { springs } from "@/lib/motion";
import { parseDueDate } from "@/lib/due-date";
interface CardOverlayProps {
card: Card;
@@ -13,7 +14,7 @@ interface CardOverlayProps {
export function CardOverlay({ card, boardLabels }: CardOverlayProps) {
const hasDueDate = card.dueDate != null;
const dueDate = hasDueDate ? new Date(card.dueDate!) : null;
const dueDate = card.dueDate ? parseDueDate(card.dueDate) : null;
const overdue = dueDate != null && isPast(dueDate) && !isToday(dueDate);
const rotate = useMotionValue(0);
+2 -1
View File
@@ -2,6 +2,7 @@ import { format, formatDistanceToNow, isPast, isToday } from "date-fns";
import { X } from "lucide-react";
import { useBoardStore } from "@/stores/board-store";
import { CalendarPopover } from "@/components/card-detail/CalendarPopover";
import { parseDueDate } from "@/lib/due-date";
interface DueDatePickerProps {
cardId: string;
@@ -11,7 +12,7 @@ interface DueDatePickerProps {
export function DueDatePicker({ cardId, dueDate }: DueDatePickerProps) {
const updateCard = useBoardStore((s) => s.updateCard);
const dateObj = dueDate ? new Date(dueDate) : null;
const dateObj = dueDate ? parseDueDate(dueDate) : null;
const overdue = dateObj != null && isPast(dateObj) && !isToday(dateObj);
function handleSelect(date: Date) {
+10
View File
@@ -0,0 +1,10 @@
import { isValid, parse } from "date-fns";
// Due dates are stored as yyyy-MM-dd, but Trello imports keep their ISO stamp
export function parseDueDate(value: string): Date | null {
const local = parse(value, "yyyy-MM-dd", new Date());
if (isValid(local)) return local;
const fallback = new Date(value);
return isValid(fallback) ? fallback : null;
}
+3 -1
View File
@@ -3,6 +3,7 @@ import type { AppSettings, BoardSortOrder } from "@/types/settings";
import type { BoardMeta, ColumnWidth } from "@/types/board";
import { loadSettings, saveSettings, listBoards, ensureDataDirs, loadBoard } from "@/lib/storage";
import { isPermissionGranted, requestPermission, sendNotification } from "@tauri-apps/plugin-notification";
import { parseDueDate } from "@/lib/due-date";
export type View = { type: "board-list" } | { type: "board"; boardId: string };
@@ -111,7 +112,8 @@ export const useAppStore = create<AppState>((set, get) => ({
const board = await loadBoard(meta.id);
for (const card of Object.values(board.cards)) {
if (!card.dueDate) continue;
const due = new Date(card.dueDate);
const due = parseDueDate(card.dueDate);
if (!due) continue;
if (due.toDateString() === todayStr) dueToday++;
else if (due < today) overdue++;
}