fix(payments,dates): improve duplicate payment detection and Jalali date parsing
This commit is contained in:
+23
-3
@@ -70,12 +70,32 @@ const parseImportDate = (raw) => {
|
||||
if (raw instanceof Date) {
|
||||
return Number.isNaN(raw.getTime()) ? null : raw;
|
||||
}
|
||||
const text = String(raw).trim();
|
||||
const text = toEnglishDigits(raw).trim();
|
||||
if (!text) return null;
|
||||
const gregorian = text.match(/^(\d{4}-\d{2}-\d{2})/);
|
||||
if (gregorian) return new Date(`${gregorian[1]}T00:00:00.000Z`);
|
||||
|
||||
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(text)) {
|
||||
const d = new Date(text);
|
||||
return Number.isNaN(d.getTime()) ? null : d;
|
||||
}
|
||||
|
||||
const dateMatch = text.match(/^(\d{3,4})[./\-](\d{1,2})[./\-](\d{1,2})/);
|
||||
if (dateMatch) {
|
||||
const year = Number(dateMatch[1]);
|
||||
const month = Number(dateMatch[2]);
|
||||
const day = Number(dateMatch[3]);
|
||||
if (year >= 1200 && year <= 1599) {
|
||||
const gDate = jalaliToGregorian(year, month, day);
|
||||
if (gDate) return new Date(`${gDate}T00:00:00.000Z`);
|
||||
} else if (year >= 1900 && year <= 2200) {
|
||||
const mStr = String(month).padStart(2, '0');
|
||||
const dStr = String(day).padStart(2, '0');
|
||||
return new Date(`${year}-${mStr}-${dStr}T00:00:00.000Z`);
|
||||
}
|
||||
}
|
||||
|
||||
const jalali = parseJalaliDate(text);
|
||||
if (jalali) return new Date(`${jalali}T00:00:00.000Z`);
|
||||
|
||||
const date = new Date(text);
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user