From 8e173a996f89b1f8f2a8765b974a8b0df14f6548 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Wed, 17 Jul 2024 10:48:56 +0000 Subject: [PATCH] fix: input datepicker th (function) --- src/utils/datetime.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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; }