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:
@@ -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())) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Metadata } from 'next';
|
||||
import { DailyPageClient } from './DailyPageClient';
|
||||
import { dailyService } from '@/services/daily';
|
||||
import { getToday } from '@/lib/date-utils';
|
||||
|
||||
// Force dynamic rendering (no static generation)
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -12,7 +13,7 @@ export const metadata: Metadata = {
|
||||
|
||||
export default async function DailyPage() {
|
||||
// Récupérer les données côté serveur
|
||||
const today = new Date();
|
||||
const today = getToday();
|
||||
|
||||
try {
|
||||
const [dailyView, dailyDates] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user