refactor: enhance date handling across components

- Replaced direct date manipulations with utility functions for consistency and readability.
- Updated date formatting in `DailyCalendar`, `RecentTasks`, `CompletionRateChart`, and other components to use `formatDateShort` and `formatDateForDisplay`.
- Improved date parsing in `JiraLogs`, `JiraSchedulerConfig`, and `BackupSettingsPageClient` to ensure proper handling of date strings.
- Streamlined date initialization in `useDaily` and `DailyService` to utilize `getToday` and `getYesterday` for better clarity.
This commit is contained in:
Julien Froidefond
2025-09-21 12:02:06 +02:00
parent 557cdebc13
commit c3c1d24fa2
15 changed files with 39 additions and 46 deletions

View File

@@ -4,7 +4,7 @@ import { useState, useEffect, useCallback, useTransition } from 'react';
import { DailyCheckbox } from '@/lib/types';
import { tasksClient } from '@/clients/tasks-client';
import { Button } from '@/components/ui/Button';
import { formatDateSmart } from '@/lib/date-utils';
import { formatDateSmart, parseDate } from '@/lib/date-utils';
import { Input } from '@/components/ui/Input';
import { addTodoToTask, toggleCheckbox } from '@/actions/daily';
@@ -42,7 +42,7 @@ export function RelatedTodos({ taskId }: RelatedTodosProps) {
startTransition(async () => {
try {
// Si une date est spécifiée, l'utiliser, sinon undefined (aujourd'hui par défaut)
const targetDate = newTodoDate ? new Date(newTodoDate) : undefined;
const targetDate = newTodoDate ? parseDate(newTodoDate) : undefined;
const result = await addTodoToTask(taskId, newTodoText, targetDate);
@@ -79,7 +79,7 @@ export function RelatedTodos({ taskId }: RelatedTodosProps) {
const formatDate = (date: Date | string) => {
try {
const dateObj = typeof date === 'string' ? new Date(date) : date;
const dateObj = typeof date === 'string' ? parseDate(date) : date;
if (isNaN(dateObj.getTime())) {
return 'Date invalide';
}