refactor: unify date handling with utility functions

- Replaced direct date manipulations with utility functions like `getToday`, `parseDate`, and `createDateFromParts` across various components and services for consistency.
- Updated date initialization in `JiraAnalyticsService`, `BackupService`, and `DailyClient` to improve clarity and maintainability.
- Enhanced date parsing in forms and API routes to ensure proper handling of date strings.
This commit is contained in:
Julien Froidefond
2025-09-21 13:04:34 +02:00
parent c3c1d24fa2
commit 4ba6ba2c0b
23 changed files with 117 additions and 68 deletions

View File

@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import { dailyService } from '@/services/daily';
import { getToday, parseDate, isValidAPIDate } from '@/lib/date-utils';
import { getToday, parseDate, isValidAPIDate, createDateFromParts } from '@/lib/date-utils';
/**
* API route pour récupérer la vue daily (hier + aujourd'hui)
@@ -79,9 +79,9 @@ export async function POST(request: Request) {
if (typeof body.date === 'string') {
// Si c'est une string YYYY-MM-DD, créer une date locale
const [year, month, day] = body.date.split('-').map(Number);
date = new Date(year, month - 1, day); // month est 0-indexé
date = createDateFromParts(year, month, day);
} else {
date = new Date(body.date);
date = parseDate(body.date);
}
if (isNaN(date.getTime())) {