fix: use robust date parsing utility to handle varying n8n date formats
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m26s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m26s
This commit is contained in:
@@ -52,3 +52,20 @@ export const fetchData = async (): Promise<OrderData[]> => {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const parseOrderDate = (dateStr: string): Date => {
|
||||
if (!dateStr) return new Date(0);
|
||||
if (dateStr.includes('T')) return new Date(dateStr);
|
||||
const parts = dateStr.split(/[-/]/);
|
||||
if (parts.length === 3) {
|
||||
if (parts[0].length === 4) {
|
||||
// YYYY-MM-DD
|
||||
return new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]));
|
||||
} else {
|
||||
// DD-MM-YYYY
|
||||
return new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));
|
||||
}
|
||||
}
|
||||
const fallback = new Date(dateStr);
|
||||
return isNaN(fallback.getTime()) ? new Date(0) : fallback;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user