refactor: date utils and all calls
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { httpClient } from './base/http-client';
|
||||
import { DailyCheckbox, DailyView, Task } from '@/lib/types';
|
||||
import { formatDateForAPI, parseDate } from '@/lib/date-utils';
|
||||
|
||||
// Types pour les réponses API (avec dates en string)
|
||||
interface ApiCheckbox {
|
||||
@@ -97,10 +98,7 @@ export class DailyClient {
|
||||
* Formate une date pour l'API (évite les décalages timezone)
|
||||
*/
|
||||
formatDateForAPI(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`; // YYYY-MM-DD
|
||||
return formatDateForAPI(date);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +107,9 @@ export class DailyClient {
|
||||
private transformCheckboxDates(checkbox: ApiCheckbox): DailyCheckbox {
|
||||
return {
|
||||
...checkbox,
|
||||
date: new Date(checkbox.date),
|
||||
createdAt: new Date(checkbox.createdAt),
|
||||
updatedAt: new Date(checkbox.updatedAt)
|
||||
date: parseDate(checkbox.date),
|
||||
createdAt: parseDate(checkbox.createdAt),
|
||||
updatedAt: parseDate(checkbox.updatedAt)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -120,7 +118,7 @@ export class DailyClient {
|
||||
*/
|
||||
private transformDailyViewDates(view: ApiDailyView): DailyView {
|
||||
return {
|
||||
date: new Date(view.date),
|
||||
date: parseDate(view.date),
|
||||
yesterday: view.yesterday.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb)),
|
||||
today: view.today.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user