feat: enhance date parsing to support month-only formats and normalize URLs to prevent duplicates

This commit is contained in:
2026-02-14 17:55:38 +01:00
parent ba99b79d35
commit 60055dddac
3 changed files with 62 additions and 7 deletions

View File

@@ -31,8 +31,37 @@ const DATE_RANGE_OPTIONS = [
const parseDate = (value) => {
if (!value) return null;
const date = new Date(value);
return Number.isNaN(date.getTime()) ? null : date;
const toDate = (input) => {
const date = new Date(input);
return Number.isNaN(date.getTime()) ? null : date;
};
let date = value instanceof Date ? value : null;
if (!date && (typeof value === "number" || typeof value === "string")) {
date = toDate(value);
if (!date && typeof value === "string") {
const trimmed = value.trim();
const dayMatch = trimmed.match(/^([0-9]{1,2})[\/\-]([0-9]{1,2})[\/\-]([0-9]{2,4})$/);
if (dayMatch) {
const [, day, month, year] = dayMatch;
const normalizedYear = year.length === 2 ? `20${year}` : year;
date = toDate(`${normalizedYear.padStart(4, "0")}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`);
} else {
const monthMatch = trimmed.match(/^([0-9]{1,2})[\/\-]([0-9]{2,4})$/);
if (monthMatch) {
const [, month, year] = monthMatch;
const normalizedYear = year.length === 2 ? `20${year}` : year;
date = toDate(`${normalizedYear.padStart(4, "0")}-${month.padStart(2, "0")}-01`);
}
}
}
}
return date;
};
const matchesDateRange = (annonce, range) => {