UNPKG

3.69 kBJavaScriptView Raw
1import { t } from '../localizedFormat/utils';
2export default (function (o, c, dayjs) {
3 // locale needed later
4 var proto = c.prototype;
5
6 var getLocalePart = function getLocalePart(part) {
7 return part && (part.indexOf ? part : part.s);
8 };
9
10 var getShort = function getShort(ins, target, full, num, localeOrder) {
11 var locale = ins.name ? ins : ins.$locale();
12 var targetLocale = getLocalePart(locale[target]);
13 var fullLocale = getLocalePart(locale[full]);
14 var result = targetLocale || fullLocale.map(function (f) {
15 return f.slice(0, num);
16 });
17 if (!localeOrder) return result;
18 var weekStart = locale.weekStart;
19 return result.map(function (_, index) {
20 return result[(index + (weekStart || 0)) % 7];
21 });
22 };
23
24 var getDayjsLocaleObject = function getDayjsLocaleObject() {
25 return dayjs.Ls[dayjs.locale()];
26 };
27
28 var getLongDateFormat = function getLongDateFormat(l, format) {
29 return l.formats[format] || t(l.formats[format.toUpperCase()]);
30 };
31
32 var localeData = function localeData() {
33 var _this = this;
34
35 return {
36 months: function months(instance) {
37 return instance ? instance.format('MMMM') : getShort(_this, 'months');
38 },
39 monthsShort: function monthsShort(instance) {
40 return instance ? instance.format('MMM') : getShort(_this, 'monthsShort', 'months', 3);
41 },
42 firstDayOfWeek: function firstDayOfWeek() {
43 return _this.$locale().weekStart || 0;
44 },
45 weekdays: function weekdays(instance) {
46 return instance ? instance.format('dddd') : getShort(_this, 'weekdays');
47 },
48 weekdaysMin: function weekdaysMin(instance) {
49 return instance ? instance.format('dd') : getShort(_this, 'weekdaysMin', 'weekdays', 2);
50 },
51 weekdaysShort: function weekdaysShort(instance) {
52 return instance ? instance.format('ddd') : getShort(_this, 'weekdaysShort', 'weekdays', 3);
53 },
54 longDateFormat: function longDateFormat(format) {
55 return getLongDateFormat(_this.$locale(), format);
56 },
57 meridiem: this.$locale().meridiem,
58 ordinal: this.$locale().ordinal
59 };
60 };
61
62 proto.localeData = function () {
63 return localeData.bind(this)();
64 };
65
66 dayjs.localeData = function () {
67 var localeObject = getDayjsLocaleObject();
68 return {
69 firstDayOfWeek: function firstDayOfWeek() {
70 return localeObject.weekStart || 0;
71 },
72 weekdays: function weekdays() {
73 return dayjs.weekdays();
74 },
75 weekdaysShort: function weekdaysShort() {
76 return dayjs.weekdaysShort();
77 },
78 weekdaysMin: function weekdaysMin() {
79 return dayjs.weekdaysMin();
80 },
81 months: function months() {
82 return dayjs.months();
83 },
84 monthsShort: function monthsShort() {
85 return dayjs.monthsShort();
86 },
87 longDateFormat: function longDateFormat(format) {
88 return getLongDateFormat(localeObject, format);
89 },
90 meridiem: localeObject.meridiem,
91 ordinal: localeObject.ordinal
92 };
93 };
94
95 dayjs.months = function () {
96 return getShort(getDayjsLocaleObject(), 'months');
97 };
98
99 dayjs.monthsShort = function () {
100 return getShort(getDayjsLocaleObject(), 'monthsShort', 'months', 3);
101 };
102
103 dayjs.weekdays = function (localeOrder) {
104 return getShort(getDayjsLocaleObject(), 'weekdays', null, null, localeOrder);
105 };
106
107 dayjs.weekdaysShort = function (localeOrder) {
108 return getShort(getDayjsLocaleObject(), 'weekdaysShort', 'weekdays', 3, localeOrder);
109 };
110
111 dayjs.weekdaysMin = function (localeOrder) {
112 return getShort(getDayjsLocaleObject(), 'weekdaysMin', 'weekdays', 2, localeOrder);
113 };
114});
\No newline at end of file