if (typeof input !== 'string') {
return parseInt(input, 10);
input = locale.weekdaysParse(input);
if (typeof input === 'number') {
function parseIsoWeekday(input, locale) {
if (typeof input === 'string') {
return locale.weekdaysParse(input) % 7 || 7;
return isNaN(input) ? null : input;
function shiftWeekdays(ws, n) {
return ws.slice(n, 7).concat(ws.slice(0, n));
var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split(
defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
defaultWeekdaysRegex = matchWord,
defaultWeekdaysShortRegex = matchWord,
defaultWeekdaysMinRegex = matchWord;
function localeWeekdays(m, format) {
var weekdays = isArray(this._weekdays)
m && m !== true && this._weekdays.isFormat.test(format)
? shiftWeekdays(weekdays, this._week.dow)
function localeWeekdaysShort(m) {
? shiftWeekdays(this._weekdaysShort, this._week.dow)
? this._weekdaysShort[m.day()]
function localeWeekdaysMin(m) {
? shiftWeekdays(this._weekdaysMin, this._week.dow)
? this._weekdaysMin[m.day()]
function handleStrictParse$1(weekdayName, format, strict) {
llc = weekdayName.toLocaleLowerCase();
if (!this._weekdaysParse) {
this._weekdaysParse = [];
this._shortWeekdaysParse = [];
this._minWeekdaysParse = [];
for (i = 0; i < 7; ++i) {
mom = createUTC([2000, 1]).day(i);
this._minWeekdaysParse[i] = this.weekdaysMin(
this._shortWeekdaysParse[i] = this.weekdaysShort(
this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
ii = indexOf.call(this._weekdaysParse, llc);
return ii !== -1 ? ii : null;
} else if (format === 'ddd') {
ii = indexOf.call(this._shortWeekdaysParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._weekdaysParse, llc);
ii = indexOf.call(this._shortWeekdaysParse, llc);
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
} else if (format === 'ddd') {
ii = indexOf.call(this._shortWeekdaysParse, llc);
ii = indexOf.call(this._weekdaysParse, llc);
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._minWeekdaysParse, llc);
ii = indexOf.call(this._weekdaysParse, llc);
ii = indexOf.call(this._shortWeekdaysParse, llc);
return ii !== -1 ? ii : null;
function localeWeekdaysParse(weekdayName, format, strict) {
if (this._weekdaysParseExact) {
return handleStrictParse$1.call(this, weekdayName, format, strict);
if (!this._weekdaysParse) {
this._weekdaysParse = [];
this._minWeekdaysParse = [];
this._shortWeekdaysParse = [];
this._fullWeekdaysParse = [];
for (i = 0; i < 7; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, 1]).day(i);
if (strict && !this._fullWeekdaysParse[i]) {
this._fullWeekdaysParse[i] = new RegExp(
'^' + this.weekdays(mom, '').replace('.', '\\.?') + '$',
this._shortWeekdaysParse[i] = new RegExp(
'^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$',
this._minWeekdaysParse[i] = new RegExp(
'^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$',
if (!this._weekdaysParse[i]) {
this.weekdaysShort(mom, '') +
this.weekdaysMin(mom, '');
this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
this._fullWeekdaysParse[i].test(weekdayName)
this._shortWeekdaysParse[i].test(weekdayName)
this._minWeekdaysParse[i].test(weekdayName)
} else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
function getSetDayOfWeek(input) {
return input != null ? this : NaN;
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
input = parseWeekday(input, this.localeData());
return this.add(input - day, 'd');
function getSetLocaleDayOfWeek(input) {
return input != null ? this : NaN;
var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
return input == null ? weekday : this.add(input - weekday, 'd');
function getSetISODayOfWeek(input) {
return input != null ? this : NaN;
// behaves the same as moment#day except
// as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
// as a setter, sunday should belong to the previous week.
var weekday = parseIsoWeekday(input, this.localeData());
return this.day(this.day() % 7 ? weekday : weekday - 7);
function weekdaysRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
return this._weekdaysStrictRegex;
return this._weekdaysRegex;
if (!hasOwnProp(this, '_weekdaysRegex')) {
this._weekdaysRegex = defaultWeekdaysRegex;
return this._weekdaysStrictRegex && isStrict
? this._weekdaysStrictRegex
function weekdaysShortRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
return this._weekdaysShortStrictRegex;
return this._weekdaysShortRegex;
if (!hasOwnProp(this, '_weekdaysShortRegex')) {
this._weekdaysShortRegex = defaultWeekdaysShortRegex;
return this._weekdaysShortStrictRegex && isStrict
? this._weekdaysShortStrictRegex
: this._weekdaysShortRegex;
function weekdaysMinRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
return this._weekdaysMinStrictRegex;
return this._weekdaysMinRegex;
if (!hasOwnProp(this, '_weekdaysMinRegex')) {
this._weekdaysMinRegex = defaultWeekdaysMinRegex;
return this._weekdaysMinStrictRegex && isStrict
? this._weekdaysMinStrictRegex
: this._weekdaysMinRegex;
function computeWeekdaysParse() {
function cmpLenRev(a, b) {
return b.length - a.length;
for (i = 0; i < 7; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, 1]).day(i);
minp = regexEscape(this.weekdaysMin(mom, ''));
shortp = regexEscape(this.weekdaysShort(mom, ''));
longp = regexEscape(this.weekdays(mom, ''));
shortPieces.push(shortp);
mixedPieces.push(shortp);
// Sorting makes sure if one weekday (or abbr) is a prefix of another it
// will match the longer piece.
minPieces.sort(cmpLenRev);
shortPieces.sort(cmpLenRev);
longPieces.sort(cmpLenRev);
mixedPieces.sort(cmpLenRev);
this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._weekdaysShortRegex = this._weekdaysRegex;
this._weekdaysMinRegex = this._weekdaysRegex;
this._weekdaysStrictRegex = new RegExp(
'^(' + longPieces.join('|') + ')',
this._weekdaysShortStrictRegex = new RegExp(
'^(' + shortPieces.join('|') + ')',
this._weekdaysMinStrictRegex = new RegExp(
'^(' + minPieces.join('|') + ')',
return this.hours() % 12 || 12;
return this.hours() || 24;
addFormatToken('H', ['HH', 2], 0, 'hour');
addFormatToken('h', ['hh', 2], 0, hFormat);
addFormatToken('k', ['kk', 2], 0, kFormat);
addFormatToken('hmm', 0, 0, function () {
return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
addFormatToken('hmmss', 0, 0, function () {
zeroFill(this.minutes(), 2) +
zeroFill(this.seconds(), 2)
addFormatToken('Hmm', 0, 0, function () {
return '' + this.hours() + zeroFill(this.minutes(), 2);
addFormatToken('Hmmss', 0, 0, function () {
zeroFill(this.minutes(), 2) +
zeroFill(this.seconds(), 2)
function meridiem(token, lowercase) {
addFormatToken(token, 0, 0, function () {
return this.localeData().meridiem(
addUnitAlias('hour', 'h');
addUnitPriority('hour', 13);
function matchMeridiem(isStrict, locale) {
return locale._meridiemParse;
addRegexToken('a', matchMeridiem);
addRegexToken('A', matchMeridiem);
addRegexToken('H', match1to2);
addRegexToken('h', match1to2);
addRegexToken('k', match1to2);
addRegexToken('HH', match1to2, match2);
addRegexToken('hh', match1to2, match2);
addRegexToken('kk', match1to2, match2);
addRegexToken('hmm', match3to4);
addRegexToken('hmmss', match5to6);
addRegexToken('Hmm', match3to4);
addRegexToken('Hmmss', match5to6);
addParseToken(['H', 'HH'], HOUR);
addParseToken(['k', 'kk'], function (input, array, config) {
var kInput = toInt(input);
array[HOUR] = kInput === 24 ? 0 : kInput;
addParseToken(['a', 'A'], function (input, array, config) {
config._isPm = config._locale.isPM(input);
config._meridiem = input;
addParseToken(['h', 'hh'], function (input, array, config) {
array[HOUR] = toInt(input);
getParsingFlags(config).bigHour = true;
addParseToken('hmm', function (input, array, config) {
var pos = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos));
array[MINUTE] = toInt(input.substr(pos));
getParsingFlags(config).bigHour = true;
addParseToken('hmmss', function (input, array, config) {
var pos1 = input.length - 4,
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
getParsingFlags(config).bigHour = true;
addParseToken('Hmm', function (input, array, config) {
var pos = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos));
array[MINUTE] = toInt(input.substr(pos));
addParseToken('Hmmss', function (input, array, config) {
var pos1 = input.length - 4,
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
function localeIsPM(input) {
// IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
// Using charAt should be more compatible.
return (input + '').toLowerCase().charAt(0) === 'p';
var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
// Setting the hour should keep the time, because the user explicitly
// specified which hour they want. So trying to maintain the same hour (in
// a new timezone) makes sense. Adding/subtracting hours does not follow
getSetHour = makeGetSet('Hours', true);
function localeMeridiem(hours, minutes, isLower) {
return isLower ? 'pm' : 'PM';
return isLower ? 'am' : 'AM';