feat: enhance date handling in TaskBasicFields and date-utils

- Integrated `ensureDate` and `formatDateForDateTimeInput` in `TaskBasicFields` for improved due date management.
- Updated `date-utils` functions to accept both `Date` and `string` types, ensuring robust date validation and parsing.
- Added `ensureDate` utility to handle various date inputs, improving error handling and consistency across date-related functions.
This commit is contained in:
Julien Froidefond
2025-09-24 13:53:18 +02:00
parent 75aa60cb83
commit 167f90369b
2 changed files with 88 additions and 17 deletions

View File

@@ -3,6 +3,7 @@
import { Input } from '@/components/ui/Input';
import { TaskPriority, TaskStatus } from '@/lib/types';
import { getAllStatuses, getAllPriorities } from '@/lib/status-config';
import { ensureDate, formatDateForDateTimeInput } from '@/lib/date-utils';
interface TaskBasicFieldsProps {
title: string;
@@ -109,7 +110,10 @@ export function TaskBasicFields({
<Input
label="Date d'échéance"
type="datetime-local"
value={dueDate ? new Date(dueDate.getTime() - dueDate.getTimezoneOffset() * 60000).toISOString().slice(0, 16) : ''}
value={(() => {
const date = ensureDate(dueDate);
return date ? formatDateForDateTimeInput(date) : '';
})()}
onChange={(e) => onDueDateChange(e.target.value ? new Date(e.target.value) : undefined)}
disabled={loading}
/>