for (i = 0; i < length; i++) {
output += isFunction(array[i])
? array[i].call(mom, format)
// format date using native date object
function formatMoment(m, format) {
return m.localeData().invalidDate();
format = expandFormat(format, m.localeData());
formatFunctions[format] =
formatFunctions[format] || makeFormatFunction(format);
return formatFunctions[format](m);
function expandFormat(format, locale) {
function replaceLongDateFormatTokens(input) {
return locale.longDateFormat(input) || input;
localFormattingTokens.lastIndex = 0;
while (i >= 0 && localFormattingTokens.test(format)) {
replaceLongDateFormatTokens
localFormattingTokens.lastIndex = 0;
var defaultLongDateFormat = {
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A',
function longDateFormat(key) {
var format = this._longDateFormat[key],
formatUpper = this._longDateFormat[key.toUpperCase()];
if (format || !formatUpper) {
this._longDateFormat[key] = formatUpper
return this._longDateFormat[key];
var defaultInvalidDate = 'Invalid date';
return this._invalidDate;
var defaultOrdinal = '%d',
defaultDayOfMonthOrdinalParse = /\d{1,2}/;
function ordinal(number) {
return this._ordinal.replace('%d', number);
var defaultRelativeTime = {
function relativeTime(number, withoutSuffix, string, isFuture) {
var output = this._relativeTime[string];
return isFunction(output)
? output(number, withoutSuffix, string, isFuture)
: output.replace(/%d/i, number);
function pastFuture(diff, output) {
var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
return isFunction(format) ? format(output) : format.replace(/%s/i, output);
function addUnitAlias(unit, shorthand) {
var lowerCase = unit.toLowerCase();
aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
function normalizeUnits(units) {
return typeof units === 'string'
? aliases[units] || aliases[units.toLowerCase()]
function normalizeObjectUnits(inputObject) {
var normalizedInput = {},
for (prop in inputObject) {
if (hasOwnProp(inputObject, prop)) {
normalizedProp = normalizeUnits(prop);
normalizedInput[normalizedProp] = inputObject[prop];
function addUnitPriority(unit, priority) {
priorities[unit] = priority;
function getPrioritizedUnits(unitsObj) {
if (hasOwnProp(unitsObj, u)) {
units.push({ unit: u, priority: priorities[u] });
units.sort(function (a, b) {
return a.priority - b.priority;
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
function absFloor(number) {
return Math.ceil(number) || 0;
return Math.floor(number);
function toInt(argumentForCoercion) {
var coercedNumber = +argumentForCoercion,
if (coercedNumber !== 0 && isFinite(coercedNumber)) {
value = absFloor(coercedNumber);
function makeGetSet(unit, keepTime) {
return function (value) {
set$1(this, unit, value);
hooks.updateOffset(this, keepTime);
function get(mom, unit) {
? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]()
function set$1(mom, unit, value) {
if (mom.isValid() && !isNaN(value)) {
isLeapYear(mom.year()) &&
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](
daysInMonth(value, mom.month())
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
function stringGet(units) {
units = normalizeUnits(units);
if (isFunction(this[units])) {
function stringSet(units, value) {
if (typeof units === 'object') {
units = normalizeObjectUnits(units);
var prioritized = getPrioritizedUnits(units),
for (i = 0; i < prioritized.length; i++) {
this[prioritized[i].unit](units[prioritized[i].unit]);
units = normalizeUnits(units);
if (isFunction(this[units])) {
return this[units](value);
var match1 = /\d/, // 0 - 9
match2 = /\d\d/, // 00 - 99
match3 = /\d{3}/, // 000 - 999
match4 = /\d{4}/, // 0000 - 9999
match6 = /[+-]?\d{6}/, // -999999 - 999999
match1to2 = /\d\d?/, // 0 - 99
match3to4 = /\d\d\d\d?/, // 999 - 9999
match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999
match1to3 = /\d{1,3}/, // 0 - 999
match1to4 = /\d{1,4}/, // 0 - 9999
match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
matchUnsigned = /\d+/, // 0 - inf
matchSigned = /[+-]?\d+/, // -inf - inf
matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
// any word (or two) characters or numbers including two/three word month in arabic.
// includes scottish gaelic two word and hyphenated months
matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
function addRegexToken(token, regex, strictRegex) {
regexes[token] = isFunction(regex)
: function (isStrict, localeData) {
return isStrict && strictRegex ? strictRegex : regex;
function getParseRegexForToken(token, config) {
if (!hasOwnProp(regexes, token)) {
return new RegExp(unescapeFormat(token));
return regexes[token](config._strict, config._locale);
// Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
function unescapeFormat(s) {
.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (
return p1 || p2 || p3 || p4;
function regexEscape(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
function addParseToken(token, callback) {
if (typeof token === 'string') {
if (isNumber(callback)) {
func = function (input, array) {
array[callback] = toInt(input);
for (i = 0; i < token.length; i++) {
function addWeekParseToken(token, callback) {
addParseToken(token, function (input, array, config, token) {
config._w = config._w || {};
callback(input, config._w, config, token);
function addTimeToArrayFromToken(token, input, config) {
if (input != null && hasOwnProp(tokens, token)) {
tokens[token](input, config._a, config, token);
return ((n % x) + x) % x;
if (Array.prototype.indexOf) {
indexOf = Array.prototype.indexOf;
for (i = 0; i < this.length; ++i) {
function daysInMonth(year, month) {
if (isNaN(year) || isNaN(month)) {
var modMonth = mod(month, 12);
year += (month - modMonth) / 12;
: 31 - ((modMonth % 7) % 2);
addFormatToken('M', ['MM', 2], 'Mo', function () {
addFormatToken('MMM', 0, 0, function (format) {
return this.localeData().monthsShort(this, format);
addFormatToken('MMMM', 0, 0, function (format) {
return this.localeData().months(this, format);
addUnitAlias('month', 'M');
addUnitPriority('month', 8);
addRegexToken('M', match1to2);
addRegexToken('MM', match1to2, match2);
addRegexToken('MMM', function (isStrict, locale) {
return locale.monthsShortRegex(isStrict);
addRegexToken('MMMM', function (isStrict, locale) {
return locale.monthsRegex(isStrict);
addParseToken(['M', 'MM'], function (input, array) {
array[MONTH] = toInt(input) - 1;
addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
var month = config._locale.monthsParse(input, token, config._strict);
// if we didn't find a month name, mark the date as invalid.
getParsingFlags(config).invalidMonth = input;
var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split(
MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
defaultMonthsShortRegex = matchWord,
defaultMonthsRegex = matchWord;
function localeMonths(m, format) {
return isArray(this._months)
: this._months['standalone'];
return isArray(this._months)
? this._months[m.month()]
(this._months.isFormat || MONTHS_IN_FORMAT).test(format)
function localeMonthsShort(m, format) {
return isArray(this._monthsShort)
: this._monthsShort['standalone'];
return isArray(this._monthsShort)
? this._monthsShort[m.month()]
MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'
function handleStrictParse(monthName, format, strict) {
llc = monthName.toLocaleLowerCase();
if (!this._monthsParse) {
this._longMonthsParse = [];
this._shortMonthsParse = [];
for (i = 0; i < 12; ++i) {
mom = createUTC([2000, i]);
this._shortMonthsParse[i] = this.monthsShort(