fix: input datepicker th (function)

This commit is contained in:
puriphatt 2024-07-17 10:48:56 +00:00
parent 53669267b1
commit 8e173a996f

View file

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