Refine loan tab filtering and date formats
This commit is contained in:
+21
-4
@@ -87,9 +87,11 @@ function isDateOnlyString(value) {
|
||||
return typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value);
|
||||
}
|
||||
|
||||
const VALID_DATE_FORMATS = ['mdy', 'dmy', 'ymd', 'mdy_dot', 'dmy_dot', 'ymd_dot', 'ymd_slash'];
|
||||
|
||||
function getDateFormatPreference() {
|
||||
const stored = localStorage.getItem(DATE_FORMAT_KEY);
|
||||
return ['mdy', 'dmy', 'ymd'].includes(stored) ? stored : DEFAULT_DATE_FORMAT;
|
||||
return VALID_DATE_FORMATS.includes(stored) ? stored : DEFAULT_DATE_FORMAT;
|
||||
}
|
||||
|
||||
export function getDateFormat() {
|
||||
@@ -112,8 +114,12 @@ function formatDateParts(date, useUtc = false) {
|
||||
const month = String((useUtc ? d.getUTCMonth() : d.getMonth()) + 1).padStart(2, '0');
|
||||
const day = String(useUtc ? d.getUTCDate() : d.getDate()).padStart(2, '0');
|
||||
switch (getDateFormatPreference()) {
|
||||
case 'dmy': return `${day}.${month}.${year}`;
|
||||
case 'dmy': return `${day}/${month}/${year}`;
|
||||
case 'mdy_dot': return `${month}.${day}.${year}`;
|
||||
case 'dmy_dot': return `${day}.${month}.${year}`;
|
||||
case 'ymd': return `${year}-${month}-${day}`;
|
||||
case 'ymd_dot': return `${year}.${month}.${day}`;
|
||||
case 'ymd_slash': return `${year}/${month}/${day}`;
|
||||
default: return `${month}/${day}/${year}`;
|
||||
}
|
||||
}
|
||||
@@ -139,8 +145,12 @@ export function formatDate(date) {
|
||||
|
||||
export function dateInputPlaceholder() {
|
||||
switch (getDateFormatPreference()) {
|
||||
case 'dmy': return 'DD.MM.YYYY';
|
||||
case 'dmy': return 'DD/MM/YYYY';
|
||||
case 'mdy_dot': return 'MM.DD.YYYY';
|
||||
case 'dmy_dot': return 'DD.MM.YYYY';
|
||||
case 'ymd': return 'YYYY-MM-DD';
|
||||
case 'ymd_dot': return 'YYYY.MM.DD';
|
||||
case 'ymd_slash': return 'YYYY/MM/DD';
|
||||
default: return 'MM/DD/YYYY';
|
||||
}
|
||||
}
|
||||
@@ -157,11 +167,18 @@ export function parseDateInput(value) {
|
||||
const isoMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||
if (isoMatch) return isValidDateParts(isoMatch[1], isoMatch[2], isoMatch[3]) ? raw : '';
|
||||
|
||||
const ymdSeparatorMatch = raw.match(/^(\d{4})[\/.](\d{1,2})[\/.](\d{1,2})$/);
|
||||
if (ymdSeparatorMatch && getDateFormatPreference().startsWith('ymd')) {
|
||||
const [, year, month, day] = ymdSeparatorMatch;
|
||||
if (!isValidDateParts(year, month, day)) return '';
|
||||
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
const slashMatch = raw.match(/^(\d{1,2})[\/.](\d{1,2})[\/.](\d{4})$/);
|
||||
if (!slashMatch) return '';
|
||||
|
||||
const [, first, second, year] = slashMatch;
|
||||
const [month, day] = getDateFormatPreference() === 'dmy'
|
||||
const [month, day] = getDateFormatPreference().startsWith('dmy')
|
||||
? [second, first]
|
||||
: [first, second];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user