refactor: date time util function default
This commit is contained in:
parent
a7d43cd755
commit
5afe625290
1 changed files with 11 additions and 3 deletions
|
|
@ -2,6 +2,8 @@ import moment from 'moment';
|
||||||
import 'moment/dist/locale/th';
|
import 'moment/dist/locale/th';
|
||||||
import 'moment/dist/locale/en-gb';
|
import 'moment/dist/locale/en-gb';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { i18n } from 'src/boot/i18n';
|
||||||
|
import { Lang } from './ui';
|
||||||
|
|
||||||
moment.locale('en-gb');
|
moment.locale('en-gb');
|
||||||
|
|
||||||
|
|
@ -29,9 +31,15 @@ export function dateFormatJS(opts: {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let formattedDate = new Intl.DateTimeFormat(opts.locale || 'en-US', {
|
const { locale } = i18n.global;
|
||||||
day: opts.dayStyle,
|
|
||||||
month: opts.monthStyle,
|
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,
|
timeStyle: opts.timeStyle,
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
}).format(dateFormat);
|
}).format(dateFormat);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue