Debian Codegraph @

vendor/static/moment/src/lib/locale/lists.js

raw
1 import isNumber from '../utils/is-number';
2 import { getLocale } from './locales';
3 import { createUTC } from '../create/utc';
4
5 function get(format, index, field, setter) {
6 var locale = getLocale(),
7 utc = createUTC().set(setter, index);
8 return locale[field](utc, format);
9 }
10
11 function listMonthsImpl(format, index, field) {
12 if (isNumber(format)) {
13 index = format;
14 format = undefined;
15 }
16
17 format = format || '';
18
19 if (index != null) {
20 return get(format, index, field, 'month');
21 }
22
23 var i,
24 out = [];
25 for (i = 0; i < 12; i++) {
26 out[i] = get(format, i, field, 'month');
27 }
28 return out;
29 }
30
31 // ()
32 // (5)
33 // (fmt, 5)
34 // (fmt)
35 // (true)
36 // (true, 5)
37 // (true, fmt, 5)
38 // (true, fmt)
39 function listWeekdaysImpl(localeSorted, format, index, field) {
40 if (typeof localeSorted === 'boolean') {
41 if (isNumber(format)) {
42 index = format;
43 format = undefined;
44 }
45
46 format = format || '';
47 } else {
48 format = localeSorted;
49 index = format;
50 localeSorted = false;
51
52 if (isNumber(format)) {
53 index = format;
54 format = undefined;
55 }
56
57 format = format || '';
58 }
59
60 var locale = getLocale(),
61 shift = localeSorted ? locale._week.dow : 0,
62 i,
63 out = [];
64
65 if (index != null) {
66 return get(format, (index + shift) % 7, field, 'day');
67 }
68
69 for (i = 0; i < 7; i++) {
70 out[i] = get(format, (i + shift) % 7, field, 'day');
71 }
72 return out;
73 }
74
75 export function listMonths(format, index) {
76 return listMonthsImpl(format, index, 'months');
77 }
78
79 export function listMonthsShort(format, index) {
80 return listMonthsImpl(format, index, 'monthsShort');
81 }
82
83 export function listWeekdays(localeSorted, format, index) {
84 return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
85 }
86
87 export function listWeekdaysShort(localeSorted, format, index) {
88 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
89 }
90
91 export function listWeekdaysMin(localeSorted, format, index) {
92 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
93 }