refactor: use A.D. year

This commit is contained in:
Methapon Metanipat 2024-11-05 07:30:03 +07:00
parent 7e9a033a47
commit f96837b133
2 changed files with 3 additions and 11 deletions

View file

@ -25,7 +25,7 @@ function valueUpdate(value: string) {
}
if (value.length === 10) {
const _date = parseAndFormatDate(value, i18n.locale.value);
const _date = parseAndFormatDate(value);
if (_date) {
if (Array.isArray(props.disabledDates)) {

View file

@ -139,20 +139,12 @@ export function disabledAfterToday(date: Date) {
return date > today;
}
export function parseAndFormatDate(
value: string | number | undefined,
locale: string,
) {
export function parseAndFormatDate(value: string | number | undefined) {
if (!value) return;
if (value && value.toString().length === 10) {
const [date, month, year] = value.toString().split('/');
if (locale === 'tha') {
const adjustedYear = Number(year) - 543;
return new Date(`${adjustedYear}-${month}-${date}T00:00:00.000Z`);
} else {
return new Date(`${year}-${month}-${date}T00:00:00.000Z`);
}
return new Date(`${year}-${month}-${date}T00:00:00.000Z`);
}
return null;
}