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

This commit is contained in:
Cauê Faleiros
2026-05-06 09:58:10 -03:00
parent 4ffe97ede8
commit 940b2113cc
6 changed files with 36 additions and 11 deletions

View File

@@ -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;
};