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:
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useRef, useEffect, useCallback } from "react";
|
import React, { useState, useRef, useEffect, useCallback } from "react";
|
||||||
import { Plus } from "lucide-react";
|
import { Plus } from "lucide-react";
|
||||||
import { parse } from "date-fns";
|
import { parseDueDate } from "@/lib/due-date";
|
||||||
import { AnimatePresence, motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
import { OverlayScrollbarsComponent, type OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
|
import { OverlayScrollbarsComponent, type OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
|
||||||
import { staggerContainer } from "@/lib/motion";
|
import { staggerContainer } from "@/lib/motion";
|
||||||
@@ -97,8 +97,7 @@ export function BoardView() {
|
|||||||
if (filters.dueDate !== "all") {
|
if (filters.dueDate !== "all") {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
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 ? parseDueDate(card.dueDate) : null;
|
||||||
const due = card.dueDate ? parse(card.dueDate, "yyyy-MM-dd", now) : null;
|
|
||||||
if (filters.dueDate === "none" && due != null) return false;
|
if (filters.dueDate === "none" && due != null) return false;
|
||||||
if (filters.dueDate === "overdue" && (!due || due >= today)) return false;
|
if (filters.dueDate === "overdue" && (!due || due >= today)) return false;
|
||||||
if (filters.dueDate === "today") {
|
if (filters.dueDate === "today") {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useState, useRef, useEffect } from "react";
|
import { useState, useRef, useEffect } from "react";
|
||||||
import { createPortal } from "react-dom";
|
import { createPortal } from "react-dom";
|
||||||
import { format, parse } 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 { 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";
|
||||||
@@ -26,10 +27,10 @@ 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);
|
||||||
|
if (!dueDay) return null;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
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));
|
const diffDays = Math.ceil((dueDay.getTime() - today.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
if (diffDays < 0) {
|
if (diffDays < 0) {
|
||||||
@@ -92,6 +93,7 @@ export function CardThumbnail({ card, boardLabels, columnId, onCardClick, isFocu
|
|||||||
}, [isFocused]);
|
}, [isFocused]);
|
||||||
|
|
||||||
const hasDueDate = card.dueDate != null;
|
const hasDueDate = card.dueDate != null;
|
||||||
|
const dueDate = card.dueDate ? parseDueDate(card.dueDate) : null;
|
||||||
const dueDateStatus = getDueDateStatus(card.dueDate);
|
const dueDateStatus = getDueDateStatus(card.dueDate);
|
||||||
|
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
@@ -179,12 +181,12 @@ export function CardThumbnail({ card, boardLabels, columnId, onCardClick, isFocu
|
|||||||
role="img"
|
role="img"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{dueDateStatus && card.dueDate && (
|
{dueDateStatus && dueDate && (
|
||||||
<span
|
<span
|
||||||
className={`font-mono text-xs rounded px-1 py-0.5 ${dueDateStatus.color} ${dueDateStatus.bgColor}`}
|
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>
|
</span>
|
||||||
)}
|
)}
|
||||||
{card.checklist.length > 0 && (
|
{card.checklist.length > 0 && (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { LabelDots } from "@/components/board/LabelDots";
|
|||||||
import { ChecklistBar } from "@/components/board/ChecklistBar";
|
import { ChecklistBar } from "@/components/board/ChecklistBar";
|
||||||
import { format, isPast, isToday } from "date-fns";
|
import { format, isPast, isToday } from "date-fns";
|
||||||
import { springs } from "@/lib/motion";
|
import { springs } from "@/lib/motion";
|
||||||
|
import { parseDueDate } from "@/lib/due-date";
|
||||||
|
|
||||||
interface CardOverlayProps {
|
interface CardOverlayProps {
|
||||||
card: Card;
|
card: Card;
|
||||||
@@ -13,7 +14,7 @@ interface CardOverlayProps {
|
|||||||
|
|
||||||
export function CardOverlay({ card, boardLabels }: CardOverlayProps) {
|
export function CardOverlay({ card, boardLabels }: CardOverlayProps) {
|
||||||
const hasDueDate = card.dueDate != null;
|
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 overdue = dueDate != null && isPast(dueDate) && !isToday(dueDate);
|
||||||
|
|
||||||
const rotate = useMotionValue(0);
|
const rotate = useMotionValue(0);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { format, formatDistanceToNow, isPast, isToday } from "date-fns";
|
|||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { useBoardStore } from "@/stores/board-store";
|
import { useBoardStore } from "@/stores/board-store";
|
||||||
import { CalendarPopover } from "@/components/card-detail/CalendarPopover";
|
import { CalendarPopover } from "@/components/card-detail/CalendarPopover";
|
||||||
|
import { parseDueDate } from "@/lib/due-date";
|
||||||
|
|
||||||
interface DueDatePickerProps {
|
interface DueDatePickerProps {
|
||||||
cardId: string;
|
cardId: string;
|
||||||
@@ -11,7 +12,7 @@ interface DueDatePickerProps {
|
|||||||
export function DueDatePicker({ cardId, dueDate }: DueDatePickerProps) {
|
export function DueDatePicker({ cardId, dueDate }: DueDatePickerProps) {
|
||||||
const updateCard = useBoardStore((s) => s.updateCard);
|
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);
|
const overdue = dateObj != null && isPast(dateObj) && !isToday(dateObj);
|
||||||
|
|
||||||
function handleSelect(date: Date) {
|
function handleSelect(date: Date) {
|
||||||
|
|||||||
@@ -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,6 +3,7 @@ import type { AppSettings, BoardSortOrder } from "@/types/settings";
|
|||||||
import type { BoardMeta, ColumnWidth } from "@/types/board";
|
import type { BoardMeta, ColumnWidth } from "@/types/board";
|
||||||
import { loadSettings, saveSettings, listBoards, ensureDataDirs, loadBoard } from "@/lib/storage";
|
import { loadSettings, saveSettings, listBoards, ensureDataDirs, loadBoard } from "@/lib/storage";
|
||||||
import { isPermissionGranted, requestPermission, sendNotification } from "@tauri-apps/plugin-notification";
|
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 };
|
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);
|
const board = await loadBoard(meta.id);
|
||||||
for (const card of Object.values(board.cards)) {
|
for (const card of Object.values(board.cards)) {
|
||||||
if (!card.dueDate) continue;
|
if (!card.dueDate) continue;
|
||||||
const due = new Date(card.dueDate);
|
const due = parseDueDate(card.dueDate);
|
||||||
|
if (!due) continue;
|
||||||
if (due.toDateString() === todayStr) dueToday++;
|
if (due.toDateString() === todayStr) dueToday++;
|
||||||
else if (due < today) overdue++;
|
else if (due < today) overdue++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user