config._d = createUTCDate.apply(null, config._a);
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
getParsingFlags(config).rfc2822 = true;
// date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict
function configFromString(config) {
var matched = aspNetJsonRegex.exec(config._i);
config._d = new Date(+matched[1]);
if (config._isValid === false) {
configFromRFC2822(config);
if (config._isValid === false) {
// Final attempt, use Input Fallback
hooks.createFromInputFallback(config);
hooks.createFromInputFallback = deprecate(
'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
'discouraged and will be removed in an upcoming major release. Please refer to ' +
'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
// Pick the first defined of two or three arguments.
function defaults(a, b, c) {
function currentDateArray(config) {
// hooks is actually the exported moment object
var nowValue = new Date(hooks.now());
nowValue.getUTCFullYear(),
return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
// convert an array to a date.
// the array should mirror the parameters below
// note: all values past the year are optional and will default to the lowest possible value.
// [year, month, day , hour, minute, second, millisecond]
function configFromArray(config) {
currentDate = currentDateArray(config);
//compute day of the year from weeks and weekdays
if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
dayOfYearFromWeekInfo(config);
//if the day of the year is set, figure out what it is
if (config._dayOfYear != null) {
yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
config._dayOfYear > daysInYear(yearToUse) ||
getParsingFlags(config)._overflowDayOfYear = true;
date = createUTCDate(yearToUse, 0, config._dayOfYear);
config._a[MONTH] = date.getUTCMonth();
config._a[DATE] = date.getUTCDate();
// Default to current date.
// * if no year, month, day of month are given, default to today
// * if day of month is given, default month and year
// * if month is given, default only year
// * if year is given, don't default anything
for (i = 0; i < 3 && config._a[i] == null; ++i) {
config._a[i] = input[i] = currentDate[i];
// Zero out whatever was not defaulted, including time
config._a[i] = input[i] =
config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
// Check for 24:00:00.000
config._a[HOUR] === 24 &&
config._a[MINUTE] === 0 &&
config._a[SECOND] === 0 &&
config._a[MILLISECOND] === 0
config._d = (config._useUTC ? createUTCDate : createDate).apply(
expectedWeekday = config._useUTC
// Apply timezone offset from input. The actual utcOffset can be changed
if (config._tzm != null) {
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
// check for mismatching day of week
typeof config._w.d !== 'undefined' &&
config._w.d !== expectedWeekday
getParsingFlags(config).weekdayMismatch = true;
function dayOfYearFromWeekInfo(config) {
var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
if (w.GG != null || w.W != null || w.E != null) {
// TODO: We need to take the current isoWeekYear, but that depends on
// how we interpret now (local, utc, fixed offset). So create
// a now version of current config (take local/utc/offset flags, and
weekOfYear(createLocal(), 1, 4).year
weekday = defaults(w.E, 1);
if (weekday < 1 || weekday > 7) {
dow = config._locale._week.dow;
doy = config._locale._week.doy;
curWeek = weekOfYear(createLocal(), dow, doy);
weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
// Default to current week.
week = defaults(w.w, curWeek.week);
// weekday -- low day numbers are considered next week
if (weekday < 0 || weekday > 6) {
} else if (w.e != null) {
// local weekday -- counting starts from beginning of week
if (w.e < 0 || w.e > 6) {
// default to beginning of week
if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
getParsingFlags(config)._overflowWeeks = true;
} else if (weekdayOverflow != null) {
getParsingFlags(config)._overflowWeekday = true;
temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
config._a[YEAR] = temp.year;
config._dayOfYear = temp.dayOfYear;
// constant that refers to the ISO standard
hooks.ISO_8601 = function () {};
// constant that refers to the RFC 2822 form
hooks.RFC_2822 = function () {};
// date from string and format string
function configFromStringAndFormat(config) {
// TODO: Move this to another part of the creation flow to prevent circular deps
if (config._f === hooks.ISO_8601) {
if (config._f === hooks.RFC_2822) {
configFromRFC2822(config);
getParsingFlags(config).empty = true;
// This array is used to make a Date, either with `new Date` or `Date.UTC`
var string = '' + config._i,
stringLength = string.length,
totalParsedInputLength = 0,
expandFormat(config._f, config._locale).match(formattingTokens) || [];
for (i = 0; i < tokens.length; i++) {
parsedInput = (string.match(getParseRegexForToken(token, config)) ||
skipped = string.substr(0, string.indexOf(parsedInput));
if (skipped.length > 0) {
getParsingFlags(config).unusedInput.push(skipped);
string.indexOf(parsedInput) + parsedInput.length
totalParsedInputLength += parsedInput.length;
// don't parse if it's not a known token
if (formatTokenFunctions[token]) {
getParsingFlags(config).empty = false;
getParsingFlags(config).unusedTokens.push(token);
addTimeToArrayFromToken(token, parsedInput, config);
} else if (config._strict && !parsedInput) {
getParsingFlags(config).unusedTokens.push(token);
// add remaining unparsed input length to the string
getParsingFlags(config).charsLeftOver =
stringLength - totalParsedInputLength;
getParsingFlags(config).unusedInput.push(string);
// clear _12h flag if hour is <= 12
getParsingFlags(config).bigHour === true &&
getParsingFlags(config).bigHour = undefined;
getParsingFlags(config).parsedDateParts = config._a.slice(0);
getParsingFlags(config).meridiem = config._meridiem;
config._a[HOUR] = meridiemFixWrap(
era = getParsingFlags(config).era;
config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
function meridiemFixWrap(locale, hour, meridiem) {
if (locale.meridiemHour != null) {
return locale.meridiemHour(hour, meridiem);
} else if (locale.isPM != null) {
isPm = locale.isPM(meridiem);
if (!isPm && hour === 12) {
// this is not supposed to happen
// date from string and array of format strings
function configFromStringAndArray(config) {
bestFormatIsValid = false;
if (config._f.length === 0) {
getParsingFlags(config).invalidFormat = true;
config._d = new Date(NaN);
for (i = 0; i < config._f.length; i++) {
validFormatFound = false;
tempConfig = copyConfig({}, config);
if (config._useUTC != null) {
tempConfig._useUTC = config._useUTC;
tempConfig._f = config._f[i];
configFromStringAndFormat(tempConfig);
if (isValid(tempConfig)) {
// if there is any input that was not parsed add a penalty for that format
currentScore += getParsingFlags(tempConfig).charsLeftOver;
currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
getParsingFlags(tempConfig).score = currentScore;
if (!bestFormatIsValid) {
currentScore < scoreToBeat ||
scoreToBeat = currentScore;
bestFormatIsValid = true;
if (currentScore < scoreToBeat) {
scoreToBeat = currentScore;
extend(config, bestMoment || tempConfig);
function configFromObject(config) {
var i = normalizeObjectUnits(config._i),
dayOrDate = i.day === undefined ? i.date : i.day;
[i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
return obj && parseInt(obj, 10);
function createFromConfig(config) {
var res = new Moment(checkOverflow(prepareConfig(config)));
// Adding is smart enough around DST
res._nextDay = undefined;
function prepareConfig(config) {
config._locale = config._locale || getLocale(config._l);
if (input === null || (format === undefined && input === '')) {
return createInvalid({ nullInput: true });
if (typeof input === 'string') {
config._i = input = config._locale.preparse(input);
return new Moment(checkOverflow(input));
} else if (isDate(input)) {
} else if (isArray(format)) {
configFromStringAndArray(config);
configFromStringAndFormat(config);
function configFromInput(config) {
if (isUndefined(input)) {
config._d = new Date(hooks.now());
} else if (isDate(input)) {
config._d = new Date(input.valueOf());
} else if (typeof input === 'string') {
configFromString(config);
} else if (isArray(input)) {
config._a = map(input.slice(0), function (obj) {
return parseInt(obj, 10);
} else if (isObject(input)) {
configFromObject(config);
} else if (isNumber(input)) {
config._d = new Date(input);
hooks.createFromInputFallback(config);
function createLocalOrUTC(input, format, locale, strict, isUTC) {
if (format === true || format === false) {