fix: normalize bd leader history date params

This commit is contained in:
170-carry 2026-04-29 11:04:05 +08:00
parent 607a244c0a
commit ff759a9898
2 changed files with 97 additions and 8 deletions

View File

@ -168,6 +168,6 @@
<div class="toast" id="toast" role="status" aria-live="polite" hidden></div>
</div>
<script src="./script.js?v=20260429-0135" defer></script>
<script src="./script.js?v=20260429-0315" defer></script>
</body>
</html>

View File

@ -705,14 +705,103 @@
replaceChildren(list, items.map(createHistoryRow));
}
const digitMaps = [
["\u0660", "0"], ["\u0661", "1"], ["\u0662", "2"], ["\u0663", "3"], ["\u0664", "4"], ["\u0665", "5"], ["\u0666", "6"], ["\u0667", "7"], ["\u0668", "8"], ["\u0669", "9"],
["\u06f0", "0"], ["\u06f1", "1"], ["\u06f2", "2"], ["\u06f3", "3"], ["\u06f4", "4"], ["\u06f5", "5"], ["\u06f6", "6"], ["\u06f7", "7"], ["\u06f8", "8"], ["\u06f9", "9"],
["\u09e6", "0"], ["\u09e7", "1"], ["\u09e8", "2"], ["\u09e9", "3"], ["\u09ea", "4"], ["\u09eb", "5"], ["\u09ec", "6"], ["\u09ed", "7"], ["\u09ee", "8"], ["\u09ef", "9"]
];
const monthNames = new Map(Object.entries({
january: 1, jan: 1, "يناير": 1, "كانون الثاني": 1, ocak: 1, "জানুয়ারি": 1,
february: 2, feb: 2, "فبراير": 2, "شباط": 2, subat: 2, "şubat": 2, "ফেব্রুয়ারি": 2,
march: 3, mar: 3, "مارس": 3, "آذار": 3, mart: 3, "মার্চ": 3,
april: 4, apr: 4, "أبريل": 4, "ابريل": 4, "نيسان": 4, nisan: 4, "এপ্রিল": 4,
may: 5, "مايو": 5, "أيار": 5, mayis: 5, "mayıs": 5, "মে": 5,
june: 6, jun: 6, "يونيو": 6, "حزيران": 6, haziran: 6, "জুন": 6,
july: 7, jul: 7, "يوليو": 7, "تموز": 7, temmuz: 7, "জুলাই": 7,
august: 8, aug: 8, "أغسطس": 8, "اغسطس": 8, "آب": 8, agustos: 8, "ağustos": 8, "আগস্ট": 8,
september: 9, sep: 9, "سبتمبر": 9, "أيلول": 9, eylul: 9, "eylül": 9, "সেপ্টেম্বর": 9,
october: 10, oct: 10, "أكتوبر": 10, "اكتوبر": 10, "تشرين الأول": 10, ekim: 10, "অক্টোবর": 10,
november: 11, nov: 11, "نوفمبر": 11, "تشرين الثاني": 11, kasim: 11, "kasım": 11, "নভেম্বর": 11,
december: 12, dec: 12, "ديسمبر": 12, "كانون الأول": 12, aralik: 12, "aralık": 12, "ডিসেম্বর": 12
}));
function pad2(value) {
return String(value).padStart(2, "0");
}
function formatBillBelong(year, month, day, time) {
const monthNumber = Number(month);
const dayNumber = Number(day);
if (monthNumber < 1 || monthNumber > 12 || dayNumber < 1 || dayNumber > 31) return "";
return `${year}-${pad2(monthNumber)}-${pad2(dayNumber)}T${time}`;
}
function normalizeDateText(value) {
return digitMaps.reduce((textValue, [from, to]) => textValue.split(from).join(to), String(value || ""))
.replace(/&(?:rlm|lrm);/gi, "")
.replace(/&nbsp;/gi, " ")
.replace(/[\u061c\u200e\u200f]/g, "")
.replace(/[،]/g, ",")
.replace(/\s+/g, " ")
.trim();
}
function normalizeTime(value, markerText = "") {
const match = String(value || "").match(/(\d{1,2}):(\d{2})(?::(\d{2}))?/);
if (!match) return "00:00:00";
let hour = Number(match[1]);
const marker = markerText.toLowerCase();
const isPm = /\bpm\b|مساء|(?:^|\s)م(?:\s|$)/.test(marker);
const isAm = /\bam\b|صباح|(?:^|\s)ص(?:\s|$)/.test(marker);
if (isPm && hour < 12) hour += 12;
if (isAm && hour === 12) hour = 0;
return `${pad2(hour)}:${match[2]}:${match[3] || "00"}`;
}
function normalizeBillBelong(value) {
const text = String(value || "").trim();
if (!text) return "";
const iso = text.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/);
if (iso) return `${iso[1]}-${iso[2]}-${iso[3]}T${iso[4] || "00"}:${iso[5] || "00"}:${iso[6] || "00"}`;
const compact = text.match(/^(\d{4})(\d{2})(\d{2})(?:(\d{2})(\d{2})(\d{2})?)?$/);
if (compact) return `${compact[1]}-${compact[2]}-${compact[3]}T${compact[4] || "00"}:${compact[5] || "00"}:${compact[6] || "00"}`;
return text;
const textValue = normalizeDateText(value);
if (!textValue) return "";
const isoMatch = textValue.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/);
if (isoMatch) {
return formatBillBelong(isoMatch[1], isoMatch[2], isoMatch[3], `${isoMatch[4] || "00"}:${isoMatch[5] || "00"}:${isoMatch[6] || "00"}`);
}
const compactDateTime = textValue.match(/^(\d{4})(\d{2})(\d{2})(?:\D?(\d{2})(\d{2})(\d{2})?)?$/);
if (compactDateTime) {
return formatBillBelong(compactDateTime[1], compactDateTime[2], compactDateTime[3], `${compactDateTime[4] || "00"}:${compactDateTime[5] || "00"}:${compactDateTime[6] || "00"}`);
}
const numericDate = textValue.match(/\b(?:(\d{4})\s*[./-]\s*(\d{1,2})\s*[./-]\s*(\d{1,2})|(\d{1,2})\s*[./-]\s*(\d{1,2})\s*[./-]\s*(\d{4}))\b/);
if (numericDate) {
const time = normalizeTime(textValue, textValue);
if (numericDate[1]) return formatBillBelong(numericDate[1], numericDate[2], numericDate[3], time);
const first = Number(numericDate[4]);
const second = Number(numericDate[5]);
const month = first > 12 && second <= 12 ? second : first;
const day = second > 12 && first <= 12 ? second : first > 12 ? first : second;
return formatBillBelong(numericDate[6], month, day, time);
}
const lowerText = textValue.toLowerCase();
let month = 0;
for (const [name, valueForMonth] of monthNames) {
if (lowerText.includes(name)) {
month = valueForMonth;
break;
}
}
const yearMatch = textValue.match(/\b(20\d{2})\b/);
if (month && yearMatch) {
const withoutYear = textValue.replace(yearMatch[1], "");
const dayMatch = withoutYear.match(/\b([0-3]?\d)\b/);
if (dayMatch) {
return formatBillBelong(yearMatch[1], month, dayMatch[1], normalizeTime(textValue, textValue));
}
}
return "";
}
function historyMorePath(billBelong) {