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 { httpClient } from './base/http-client';
|
||||
import { DailyCheckbox, DailyView, Task } from '@/lib/types';
|
||||
import { formatDateForAPI, parseDate } from '@/lib/date-utils';
|
||||
import { formatDateForAPI, parseDate, getToday, addDays, subtractDays } from '@/lib/date-utils';
|
||||
|
||||
// Types pour les réponses API (avec dates en string)
|
||||
interface ApiCheckbox {
|
||||
@@ -74,7 +74,7 @@ export class DailyClient {
|
||||
|
||||
const result = await httpClient.get<ApiHistoryItem[]>(`/daily?${params}`);
|
||||
return result.map(item => ({
|
||||
date: new Date(item.date),
|
||||
date: parseDate(item.date),
|
||||
checkboxes: item.checkboxes.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb))
|
||||
}));
|
||||
}
|
||||
@@ -128,16 +128,19 @@ export class DailyClient {
|
||||
* Récupère la vue daily d'une date relative (hier, aujourd'hui, demain)
|
||||
*/
|
||||
async getDailyViewByRelativeDate(relative: 'yesterday' | 'today' | 'tomorrow'): Promise<DailyView> {
|
||||
const date = new Date();
|
||||
let date: Date;
|
||||
|
||||
switch (relative) {
|
||||
case 'yesterday':
|
||||
date.setDate(date.getDate() - 1);
|
||||
date = subtractDays(getToday(), 1);
|
||||
break;
|
||||
case 'tomorrow':
|
||||
date.setDate(date.getDate() + 1);
|
||||
date = addDays(getToday(), 1);
|
||||
break;
|
||||
case 'today':
|
||||
default:
|
||||
date = getToday();
|
||||
break;
|
||||
// 'today' ne change rien
|
||||
}
|
||||
|
||||
return this.getDailyView(date);
|
||||
|
||||
Reference in New Issue
Block a user