diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts index 165e1ac2..8ccacf0a 100644 --- a/src/utils/datetime.ts +++ b/src/utils/datetime.ts @@ -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; }