refactor: date time util function default

This commit is contained in:
Methapon2001 2024-12-16 16:27:09 +07:00
parent a7d43cd755
commit 5afe625290

View file

@ -2,6 +2,8 @@ import moment from 'moment';
import 'moment/dist/locale/th';
import 'moment/dist/locale/en-gb';
import { useI18n } from 'vue-i18n';
import { i18n } from 'src/boot/i18n';
import { Lang } from './ui';
moment.locale('en-gb');
@ -29,9 +31,15 @@ export function dateFormatJS(opts: {
),
);
let formattedDate = new Intl.DateTimeFormat(opts.locale || 'en-US', {
day: opts.dayStyle,
month: opts.monthStyle,
const { locale } = i18n.global;
if (!opts.locale) {
opts.locale = locale.value === Lang.Thai ? 'th-Th' : 'en-US';
}
let formattedDate = new Intl.DateTimeFormat(opts.locale, {
day: opts.dayStyle || 'numeric',
month: opts.monthStyle || 'short',
timeStyle: opts.timeStyle,
year: 'numeric',
}).format(dateFormat);