-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathLocaleUtil.ts
34 lines (30 loc) · 882 Bytes
/
LocaleUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as dayjs from 'dayjs';
import { IDatePicker } from '../common/@types';
import { range } from '../utils/ArrayUtil';
import * as localeData from 'dayjs/plugin/localeData';
import * as localizedFormat from 'dayjs/plugin/localizedFormat';
import * as weekday from 'dayjs/plugin/weekday';
dayjs.extend(localeData);
dayjs.extend(localizedFormat);
dayjs.extend(weekday);
export const getMonthShort = (locale: IDatePicker.Locale) => {
dayjs.locale(locale);
return range(0, 12).map(v =>
dayjs()
.localeData()
.monthsShort(dayjs().month(v))
);
};
export const getWeekDays = (locale: IDatePicker.Locale) => {
dayjs.locale(locale);
return range(7).map(v =>
dayjs()
.localeData()
.weekdaysShort(dayjs().weekday(v))
);
};
export const getToday = (locale: IDatePicker.Locale) => {
return dayjs()
.locale(locale)
.format('LL');
};