Debian Codegraph @

vendor/static/moment/src/lib/units/week.js

raw
1 import { addFormatToken } from '../format/format';
2 import {
3 addRegexToken,
4 match1to2,
5 match2,
6 match1to2NoLeadingZero,
7 } from '../parse/regex';
8 import { addWeekParseToken } from '../parse/token';
9 import toInt from '../utils/to-int';
10 import { weekOfYear } from './week-calendar-utils';
11
12 // FORMATTING
13
14 addFormatToken('w', ['ww', 2], 'wo', 'week');
15 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
16
17 // PARSING
18
19 addRegexToken('w', match1to2, match1to2NoLeadingZero);
20 addRegexToken('ww', match1to2, match2);
21 addRegexToken('W', match1to2, match1to2NoLeadingZero);
22 addRegexToken('WW', match1to2, match2);
23
24 addWeekParseToken(
25 ['w', 'ww', 'W', 'WW'],
26 function (input, week, config, token) {
27 week[token.substr(0, 1)] = toInt(input);
28 }
29 );
30
31 // HELPERS
32
33 // LOCALES
34
35 export function localeWeek(mom) {
36 return weekOfYear(mom, this._week.dow, this._week.doy).week;
37 }
38
39 export var defaultLocaleWeek = {
40 dow: 0, // Sunday is the first day of the week.
41 doy: 6, // The week that contains Jan 6th is the first week of the year.
42 };
43
44 export function localeFirstDayOfWeek() {
45 return this._week.dow;
46 }
47
48 export function localeFirstDayOfYear() {
49 return this._week.doy;
50 }
51
52 // MOMENTS
53
54 export function getSetWeek(input) {
55 var week = this.localeData().week(this);
56 return input == null ? week : this.add((input - week) * 7, 'd');
57 }
58
59 export function getSetISOWeek(input) {
60 var week = weekOfYear(this, 1, 4).week;
61 return input == null ? week : this.add((input - week) * 7, 'd');
62 }