diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts index de14c2e1..6994869b 100644 --- a/src/utils/datetime.ts +++ b/src/utils/datetime.ts @@ -15,6 +15,7 @@ export function dateFormatJS(opts: { dayStyle?: 'numeric' | '2-digit'; monthStyle?: 'numeric' | '2-digit' | 'long' | 'short'; timeStyle?: 'full' | 'long' | 'medium' | 'short'; + timeOnly?: boolean; noDay?: boolean; noMonth?: boolean; noYear?: boolean; @@ -24,7 +25,14 @@ export function dateFormatJS(opts: { const { locale } = i18n.global; if (!opts.locale) { - opts.locale = locale.value === Lang.Thai ? 'th-Th' : 'en-US'; + opts.locale = locale.value === Lang.Thai ? 'th-TH' : 'en-US'; + } + + if (opts.timeOnly) { + opts.noDay = true; + opts.noMonth = true; + opts.noYear = true; + opts.timeStyle = opts.timeStyle || 'short'; } let formatted = new Intl.DateTimeFormat(opts.locale, { @@ -35,6 +43,8 @@ export function dateFormatJS(opts: { }).format(dt); switch (opts.locale) { + case Lang.Thai: + case 'th-TH': case 'th-Th': return formatted.replace(/(\d{4})/, (year) => (parseInt(year) - 543).toString(),