this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
ii = indexOf.call(this._shortMonthsParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._longMonthsParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._shortMonthsParse, llc);
ii = indexOf.call(this._longMonthsParse, llc);
return ii !== -1 ? ii : null;
ii = indexOf.call(this._longMonthsParse, llc);
ii = indexOf.call(this._shortMonthsParse, llc);
return ii !== -1 ? ii : null;
function localeMonthsParse(monthName, format, strict) {
if (this._monthsParseExact) {
return handleStrictParse.call(this, monthName, format, strict);
if (!this._monthsParse) {
this._longMonthsParse = [];
this._shortMonthsParse = [];
// Sorting makes sure if one month (or abbr) is a prefix of another
// see sorting in computeMonthsParse
for (i = 0; i < 12; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, i]);
if (strict && !this._longMonthsParse[i]) {
this._longMonthsParse[i] = new RegExp(
'^' + this.months(mom, '').replace('.', '') + '$',
this._shortMonthsParse[i] = new RegExp(
'^' + this.monthsShort(mom, '').replace('.', '') + '$',
if (!strict && !this._monthsParse[i]) {
'^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
this._longMonthsParse[i].test(monthName)
this._shortMonthsParse[i].test(monthName)
} else if (!strict && this._monthsParse[i].test(monthName)) {
function setMonth(mom, value) {
if (typeof value === 'string') {
if (/^\d+$/.test(value)) {
value = mom.localeData().monthsParse(value);
// TODO: Another silent failure?
dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
function getSetMonth(value) {
hooks.updateOffset(this, true);
return get(this, 'Month');
function getDaysInMonth() {
return daysInMonth(this.year(), this.month());
function monthsShortRegex(isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
computeMonthsParse.call(this);
return this._monthsShortStrictRegex;
return this._monthsShortRegex;
if (!hasOwnProp(this, '_monthsShortRegex')) {
this._monthsShortRegex = defaultMonthsShortRegex;
return this._monthsShortStrictRegex && isStrict
? this._monthsShortStrictRegex
: this._monthsShortRegex;
function monthsRegex(isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
computeMonthsParse.call(this);
return this._monthsStrictRegex;
return this._monthsRegex;
if (!hasOwnProp(this, '_monthsRegex')) {
this._monthsRegex = defaultMonthsRegex;
return this._monthsStrictRegex && isStrict
? this._monthsStrictRegex
function computeMonthsParse() {
function cmpLenRev(a, b) {
return b.length - a.length;
for (i = 0; i < 12; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, i]);
shortPieces.push(this.monthsShort(mom, ''));
longPieces.push(this.months(mom, ''));
mixedPieces.push(this.months(mom, ''));
mixedPieces.push(this.monthsShort(mom, ''));
// Sorting makes sure if one month (or abbr) is a prefix of another it
// will match the longer piece.
shortPieces.sort(cmpLenRev);
longPieces.sort(cmpLenRev);
mixedPieces.sort(cmpLenRev);
for (i = 0; i < 12; i++) {
shortPieces[i] = regexEscape(shortPieces[i]);
longPieces[i] = regexEscape(longPieces[i]);
for (i = 0; i < 24; i++) {
mixedPieces[i] = regexEscape(mixedPieces[i]);
this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._monthsShortRegex = this._monthsRegex;
this._monthsStrictRegex = new RegExp(
'^(' + longPieces.join('|') + ')',
this._monthsShortStrictRegex = new RegExp(
'^(' + shortPieces.join('|') + ')',
addFormatToken('Y', 0, 0, function () {
return y <= 9999 ? zeroFill(y, 4) : '+' + y;
addFormatToken(0, ['YY', 2], 0, function () {
return this.year() % 100;
addFormatToken(0, ['YYYY', 4], 0, 'year');
addFormatToken(0, ['YYYYY', 5], 0, 'year');
addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
addUnitAlias('year', 'y');
addUnitPriority('year', 1);
addRegexToken('Y', matchSigned);
addRegexToken('YY', match1to2, match2);
addRegexToken('YYYY', match1to4, match4);
addRegexToken('YYYYY', match1to6, match6);
addRegexToken('YYYYYY', match1to6, match6);
addParseToken(['YYYYY', 'YYYYYY'], YEAR);
addParseToken('YYYY', function (input, array) {
input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
addParseToken('YY', function (input, array) {
array[YEAR] = hooks.parseTwoDigitYear(input);
addParseToken('Y', function (input, array) {
array[YEAR] = parseInt(input, 10);
function daysInYear(year) {
return isLeapYear(year) ? 366 : 365;
hooks.parseTwoDigitYear = function (input) {
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
var getSetYear = makeGetSet('FullYear', true);
function getIsLeapYear() {
return isLeapYear(this.year());
function createDate(y, m, d, h, M, s, ms) {
// can't just apply() to create a date:
// https://stackoverflow.com/q/181348
// the date constructor remaps years 0-99 to 1900-1999
// preserve leap years using a full 400 year cycle, then reset
date = new Date(y + 400, m, d, h, M, s, ms);
if (isFinite(date.getFullYear())) {
date = new Date(y, m, d, h, M, s, ms);
function createUTCDate(y) {
// the Date.UTC function remaps years 0-99 to 1900-1999
args = Array.prototype.slice.call(arguments);
// preserve leap years using a full 400 year cycle, then reset
date = new Date(Date.UTC.apply(null, args));
if (isFinite(date.getUTCFullYear())) {
date = new Date(Date.UTC.apply(null, arguments));
// start-of-first-week - start-of-year
function firstWeekOffset(year, dow, doy) {
var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
// first-week day local weekday -- which local weekday is fwd
fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
var localWeekday = (7 + weekday - dow) % 7,
weekOffset = firstWeekOffset(year, dow, doy),
dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
resDayOfYear = daysInYear(resYear) + dayOfYear;
} else if (dayOfYear > daysInYear(year)) {
resDayOfYear = dayOfYear - daysInYear(year);
resDayOfYear = dayOfYear;
function weekOfYear(mom, dow, doy) {
var weekOffset = firstWeekOffset(mom.year(), dow, doy),
week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
resYear = mom.year() - 1;
resWeek = week + weeksInYear(resYear, dow, doy);
} else if (week > weeksInYear(mom.year(), dow, doy)) {
resWeek = week - weeksInYear(mom.year(), dow, doy);
resYear = mom.year() + 1;
function weeksInYear(year, dow, doy) {
var weekOffset = firstWeekOffset(year, dow, doy),
weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
addFormatToken('w', ['ww', 2], 'wo', 'week');
addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
addUnitAlias('week', 'w');
addUnitAlias('isoWeek', 'W');
addUnitPriority('week', 5);
addUnitPriority('isoWeek', 5);
addRegexToken('w', match1to2);
addRegexToken('ww', match1to2, match2);
addRegexToken('W', match1to2);
addRegexToken('WW', match1to2, match2);
addWeekParseToken(['w', 'ww', 'W', 'WW'], function (
week[token.substr(0, 1)] = toInt(input);
function localeWeek(mom) {
return weekOfYear(mom, this._week.dow, this._week.doy).week;
var defaultLocaleWeek = {
dow: 0, // Sunday is the first day of the week.
doy: 6, // The week that contains Jan 6th is the first week of the year.
function localeFirstDayOfWeek() {
function localeFirstDayOfYear() {
function getSetWeek(input) {
var week = this.localeData().week(this);
return input == null ? week : this.add((input - week) * 7, 'd');
function getSetISOWeek(input) {
var week = weekOfYear(this, 1, 4).week;
return input == null ? week : this.add((input - week) * 7, 'd');
addFormatToken('d', 0, 'do', 'day');
addFormatToken('dd', 0, 0, function (format) {
return this.localeData().weekdaysMin(this, format);
addFormatToken('ddd', 0, 0, function (format) {
return this.localeData().weekdaysShort(this, format);
addFormatToken('dddd', 0, 0, function (format) {
return this.localeData().weekdays(this, format);
addFormatToken('e', 0, 0, 'weekday');
addFormatToken('E', 0, 0, 'isoWeekday');
addUnitAlias('day', 'd');
addUnitAlias('weekday', 'e');
addUnitAlias('isoWeekday', 'E');
addUnitPriority('day', 11);
addUnitPriority('weekday', 11);
addUnitPriority('isoWeekday', 11);
addRegexToken('d', match1to2);
addRegexToken('e', match1to2);
addRegexToken('E', match1to2);
addRegexToken('dd', function (isStrict, locale) {
return locale.weekdaysMinRegex(isStrict);
addRegexToken('ddd', function (isStrict, locale) {
return locale.weekdaysShortRegex(isStrict);
addRegexToken('dddd', function (isStrict, locale) {
return locale.weekdaysRegex(isStrict);
addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
var weekday = config._locale.weekdaysParse(input, token, config._strict);
// if we didn't get a weekday name, mark the date as invalid
getParsingFlags(config).invalidWeekday = input;
addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
week[token] = toInt(input);
function parseWeekday(input, locale) {