return locale[field](utc, format);
}
-function list (format, index, field, count, setter) {
+function listMonthsImpl (format, index, field) {
if (typeof format === 'number') {
index = format;
format = undefined;
format = format || '';
if (index != null) {
- return get(format, index, field, setter);
+ return get(format, index, field, 'month');
}
var i;
var out = [];
- for (i = 0; i < count; i++) {
- out[i] = get(format, i, field, setter);
+ for (i = 0; i < 12; i++) {
+ out[i] = get(format, i, field, 'month');
+ }
+ return out;
+}
+
+// ()
+// (5)
+// (fmt, 5)
+// (fmt)
+// (true)
+// (true, 5)
+// (true, fmt, 5)
+// (true, fmt)
+function listWeekdaysImpl (localeSorted, format, index, field) {
+ if (typeof localeSorted === 'boolean') {
+ if (typeof format === 'number') {
+ index = format;
+ format = undefined;
+ }
+
+ format = format || '';
+ } else {
+ format = localeSorted;
+ index = format;
+ localeSorted = false;
+
+ if (typeof format === 'number') {
+ index = format;
+ format = undefined;
+ }
+
+ format = format || '';
+ }
+
+ var locale = getLocale(),
+ shift = localeSorted ? locale._week.dow : 0;
+
+ if (index != null) {
+ return get(format, (index + shift) % 7, field, 'day');
+ }
+
+ var i;
+ var out = [];
+ for (i = 0; i < 7; i++) {
+ out[i] = get(format, (i + shift) % 7, field, 'day');
}
return out;
}
export function listMonths (format, index) {
- return list(format, index, 'months', 12, 'month');
+ return listMonthsImpl(format, index, 'months');
}
export function listMonthsShort (format, index) {
- return list(format, index, 'monthsShort', 12, 'month');
+ return listMonthsImpl(format, index, 'monthsShort');
}
-export function listWeekdays (format, index) {
- return list(format, index, 'weekdays', 7, 'day');
+export function listWeekdays (localeSorted, format, index) {
+ return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
}
-export function listWeekdaysShort (format, index) {
- return list(format, index, 'weekdaysShort', 7, 'day');
+export function listWeekdaysShort (localeSorted, format, index) {
+ return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
}
-export function listWeekdaysMin (format, index) {
- return list(format, index, 'weekdaysMin', 7, 'day');
+export function listWeekdaysMin (localeSorted, format, index) {
+ return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
}
monthsShort = 'on_tw_th_fo_fi_si_se_ei_ni_te_el_tw'.split('_'),
weekdays = 'one_two_three_four_five_six_seven'.split('_'),
weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'),
- weekdaysMin = '1_2_3_4_5_6_7'.split('_');
+ weekdaysMin = '1_2_3_4_5_6_7'.split('_'),
+ weekdaysLocale = 'four_five_six_seven_one_two_three'.split('_'),
+ weekdaysShortLocale = 'fo_fi_si_se_on_tw_th'.split('_'),
+ weekdaysMinLocale = '4_5_6_7_1_2_3'.split('_'),
+ week = {
+ dow : 3,
+ doy : 6
+ };
moment.locale('numerologists', {
months : months,
monthsShort : monthsShort,
weekdays : weekdays,
weekdaysShort: weekdaysShort,
- weekdaysMin: weekdaysMin
+ weekdaysMin: weekdaysMin,
+ week : week
});
assert.deepEqual(moment.months(), months);
assert.equal(moment.weekdays(2), 'three');
assert.equal(moment.weekdaysShort(2), 'th');
assert.equal(moment.weekdaysMin(2), '3');
+
+ assert.deepEqual(moment.weekdays(true), weekdaysLocale);
+ assert.deepEqual(moment.weekdaysShort(true), weekdaysShortLocale);
+ assert.deepEqual(moment.weekdaysMin(true), weekdaysMinLocale);
+
+ assert.equal(moment.weekdays(true, 0), 'four');
+ assert.equal(moment.weekdaysShort(true, 0), 'fo');
+ assert.equal(moment.weekdaysMin(true, 0), '4');
+
+ assert.equal(moment.weekdays(false, 2), 'three');
+ assert.equal(moment.weekdaysShort(false, 2), 'th');
+ assert.equal(moment.weekdaysMin(false, 2), '3');
});
test('with functions', function (assert) {