From 8f40c4ea26b7fa7133790ea0b4efe99e8708b6f1 Mon Sep 17 00:00:00 2001 From: unuunn <62112339+unuunn@users.noreply.github.com> Date: Tue, 8 Jul 2025 06:20:27 +0000 Subject: [PATCH] fix: dayjs - ISO 8601 compatible DATE_TIME_FORMAT Date parsing does not work without the CustomParseFormat plugin It is better to use ISO 8601 (or compatible) as the default format. --- web/src/components/DateTimeInput.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web/src/components/DateTimeInput.tsx b/web/src/components/DateTimeInput.tsx index a1901be05..07f343b75 100644 --- a/web/src/components/DateTimeInput.tsx +++ b/web/src/components/DateTimeInput.tsx @@ -2,7 +2,8 @@ import dayjs from "dayjs"; import toast from "react-hot-toast"; import { cn } from "@/lib/utils"; -const DATE_TIME_FORMAT = "M/D/YYYY, H:mm:ss"; +// ISO 8601 (almost) +const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss"; // convert Date to datetime string. const formatDate = (date: Date): string => { @@ -23,12 +24,25 @@ const DateTimeInput: React.FC = ({ value, onChange }) => { onBlur={(e) => { const inputValue = e.target.value; if (inputValue) { - const date = dayjs(inputValue, DATE_TIME_FORMAT, true).toDate(); + const date = dayjs(inputValue).toDate(); // Check if the date is valid. if (!isNaN(date.getTime())) { onChange(date); } else { - toast.error("Invalid datetime format. Use format: 12/31/2023, 23:59:59"); + toast.error( + + Invalid datetime.
+ Use a{" "} + + Date.parse() + + -compatible format,
+ e.g., 2023-12-31 23:59:59
+ or 31/12/2023, 23:59:59. +
+ ); e.target.value = formatDate(value); } }