wp/wp-includes/js/dist/vendor/moment.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     1 //! moment.js
     1 //! moment.js
       
     2 //! version : 2.27.0
       
     3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
       
     4 //! license : MIT
       
     5 //! momentjs.com
     2 
     6 
     3 ;(function (global, factory) {
     7 ;(function (global, factory) {
     4     typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
     8     typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
     5     typeof define === 'function' && define.amd ? define(factory) :
     9     typeof define === 'function' && define.amd ? define(factory) :
     6     global.moment = factory()
    10     global.moment = factory()
     7 }(this, (function () { 'use strict';
    11 }(this, (function () { 'use strict';
     8 
    12 
     9     var hookCallback;
    13     var hookCallback;
    10 
    14 
    11     function hooks () {
    15     function hooks() {
    12         return hookCallback.apply(null, arguments);
    16         return hookCallback.apply(null, arguments);
    13     }
    17     }
    14 
    18 
    15     // This is done to register the method called with moment()
    19     // This is done to register the method called with moment()
    16     // without creating circular dependencies.
    20     // without creating circular dependencies.
    17     function setHookCallback (callback) {
    21     function setHookCallback(callback) {
    18         hookCallback = callback;
    22         hookCallback = callback;
    19     }
    23     }
    20 
    24 
    21     function isArray(input) {
    25     function isArray(input) {
    22         return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
    26         return (
       
    27             input instanceof Array ||
       
    28             Object.prototype.toString.call(input) === '[object Array]'
       
    29         );
    23     }
    30     }
    24 
    31 
    25     function isObject(input) {
    32     function isObject(input) {
    26         // IE8 will treat undefined and null as object if it wasn't for
    33         // IE8 will treat undefined and null as object if it wasn't for
    27         // input != null
    34         // input != null
    28         return input != null && Object.prototype.toString.call(input) === '[object Object]';
    35         return (
       
    36             input != null &&
       
    37             Object.prototype.toString.call(input) === '[object Object]'
       
    38         );
       
    39     }
       
    40 
       
    41     function hasOwnProp(a, b) {
       
    42         return Object.prototype.hasOwnProperty.call(a, b);
    29     }
    43     }
    30 
    44 
    31     function isObjectEmpty(obj) {
    45     function isObjectEmpty(obj) {
    32         if (Object.getOwnPropertyNames) {
    46         if (Object.getOwnPropertyNames) {
    33             return (Object.getOwnPropertyNames(obj).length === 0);
    47             return Object.getOwnPropertyNames(obj).length === 0;
    34         } else {
    48         } else {
    35             var k;
    49             var k;
    36             for (k in obj) {
    50             for (k in obj) {
    37                 if (obj.hasOwnProperty(k)) {
    51                 if (hasOwnProp(obj, k)) {
    38                     return false;
    52                     return false;
    39                 }
    53                 }
    40             }
    54             }
    41             return true;
    55             return true;
    42         }
    56         }
    45     function isUndefined(input) {
    59     function isUndefined(input) {
    46         return input === void 0;
    60         return input === void 0;
    47     }
    61     }
    48 
    62 
    49     function isNumber(input) {
    63     function isNumber(input) {
    50         return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
    64         return (
       
    65             typeof input === 'number' ||
       
    66             Object.prototype.toString.call(input) === '[object Number]'
       
    67         );
    51     }
    68     }
    52 
    69 
    53     function isDate(input) {
    70     function isDate(input) {
    54         return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
    71         return (
       
    72             input instanceof Date ||
       
    73             Object.prototype.toString.call(input) === '[object Date]'
       
    74         );
    55     }
    75     }
    56 
    76 
    57     function map(arr, fn) {
    77     function map(arr, fn) {
    58         var res = [], i;
    78         var res = [],
       
    79             i;
    59         for (i = 0; i < arr.length; ++i) {
    80         for (i = 0; i < arr.length; ++i) {
    60             res.push(fn(arr[i], i));
    81             res.push(fn(arr[i], i));
    61         }
    82         }
    62         return res;
    83         return res;
    63     }
       
    64 
       
    65     function hasOwnProp(a, b) {
       
    66         return Object.prototype.hasOwnProperty.call(a, b);
       
    67     }
    84     }
    68 
    85 
    69     function extend(a, b) {
    86     function extend(a, b) {
    70         for (var i in b) {
    87         for (var i in b) {
    71             if (hasOwnProp(b, i)) {
    88             if (hasOwnProp(b, i)) {
    82         }
    99         }
    83 
   100 
    84         return a;
   101         return a;
    85     }
   102     }
    86 
   103 
    87     function createUTC (input, format, locale, strict) {
   104     function createUTC(input, format, locale, strict) {
    88         return createLocalOrUTC(input, format, locale, strict, true).utc();
   105         return createLocalOrUTC(input, format, locale, strict, true).utc();
    89     }
   106     }
    90 
   107 
    91     function defaultParsingFlags() {
   108     function defaultParsingFlags() {
    92         // We need to deep clone this object.
   109         // We need to deep clone this object.
    93         return {
   110         return {
    94             empty           : false,
   111             empty: false,
    95             unusedTokens    : [],
   112             unusedTokens: [],
    96             unusedInput     : [],
   113             unusedInput: [],
    97             overflow        : -2,
   114             overflow: -2,
    98             charsLeftOver   : 0,
   115             charsLeftOver: 0,
    99             nullInput       : false,
   116             nullInput: false,
   100             invalidMonth    : null,
   117             invalidEra: null,
   101             invalidFormat   : false,
   118             invalidMonth: null,
   102             userInvalidated : false,
   119             invalidFormat: false,
   103             iso             : false,
   120             userInvalidated: false,
   104             parsedDateParts : [],
   121             iso: false,
   105             meridiem        : null,
   122             parsedDateParts: [],
   106             rfc2822         : false,
   123             era: null,
   107             weekdayMismatch : false
   124             meridiem: null,
       
   125             rfc2822: false,
       
   126             weekdayMismatch: false,
   108         };
   127         };
   109     }
   128     }
   110 
   129 
   111     function getParsingFlags(m) {
   130     function getParsingFlags(m) {
   112         if (m._pf == null) {
   131         if (m._pf == null) {
   118     var some;
   137     var some;
   119     if (Array.prototype.some) {
   138     if (Array.prototype.some) {
   120         some = Array.prototype.some;
   139         some = Array.prototype.some;
   121     } else {
   140     } else {
   122         some = function (fun) {
   141         some = function (fun) {
   123             var t = Object(this);
   142             var t = Object(this),
   124             var len = t.length >>> 0;
   143                 len = t.length >>> 0,
   125 
   144                 i;
   126             for (var i = 0; i < len; i++) {
   145 
       
   146             for (i = 0; i < len; i++) {
   127                 if (i in t && fun.call(this, t[i], i, t)) {
   147                 if (i in t && fun.call(this, t[i], i, t)) {
   128                     return true;
   148                     return true;
   129                 }
   149                 }
   130             }
   150             }
   131 
   151 
   133         };
   153         };
   134     }
   154     }
   135 
   155 
   136     function isValid(m) {
   156     function isValid(m) {
   137         if (m._isValid == null) {
   157         if (m._isValid == null) {
   138             var flags = getParsingFlags(m);
   158             var flags = getParsingFlags(m),
   139             var parsedParts = some.call(flags.parsedDateParts, function (i) {
   159                 parsedParts = some.call(flags.parsedDateParts, function (i) {
   140                 return i != null;
   160                     return i != null;
   141             });
   161                 }),
   142             var isNowValid = !isNaN(m._d.getTime()) &&
   162                 isNowValid =
   143                 flags.overflow < 0 &&
   163                     !isNaN(m._d.getTime()) &&
   144                 !flags.empty &&
   164                     flags.overflow < 0 &&
   145                 !flags.invalidMonth &&
   165                     !flags.empty &&
   146                 !flags.invalidWeekday &&
   166                     !flags.invalidEra &&
   147                 !flags.weekdayMismatch &&
   167                     !flags.invalidMonth &&
   148                 !flags.nullInput &&
   168                     !flags.invalidWeekday &&
   149                 !flags.invalidFormat &&
   169                     !flags.weekdayMismatch &&
   150                 !flags.userInvalidated &&
   170                     !flags.nullInput &&
   151                 (!flags.meridiem || (flags.meridiem && parsedParts));
   171                     !flags.invalidFormat &&
       
   172                     !flags.userInvalidated &&
       
   173                     (!flags.meridiem || (flags.meridiem && parsedParts));
   152 
   174 
   153             if (m._strict) {
   175             if (m._strict) {
   154                 isNowValid = isNowValid &&
   176                 isNowValid =
       
   177                     isNowValid &&
   155                     flags.charsLeftOver === 0 &&
   178                     flags.charsLeftOver === 0 &&
   156                     flags.unusedTokens.length === 0 &&
   179                     flags.unusedTokens.length === 0 &&
   157                     flags.bigHour === undefined;
   180                     flags.bigHour === undefined;
   158             }
   181             }
   159 
   182 
   160             if (Object.isFrozen == null || !Object.isFrozen(m)) {
   183             if (Object.isFrozen == null || !Object.isFrozen(m)) {
   161                 m._isValid = isNowValid;
   184                 m._isValid = isNowValid;
   162             }
   185             } else {
   163             else {
       
   164                 return isNowValid;
   186                 return isNowValid;
   165             }
   187             }
   166         }
   188         }
   167         return m._isValid;
   189         return m._isValid;
   168     }
   190     }
   169 
   191 
   170     function createInvalid (flags) {
   192     function createInvalid(flags) {
   171         var m = createUTC(NaN);
   193         var m = createUTC(NaN);
   172         if (flags != null) {
   194         if (flags != null) {
   173             extend(getParsingFlags(m), flags);
   195             extend(getParsingFlags(m), flags);
   174         }
   196         } else {
   175         else {
       
   176             getParsingFlags(m).userInvalidated = true;
   197             getParsingFlags(m).userInvalidated = true;
   177         }
   198         }
   178 
   199 
   179         return m;
   200         return m;
   180     }
   201     }
   181 
   202 
   182     // Plugins that add properties should also add the key here (null value),
   203     // Plugins that add properties should also add the key here (null value),
   183     // so we can properly clone ourselves.
   204     // so we can properly clone ourselves.
   184     var momentProperties = hooks.momentProperties = [];
   205     var momentProperties = (hooks.momentProperties = []),
       
   206         updateInProgress = false;
   185 
   207 
   186     function copyConfig(to, from) {
   208     function copyConfig(to, from) {
   187         var i, prop, val;
   209         var i, prop, val;
   188 
   210 
   189         if (!isUndefined(from._isAMomentObject)) {
   211         if (!isUndefined(from._isAMomentObject)) {
   228         }
   250         }
   229 
   251 
   230         return to;
   252         return to;
   231     }
   253     }
   232 
   254 
   233     var updateInProgress = false;
       
   234 
       
   235     // Moment prototype object
   255     // Moment prototype object
   236     function Moment(config) {
   256     function Moment(config) {
   237         copyConfig(this, config);
   257         copyConfig(this, config);
   238         this._d = new Date(config._d != null ? config._d.getTime() : NaN);
   258         this._d = new Date(config._d != null ? config._d.getTime() : NaN);
   239         if (!this.isValid()) {
   259         if (!this.isValid()) {
   246             hooks.updateOffset(this);
   266             hooks.updateOffset(this);
   247             updateInProgress = false;
   267             updateInProgress = false;
   248         }
   268         }
   249     }
   269     }
   250 
   270 
   251     function isMoment (obj) {
   271     function isMoment(obj) {
   252         return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
   272         return (
   253     }
   273             obj instanceof Moment || (obj != null && obj._isAMomentObject != null)
   254 
   274         );
   255     function absFloor (number) {
       
   256         if (number < 0) {
       
   257             // -0 -> 0
       
   258             return Math.ceil(number) || 0;
       
   259         } else {
       
   260             return Math.floor(number);
       
   261         }
       
   262     }
       
   263 
       
   264     function toInt(argumentForCoercion) {
       
   265         var coercedNumber = +argumentForCoercion,
       
   266             value = 0;
       
   267 
       
   268         if (coercedNumber !== 0 && isFinite(coercedNumber)) {
       
   269             value = absFloor(coercedNumber);
       
   270         }
       
   271 
       
   272         return value;
       
   273     }
       
   274 
       
   275     // compare two arrays, return the number of differences
       
   276     function compareArrays(array1, array2, dontConvert) {
       
   277         var len = Math.min(array1.length, array2.length),
       
   278             lengthDiff = Math.abs(array1.length - array2.length),
       
   279             diffs = 0,
       
   280             i;
       
   281         for (i = 0; i < len; i++) {
       
   282             if ((dontConvert && array1[i] !== array2[i]) ||
       
   283                 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
       
   284                 diffs++;
       
   285             }
       
   286         }
       
   287         return diffs + lengthDiff;
       
   288     }
   275     }
   289 
   276 
   290     function warn(msg) {
   277     function warn(msg) {
   291         if (hooks.suppressDeprecationWarnings === false &&
   278         if (
   292                 (typeof console !==  'undefined') && console.warn) {
   279             hooks.suppressDeprecationWarnings === false &&
       
   280             typeof console !== 'undefined' &&
       
   281             console.warn
       
   282         ) {
   293             console.warn('Deprecation warning: ' + msg);
   283             console.warn('Deprecation warning: ' + msg);
   294         }
   284         }
   295     }
   285     }
   296 
   286 
   297     function deprecate(msg, fn) {
   287     function deprecate(msg, fn) {
   300         return extend(function () {
   290         return extend(function () {
   301             if (hooks.deprecationHandler != null) {
   291             if (hooks.deprecationHandler != null) {
   302                 hooks.deprecationHandler(null, msg);
   292                 hooks.deprecationHandler(null, msg);
   303             }
   293             }
   304             if (firstTime) {
   294             if (firstTime) {
   305                 var args = [];
   295                 var args = [],
   306                 var arg;
   296                     arg,
   307                 for (var i = 0; i < arguments.length; i++) {
   297                     i,
       
   298                     key;
       
   299                 for (i = 0; i < arguments.length; i++) {
   308                     arg = '';
   300                     arg = '';
   309                     if (typeof arguments[i] === 'object') {
   301                     if (typeof arguments[i] === 'object') {
   310                         arg += '\n[' + i + '] ';
   302                         arg += '\n[' + i + '] ';
   311                         for (var key in arguments[0]) {
   303                         for (key in arguments[0]) {
   312                             arg += key + ': ' + arguments[0][key] + ', ';
   304                             if (hasOwnProp(arguments[0], key)) {
       
   305                                 arg += key + ': ' + arguments[0][key] + ', ';
       
   306                             }
   313                         }
   307                         }
   314                         arg = arg.slice(0, -2); // Remove trailing comma and space
   308                         arg = arg.slice(0, -2); // Remove trailing comma and space
   315                     } else {
   309                     } else {
   316                         arg = arguments[i];
   310                         arg = arguments[i];
   317                     }
   311                     }
   318                     args.push(arg);
   312                     args.push(arg);
   319                 }
   313                 }
   320                 warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
   314                 warn(
       
   315                     msg +
       
   316                         '\nArguments: ' +
       
   317                         Array.prototype.slice.call(args).join('') +
       
   318                         '\n' +
       
   319                         new Error().stack
       
   320                 );
   321                 firstTime = false;
   321                 firstTime = false;
   322             }
   322             }
   323             return fn.apply(this, arguments);
   323             return fn.apply(this, arguments);
   324         }, fn);
   324         }, fn);
   325     }
   325     }
   338 
   338 
   339     hooks.suppressDeprecationWarnings = false;
   339     hooks.suppressDeprecationWarnings = false;
   340     hooks.deprecationHandler = null;
   340     hooks.deprecationHandler = null;
   341 
   341 
   342     function isFunction(input) {
   342     function isFunction(input) {
   343         return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
   343         return (
   344     }
   344             (typeof Function !== 'undefined' && input instanceof Function) ||
   345 
   345             Object.prototype.toString.call(input) === '[object Function]'
   346     function set (config) {
   346         );
       
   347     }
       
   348 
       
   349     function set(config) {
   347         var prop, i;
   350         var prop, i;
   348         for (i in config) {
   351         for (i in config) {
   349             prop = config[i];
   352             if (hasOwnProp(config, i)) {
   350             if (isFunction(prop)) {
   353                 prop = config[i];
   351                 this[i] = prop;
   354                 if (isFunction(prop)) {
   352             } else {
   355                     this[i] = prop;
   353                 this['_' + i] = prop;
   356                 } else {
       
   357                     this['_' + i] = prop;
       
   358                 }
   354             }
   359             }
   355         }
   360         }
   356         this._config = config;
   361         this._config = config;
   357         // Lenient ordinal parsing accepts just a number in addition to
   362         // Lenient ordinal parsing accepts just a number in addition to
   358         // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
   363         // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
   359         // TODO: Remove "ordinalParse" fallback in next major release.
   364         // TODO: Remove "ordinalParse" fallback in next major release.
   360         this._dayOfMonthOrdinalParseLenient = new RegExp(
   365         this._dayOfMonthOrdinalParseLenient = new RegExp(
   361             (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
   366             (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
   362                 '|' + (/\d{1,2}/).source);
   367                 '|' +
       
   368                 /\d{1,2}/.source
       
   369         );
   363     }
   370     }
   364 
   371 
   365     function mergeConfigs(parentConfig, childConfig) {
   372     function mergeConfigs(parentConfig, childConfig) {
   366         var res = extend({}, parentConfig), prop;
   373         var res = extend({}, parentConfig),
       
   374             prop;
   367         for (prop in childConfig) {
   375         for (prop in childConfig) {
   368             if (hasOwnProp(childConfig, prop)) {
   376             if (hasOwnProp(childConfig, prop)) {
   369                 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
   377                 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
   370                     res[prop] = {};
   378                     res[prop] = {};
   371                     extend(res[prop], parentConfig[prop]);
   379                     extend(res[prop], parentConfig[prop]);
   376                     delete res[prop];
   384                     delete res[prop];
   377                 }
   385                 }
   378             }
   386             }
   379         }
   387         }
   380         for (prop in parentConfig) {
   388         for (prop in parentConfig) {
   381             if (hasOwnProp(parentConfig, prop) &&
   389             if (
   382                     !hasOwnProp(childConfig, prop) &&
   390                 hasOwnProp(parentConfig, prop) &&
   383                     isObject(parentConfig[prop])) {
   391                 !hasOwnProp(childConfig, prop) &&
       
   392                 isObject(parentConfig[prop])
       
   393             ) {
   384                 // make sure changes to properties don't modify parent config
   394                 // make sure changes to properties don't modify parent config
   385                 res[prop] = extend({}, res[prop]);
   395                 res[prop] = extend({}, res[prop]);
   386             }
   396             }
   387         }
   397         }
   388         return res;
   398         return res;
   398 
   408 
   399     if (Object.keys) {
   409     if (Object.keys) {
   400         keys = Object.keys;
   410         keys = Object.keys;
   401     } else {
   411     } else {
   402         keys = function (obj) {
   412         keys = function (obj) {
   403             var i, res = [];
   413             var i,
       
   414                 res = [];
   404             for (i in obj) {
   415             for (i in obj) {
   405                 if (hasOwnProp(obj, i)) {
   416                 if (hasOwnProp(obj, i)) {
   406                     res.push(i);
   417                     res.push(i);
   407                 }
   418                 }
   408             }
   419             }
   409             return res;
   420             return res;
   410         };
   421         };
   411     }
   422     }
   412 
   423 
   413     var defaultCalendar = {
   424     var defaultCalendar = {
   414         sameDay : '[Today at] LT',
   425         sameDay: '[Today at] LT',
   415         nextDay : '[Tomorrow at] LT',
   426         nextDay: '[Tomorrow at] LT',
   416         nextWeek : 'dddd [at] LT',
   427         nextWeek: 'dddd [at] LT',
   417         lastDay : '[Yesterday at] LT',
   428         lastDay: '[Yesterday at] LT',
   418         lastWeek : '[Last] dddd [at] LT',
   429         lastWeek: '[Last] dddd [at] LT',
   419         sameElse : 'L'
   430         sameElse: 'L',
   420     };
   431     };
   421 
   432 
   422     function calendar (key, mom, now) {
   433     function calendar(key, mom, now) {
   423         var output = this._calendar[key] || this._calendar['sameElse'];
   434         var output = this._calendar[key] || this._calendar['sameElse'];
   424         return isFunction(output) ? output.call(mom, now) : output;
   435         return isFunction(output) ? output.call(mom, now) : output;
   425     }
   436     }
   426 
   437 
       
   438     function zeroFill(number, targetLength, forceSign) {
       
   439         var absNumber = '' + Math.abs(number),
       
   440             zerosToFill = targetLength - absNumber.length,
       
   441             sign = number >= 0;
       
   442         return (
       
   443             (sign ? (forceSign ? '+' : '') : '-') +
       
   444             Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) +
       
   445             absNumber
       
   446         );
       
   447     }
       
   448 
       
   449     var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
       
   450         localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
       
   451         formatFunctions = {},
       
   452         formatTokenFunctions = {};
       
   453 
       
   454     // token:    'M'
       
   455     // padded:   ['MM', 2]
       
   456     // ordinal:  'Mo'
       
   457     // callback: function () { this.month() + 1 }
       
   458     function addFormatToken(token, padded, ordinal, callback) {
       
   459         var func = callback;
       
   460         if (typeof callback === 'string') {
       
   461             func = function () {
       
   462                 return this[callback]();
       
   463             };
       
   464         }
       
   465         if (token) {
       
   466             formatTokenFunctions[token] = func;
       
   467         }
       
   468         if (padded) {
       
   469             formatTokenFunctions[padded[0]] = function () {
       
   470                 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
       
   471             };
       
   472         }
       
   473         if (ordinal) {
       
   474             formatTokenFunctions[ordinal] = function () {
       
   475                 return this.localeData().ordinal(
       
   476                     func.apply(this, arguments),
       
   477                     token
       
   478                 );
       
   479             };
       
   480         }
       
   481     }
       
   482 
       
   483     function removeFormattingTokens(input) {
       
   484         if (input.match(/\[[\s\S]/)) {
       
   485             return input.replace(/^\[|\]$/g, '');
       
   486         }
       
   487         return input.replace(/\\/g, '');
       
   488     }
       
   489 
       
   490     function makeFormatFunction(format) {
       
   491         var array = format.match(formattingTokens),
       
   492             i,
       
   493             length;
       
   494 
       
   495         for (i = 0, length = array.length; i < length; i++) {
       
   496             if (formatTokenFunctions[array[i]]) {
       
   497                 array[i] = formatTokenFunctions[array[i]];
       
   498             } else {
       
   499                 array[i] = removeFormattingTokens(array[i]);
       
   500             }
       
   501         }
       
   502 
       
   503         return function (mom) {
       
   504             var output = '',
       
   505                 i;
       
   506             for (i = 0; i < length; i++) {
       
   507                 output += isFunction(array[i])
       
   508                     ? array[i].call(mom, format)
       
   509                     : array[i];
       
   510             }
       
   511             return output;
       
   512         };
       
   513     }
       
   514 
       
   515     // format date using native date object
       
   516     function formatMoment(m, format) {
       
   517         if (!m.isValid()) {
       
   518             return m.localeData().invalidDate();
       
   519         }
       
   520 
       
   521         format = expandFormat(format, m.localeData());
       
   522         formatFunctions[format] =
       
   523             formatFunctions[format] || makeFormatFunction(format);
       
   524 
       
   525         return formatFunctions[format](m);
       
   526     }
       
   527 
       
   528     function expandFormat(format, locale) {
       
   529         var i = 5;
       
   530 
       
   531         function replaceLongDateFormatTokens(input) {
       
   532             return locale.longDateFormat(input) || input;
       
   533         }
       
   534 
       
   535         localFormattingTokens.lastIndex = 0;
       
   536         while (i >= 0 && localFormattingTokens.test(format)) {
       
   537             format = format.replace(
       
   538                 localFormattingTokens,
       
   539                 replaceLongDateFormatTokens
       
   540             );
       
   541             localFormattingTokens.lastIndex = 0;
       
   542             i -= 1;
       
   543         }
       
   544 
       
   545         return format;
       
   546     }
       
   547 
   427     var defaultLongDateFormat = {
   548     var defaultLongDateFormat = {
   428         LTS  : 'h:mm:ss A',
   549         LTS: 'h:mm:ss A',
   429         LT   : 'h:mm A',
   550         LT: 'h:mm A',
   430         L    : 'MM/DD/YYYY',
   551         L: 'MM/DD/YYYY',
   431         LL   : 'MMMM D, YYYY',
   552         LL: 'MMMM D, YYYY',
   432         LLL  : 'MMMM D, YYYY h:mm A',
   553         LLL: 'MMMM D, YYYY h:mm A',
   433         LLLL : 'dddd, MMMM D, YYYY h:mm A'
   554         LLLL: 'dddd, MMMM D, YYYY h:mm A',
   434     };
   555     };
   435 
   556 
   436     function longDateFormat (key) {
   557     function longDateFormat(key) {
   437         var format = this._longDateFormat[key],
   558         var format = this._longDateFormat[key],
   438             formatUpper = this._longDateFormat[key.toUpperCase()];
   559             formatUpper = this._longDateFormat[key.toUpperCase()];
   439 
   560 
   440         if (format || !formatUpper) {
   561         if (format || !formatUpper) {
   441             return format;
   562             return format;
   442         }
   563         }
   443 
   564 
   444         this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
   565         this._longDateFormat[key] = formatUpper
   445             return val.slice(1);
   566             .match(formattingTokens)
   446         });
   567             .map(function (tok) {
       
   568                 if (
       
   569                     tok === 'MMMM' ||
       
   570                     tok === 'MM' ||
       
   571                     tok === 'DD' ||
       
   572                     tok === 'dddd'
       
   573                 ) {
       
   574                     return tok.slice(1);
       
   575                 }
       
   576                 return tok;
       
   577             })
       
   578             .join('');
   447 
   579 
   448         return this._longDateFormat[key];
   580         return this._longDateFormat[key];
   449     }
   581     }
   450 
   582 
   451     var defaultInvalidDate = 'Invalid date';
   583     var defaultInvalidDate = 'Invalid date';
   452 
   584 
   453     function invalidDate () {
   585     function invalidDate() {
   454         return this._invalidDate;
   586         return this._invalidDate;
   455     }
   587     }
   456 
   588 
   457     var defaultOrdinal = '%d';
   589     var defaultOrdinal = '%d',
   458     var defaultDayOfMonthOrdinalParse = /\d{1,2}/;
   590         defaultDayOfMonthOrdinalParse = /\d{1,2}/;
   459 
   591 
   460     function ordinal (number) {
   592     function ordinal(number) {
   461         return this._ordinal.replace('%d', number);
   593         return this._ordinal.replace('%d', number);
   462     }
   594     }
   463 
   595 
   464     var defaultRelativeTime = {
   596     var defaultRelativeTime = {
   465         future : 'in %s',
   597         future: 'in %s',
   466         past   : '%s ago',
   598         past: '%s ago',
   467         s  : 'a few seconds',
   599         s: 'a few seconds',
   468         ss : '%d seconds',
   600         ss: '%d seconds',
   469         m  : 'a minute',
   601         m: 'a minute',
   470         mm : '%d minutes',
   602         mm: '%d minutes',
   471         h  : 'an hour',
   603         h: 'an hour',
   472         hh : '%d hours',
   604         hh: '%d hours',
   473         d  : 'a day',
   605         d: 'a day',
   474         dd : '%d days',
   606         dd: '%d days',
   475         M  : 'a month',
   607         w: 'a week',
   476         MM : '%d months',
   608         ww: '%d weeks',
   477         y  : 'a year',
   609         M: 'a month',
   478         yy : '%d years'
   610         MM: '%d months',
       
   611         y: 'a year',
       
   612         yy: '%d years',
   479     };
   613     };
   480 
   614 
   481     function relativeTime (number, withoutSuffix, string, isFuture) {
   615     function relativeTime(number, withoutSuffix, string, isFuture) {
   482         var output = this._relativeTime[string];
   616         var output = this._relativeTime[string];
   483         return (isFunction(output)) ?
   617         return isFunction(output)
   484             output(number, withoutSuffix, string, isFuture) :
   618             ? output(number, withoutSuffix, string, isFuture)
   485             output.replace(/%d/i, number);
   619             : output.replace(/%d/i, number);
   486     }
   620     }
   487 
   621 
   488     function pastFuture (diff, output) {
   622     function pastFuture(diff, output) {
   489         var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
   623         var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
   490         return isFunction(format) ? format(output) : format.replace(/%s/i, output);
   624         return isFunction(format) ? format(output) : format.replace(/%s/i, output);
   491     }
   625     }
   492 
   626 
   493     var aliases = {};
   627     var aliases = {};
   494 
   628 
   495     function addUnitAlias (unit, shorthand) {
   629     function addUnitAlias(unit, shorthand) {
   496         var lowerCase = unit.toLowerCase();
   630         var lowerCase = unit.toLowerCase();
   497         aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
   631         aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
   498     }
   632     }
   499 
   633 
   500     function normalizeUnits(units) {
   634     function normalizeUnits(units) {
   501         return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
   635         return typeof units === 'string'
       
   636             ? aliases[units] || aliases[units.toLowerCase()]
       
   637             : undefined;
   502     }
   638     }
   503 
   639 
   504     function normalizeObjectUnits(inputObject) {
   640     function normalizeObjectUnits(inputObject) {
   505         var normalizedInput = {},
   641         var normalizedInput = {},
   506             normalizedProp,
   642             normalizedProp,
   523     function addUnitPriority(unit, priority) {
   659     function addUnitPriority(unit, priority) {
   524         priorities[unit] = priority;
   660         priorities[unit] = priority;
   525     }
   661     }
   526 
   662 
   527     function getPrioritizedUnits(unitsObj) {
   663     function getPrioritizedUnits(unitsObj) {
   528         var units = [];
   664         var units = [],
   529         for (var u in unitsObj) {
   665             u;
   530             units.push({unit: u, priority: priorities[u]});
   666         for (u in unitsObj) {
       
   667             if (hasOwnProp(unitsObj, u)) {
       
   668                 units.push({ unit: u, priority: priorities[u] });
       
   669             }
   531         }
   670         }
   532         units.sort(function (a, b) {
   671         units.sort(function (a, b) {
   533             return a.priority - b.priority;
   672             return a.priority - b.priority;
   534         });
   673         });
   535         return units;
   674         return units;
   536     }
   675     }
   537 
   676 
   538     function zeroFill(number, targetLength, forceSign) {
       
   539         var absNumber = '' + Math.abs(number),
       
   540             zerosToFill = targetLength - absNumber.length,
       
   541             sign = number >= 0;
       
   542         return (sign ? (forceSign ? '+' : '') : '-') +
       
   543             Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
       
   544     }
       
   545 
       
   546     var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
       
   547 
       
   548     var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
       
   549 
       
   550     var formatFunctions = {};
       
   551 
       
   552     var formatTokenFunctions = {};
       
   553 
       
   554     // token:    'M'
       
   555     // padded:   ['MM', 2]
       
   556     // ordinal:  'Mo'
       
   557     // callback: function () { this.month() + 1 }
       
   558     function addFormatToken (token, padded, ordinal, callback) {
       
   559         var func = callback;
       
   560         if (typeof callback === 'string') {
       
   561             func = function () {
       
   562                 return this[callback]();
       
   563             };
       
   564         }
       
   565         if (token) {
       
   566             formatTokenFunctions[token] = func;
       
   567         }
       
   568         if (padded) {
       
   569             formatTokenFunctions[padded[0]] = function () {
       
   570                 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
       
   571             };
       
   572         }
       
   573         if (ordinal) {
       
   574             formatTokenFunctions[ordinal] = function () {
       
   575                 return this.localeData().ordinal(func.apply(this, arguments), token);
       
   576             };
       
   577         }
       
   578     }
       
   579 
       
   580     function removeFormattingTokens(input) {
       
   581         if (input.match(/\[[\s\S]/)) {
       
   582             return input.replace(/^\[|\]$/g, '');
       
   583         }
       
   584         return input.replace(/\\/g, '');
       
   585     }
       
   586 
       
   587     function makeFormatFunction(format) {
       
   588         var array = format.match(formattingTokens), i, length;
       
   589 
       
   590         for (i = 0, length = array.length; i < length; i++) {
       
   591             if (formatTokenFunctions[array[i]]) {
       
   592                 array[i] = formatTokenFunctions[array[i]];
       
   593             } else {
       
   594                 array[i] = removeFormattingTokens(array[i]);
       
   595             }
       
   596         }
       
   597 
       
   598         return function (mom) {
       
   599             var output = '', i;
       
   600             for (i = 0; i < length; i++) {
       
   601                 output += isFunction(array[i]) ? array[i].call(mom, format) : array[i];
       
   602             }
       
   603             return output;
       
   604         };
       
   605     }
       
   606 
       
   607     // format date using native date object
       
   608     function formatMoment(m, format) {
       
   609         if (!m.isValid()) {
       
   610             return m.localeData().invalidDate();
       
   611         }
       
   612 
       
   613         format = expandFormat(format, m.localeData());
       
   614         formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
       
   615 
       
   616         return formatFunctions[format](m);
       
   617     }
       
   618 
       
   619     function expandFormat(format, locale) {
       
   620         var i = 5;
       
   621 
       
   622         function replaceLongDateFormatTokens(input) {
       
   623             return locale.longDateFormat(input) || input;
       
   624         }
       
   625 
       
   626         localFormattingTokens.lastIndex = 0;
       
   627         while (i >= 0 && localFormattingTokens.test(format)) {
       
   628             format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
       
   629             localFormattingTokens.lastIndex = 0;
       
   630             i -= 1;
       
   631         }
       
   632 
       
   633         return format;
       
   634     }
       
   635 
       
   636     var match1         = /\d/;            //       0 - 9
       
   637     var match2         = /\d\d/;          //      00 - 99
       
   638     var match3         = /\d{3}/;         //     000 - 999
       
   639     var match4         = /\d{4}/;         //    0000 - 9999
       
   640     var match6         = /[+-]?\d{6}/;    // -999999 - 999999
       
   641     var match1to2      = /\d\d?/;         //       0 - 99
       
   642     var match3to4      = /\d\d\d\d?/;     //     999 - 9999
       
   643     var match5to6      = /\d\d\d\d\d\d?/; //   99999 - 999999
       
   644     var match1to3      = /\d{1,3}/;       //       0 - 999
       
   645     var match1to4      = /\d{1,4}/;       //       0 - 9999
       
   646     var match1to6      = /[+-]?\d{1,6}/;  // -999999 - 999999
       
   647 
       
   648     var matchUnsigned  = /\d+/;           //       0 - inf
       
   649     var matchSigned    = /[+-]?\d+/;      //    -inf - inf
       
   650 
       
   651     var matchOffset    = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
       
   652     var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
       
   653 
       
   654     var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
       
   655 
       
   656     // any word (or two) characters or numbers including two/three word month in arabic.
       
   657     // includes scottish gaelic two word and hyphenated months
       
   658     var 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;
       
   659 
       
   660     var regexes = {};
       
   661 
       
   662     function addRegexToken (token, regex, strictRegex) {
       
   663         regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
       
   664             return (isStrict && strictRegex) ? strictRegex : regex;
       
   665         };
       
   666     }
       
   667 
       
   668     function getParseRegexForToken (token, config) {
       
   669         if (!hasOwnProp(regexes, token)) {
       
   670             return new RegExp(unescapeFormat(token));
       
   671         }
       
   672 
       
   673         return regexes[token](config._strict, config._locale);
       
   674     }
       
   675 
       
   676     // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
       
   677     function unescapeFormat(s) {
       
   678         return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
       
   679             return p1 || p2 || p3 || p4;
       
   680         }));
       
   681     }
       
   682 
       
   683     function regexEscape(s) {
       
   684         return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
       
   685     }
       
   686 
       
   687     var tokens = {};
       
   688 
       
   689     function addParseToken (token, callback) {
       
   690         var i, func = callback;
       
   691         if (typeof token === 'string') {
       
   692             token = [token];
       
   693         }
       
   694         if (isNumber(callback)) {
       
   695             func = function (input, array) {
       
   696                 array[callback] = toInt(input);
       
   697             };
       
   698         }
       
   699         for (i = 0; i < token.length; i++) {
       
   700             tokens[token[i]] = func;
       
   701         }
       
   702     }
       
   703 
       
   704     function addWeekParseToken (token, callback) {
       
   705         addParseToken(token, function (input, array, config, token) {
       
   706             config._w = config._w || {};
       
   707             callback(input, config._w, config, token);
       
   708         });
       
   709     }
       
   710 
       
   711     function addTimeToArrayFromToken(token, input, config) {
       
   712         if (input != null && hasOwnProp(tokens, token)) {
       
   713             tokens[token](input, config._a, config, token);
       
   714         }
       
   715     }
       
   716 
       
   717     var YEAR = 0;
       
   718     var MONTH = 1;
       
   719     var DATE = 2;
       
   720     var HOUR = 3;
       
   721     var MINUTE = 4;
       
   722     var SECOND = 5;
       
   723     var MILLISECOND = 6;
       
   724     var WEEK = 7;
       
   725     var WEEKDAY = 8;
       
   726 
       
   727     // FORMATTING
       
   728 
       
   729     addFormatToken('Y', 0, 0, function () {
       
   730         var y = this.year();
       
   731         return y <= 9999 ? '' + y : '+' + y;
       
   732     });
       
   733 
       
   734     addFormatToken(0, ['YY', 2], 0, function () {
       
   735         return this.year() % 100;
       
   736     });
       
   737 
       
   738     addFormatToken(0, ['YYYY',   4],       0, 'year');
       
   739     addFormatToken(0, ['YYYYY',  5],       0, 'year');
       
   740     addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
       
   741 
       
   742     // ALIASES
       
   743 
       
   744     addUnitAlias('year', 'y');
       
   745 
       
   746     // PRIORITIES
       
   747 
       
   748     addUnitPriority('year', 1);
       
   749 
       
   750     // PARSING
       
   751 
       
   752     addRegexToken('Y',      matchSigned);
       
   753     addRegexToken('YY',     match1to2, match2);
       
   754     addRegexToken('YYYY',   match1to4, match4);
       
   755     addRegexToken('YYYYY',  match1to6, match6);
       
   756     addRegexToken('YYYYYY', match1to6, match6);
       
   757 
       
   758     addParseToken(['YYYYY', 'YYYYYY'], YEAR);
       
   759     addParseToken('YYYY', function (input, array) {
       
   760         array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
       
   761     });
       
   762     addParseToken('YY', function (input, array) {
       
   763         array[YEAR] = hooks.parseTwoDigitYear(input);
       
   764     });
       
   765     addParseToken('Y', function (input, array) {
       
   766         array[YEAR] = parseInt(input, 10);
       
   767     });
       
   768 
       
   769     // HELPERS
       
   770 
       
   771     function daysInYear(year) {
       
   772         return isLeapYear(year) ? 366 : 365;
       
   773     }
       
   774 
       
   775     function isLeapYear(year) {
   677     function isLeapYear(year) {
   776         return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
   678         return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
   777     }
   679     }
   778 
   680 
   779     // HOOKS
   681     function absFloor(number) {
   780 
   682         if (number < 0) {
   781     hooks.parseTwoDigitYear = function (input) {
   683             // -0 -> 0
   782         return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
   684             return Math.ceil(number) || 0;
   783     };
   685         } else {
   784 
   686             return Math.floor(number);
   785     // MOMENTS
   687         }
   786 
   688     }
   787     var getSetYear = makeGetSet('FullYear', true);
   689 
   788 
   690     function toInt(argumentForCoercion) {
   789     function getIsLeapYear () {
   691         var coercedNumber = +argumentForCoercion,
   790         return isLeapYear(this.year());
   692             value = 0;
   791     }
   693 
   792 
   694         if (coercedNumber !== 0 && isFinite(coercedNumber)) {
   793     function makeGetSet (unit, keepTime) {
   695             value = absFloor(coercedNumber);
       
   696         }
       
   697 
       
   698         return value;
       
   699     }
       
   700 
       
   701     function makeGetSet(unit, keepTime) {
   794         return function (value) {
   702         return function (value) {
   795             if (value != null) {
   703             if (value != null) {
   796                 set$1(this, unit, value);
   704                 set$1(this, unit, value);
   797                 hooks.updateOffset(this, keepTime);
   705                 hooks.updateOffset(this, keepTime);
   798                 return this;
   706                 return this;
   800                 return get(this, unit);
   708                 return get(this, unit);
   801             }
   709             }
   802         };
   710         };
   803     }
   711     }
   804 
   712 
   805     function get (mom, unit) {
   713     function get(mom, unit) {
   806         return mom.isValid() ?
   714         return mom.isValid()
   807             mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
   715             ? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]()
   808     }
   716             : NaN;
   809 
   717     }
   810     function set$1 (mom, unit, value) {
   718 
       
   719     function set$1(mom, unit, value) {
   811         if (mom.isValid() && !isNaN(value)) {
   720         if (mom.isValid() && !isNaN(value)) {
   812             if (unit === 'FullYear' && isLeapYear(mom.year()) && mom.month() === 1 && mom.date() === 29) {
   721             if (
   813                 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value, mom.month(), daysInMonth(value, mom.month()));
   722                 unit === 'FullYear' &&
   814             }
   723                 isLeapYear(mom.year()) &&
   815             else {
   724                 mom.month() === 1 &&
       
   725                 mom.date() === 29
       
   726             ) {
       
   727                 value = toInt(value);
       
   728                 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](
       
   729                     value,
       
   730                     mom.month(),
       
   731                     daysInMonth(value, mom.month())
       
   732                 );
       
   733             } else {
   816                 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
   734                 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
   817             }
   735             }
   818         }
   736         }
   819     }
   737     }
   820 
   738 
   821     // MOMENTS
   739     // MOMENTS
   822 
   740 
   823     function stringGet (units) {
   741     function stringGet(units) {
   824         units = normalizeUnits(units);
   742         units = normalizeUnits(units);
   825         if (isFunction(this[units])) {
   743         if (isFunction(this[units])) {
   826             return this[units]();
   744             return this[units]();
   827         }
   745         }
   828         return this;
   746         return this;
   829     }
   747     }
   830 
   748 
   831 
   749     function stringSet(units, value) {
   832     function stringSet (units, value) {
       
   833         if (typeof units === 'object') {
   750         if (typeof units === 'object') {
   834             units = normalizeObjectUnits(units);
   751             units = normalizeObjectUnits(units);
   835             var prioritized = getPrioritizedUnits(units);
   752             var prioritized = getPrioritizedUnits(units),
   836             for (var i = 0; i < prioritized.length; i++) {
   753                 i;
       
   754             for (i = 0; i < prioritized.length; i++) {
   837                 this[prioritized[i].unit](units[prioritized[i].unit]);
   755                 this[prioritized[i].unit](units[prioritized[i].unit]);
   838             }
   756             }
   839         } else {
   757         } else {
   840             units = normalizeUnits(units);
   758             units = normalizeUnits(units);
   841             if (isFunction(this[units])) {
   759             if (isFunction(this[units])) {
   842                 return this[units](value);
   760                 return this[units](value);
   843             }
   761             }
   844         }
   762         }
   845         return this;
   763         return this;
   846     }
   764     }
       
   765 
       
   766     var match1 = /\d/, //       0 - 9
       
   767         match2 = /\d\d/, //      00 - 99
       
   768         match3 = /\d{3}/, //     000 - 999
       
   769         match4 = /\d{4}/, //    0000 - 9999
       
   770         match6 = /[+-]?\d{6}/, // -999999 - 999999
       
   771         match1to2 = /\d\d?/, //       0 - 99
       
   772         match3to4 = /\d\d\d\d?/, //     999 - 9999
       
   773         match5to6 = /\d\d\d\d\d\d?/, //   99999 - 999999
       
   774         match1to3 = /\d{1,3}/, //       0 - 999
       
   775         match1to4 = /\d{1,4}/, //       0 - 9999
       
   776         match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
       
   777         matchUnsigned = /\d+/, //       0 - inf
       
   778         matchSigned = /[+-]?\d+/, //    -inf - inf
       
   779         matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
       
   780         matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
       
   781         matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
       
   782         // any word (or two) characters or numbers including two/three word month in arabic.
       
   783         // includes scottish gaelic two word and hyphenated months
       
   784         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,
       
   785         regexes;
       
   786 
       
   787     regexes = {};
       
   788 
       
   789     function addRegexToken(token, regex, strictRegex) {
       
   790         regexes[token] = isFunction(regex)
       
   791             ? regex
       
   792             : function (isStrict, localeData) {
       
   793                   return isStrict && strictRegex ? strictRegex : regex;
       
   794               };
       
   795     }
       
   796 
       
   797     function getParseRegexForToken(token, config) {
       
   798         if (!hasOwnProp(regexes, token)) {
       
   799             return new RegExp(unescapeFormat(token));
       
   800         }
       
   801 
       
   802         return regexes[token](config._strict, config._locale);
       
   803     }
       
   804 
       
   805     // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
       
   806     function unescapeFormat(s) {
       
   807         return regexEscape(
       
   808             s
       
   809                 .replace('\\', '')
       
   810                 .replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (
       
   811                     matched,
       
   812                     p1,
       
   813                     p2,
       
   814                     p3,
       
   815                     p4
       
   816                 ) {
       
   817                     return p1 || p2 || p3 || p4;
       
   818                 })
       
   819         );
       
   820     }
       
   821 
       
   822     function regexEscape(s) {
       
   823         return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
       
   824     }
       
   825 
       
   826     var tokens = {};
       
   827 
       
   828     function addParseToken(token, callback) {
       
   829         var i,
       
   830             func = callback;
       
   831         if (typeof token === 'string') {
       
   832             token = [token];
       
   833         }
       
   834         if (isNumber(callback)) {
       
   835             func = function (input, array) {
       
   836                 array[callback] = toInt(input);
       
   837             };
       
   838         }
       
   839         for (i = 0; i < token.length; i++) {
       
   840             tokens[token[i]] = func;
       
   841         }
       
   842     }
       
   843 
       
   844     function addWeekParseToken(token, callback) {
       
   845         addParseToken(token, function (input, array, config, token) {
       
   846             config._w = config._w || {};
       
   847             callback(input, config._w, config, token);
       
   848         });
       
   849     }
       
   850 
       
   851     function addTimeToArrayFromToken(token, input, config) {
       
   852         if (input != null && hasOwnProp(tokens, token)) {
       
   853             tokens[token](input, config._a, config, token);
       
   854         }
       
   855     }
       
   856 
       
   857     var YEAR = 0,
       
   858         MONTH = 1,
       
   859         DATE = 2,
       
   860         HOUR = 3,
       
   861         MINUTE = 4,
       
   862         SECOND = 5,
       
   863         MILLISECOND = 6,
       
   864         WEEK = 7,
       
   865         WEEKDAY = 8;
   847 
   866 
   848     function mod(n, x) {
   867     function mod(n, x) {
   849         return ((n % x) + x) % x;
   868         return ((n % x) + x) % x;
   850     }
   869     }
   851 
   870 
   870         if (isNaN(year) || isNaN(month)) {
   889         if (isNaN(year) || isNaN(month)) {
   871             return NaN;
   890             return NaN;
   872         }
   891         }
   873         var modMonth = mod(month, 12);
   892         var modMonth = mod(month, 12);
   874         year += (month - modMonth) / 12;
   893         year += (month - modMonth) / 12;
   875         return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2);
   894         return modMonth === 1
       
   895             ? isLeapYear(year)
       
   896                 ? 29
       
   897                 : 28
       
   898             : 31 - ((modMonth % 7) % 2);
   876     }
   899     }
   877 
   900 
   878     // FORMATTING
   901     // FORMATTING
   879 
   902 
   880     addFormatToken('M', ['MM', 2], 'Mo', function () {
   903     addFormatToken('M', ['MM', 2], 'Mo', function () {
   897 
   920 
   898     addUnitPriority('month', 8);
   921     addUnitPriority('month', 8);
   899 
   922 
   900     // PARSING
   923     // PARSING
   901 
   924 
   902     addRegexToken('M',    match1to2);
   925     addRegexToken('M', match1to2);
   903     addRegexToken('MM',   match1to2, match2);
   926     addRegexToken('MM', match1to2, match2);
   904     addRegexToken('MMM',  function (isStrict, locale) {
   927     addRegexToken('MMM', function (isStrict, locale) {
   905         return locale.monthsShortRegex(isStrict);
   928         return locale.monthsShortRegex(isStrict);
   906     });
   929     });
   907     addRegexToken('MMMM', function (isStrict, locale) {
   930     addRegexToken('MMMM', function (isStrict, locale) {
   908         return locale.monthsRegex(isStrict);
   931         return locale.monthsRegex(isStrict);
   909     });
   932     });
   922         }
   945         }
   923     });
   946     });
   924 
   947 
   925     // LOCALES
   948     // LOCALES
   926 
   949 
   927     var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
   950     var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
   928     var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
   951             '_'
   929     function localeMonths (m, format) {
   952         ),
       
   953         defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split(
       
   954             '_'
       
   955         ),
       
   956         MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
       
   957         defaultMonthsShortRegex = matchWord,
       
   958         defaultMonthsRegex = matchWord;
       
   959 
       
   960     function localeMonths(m, format) {
   930         if (!m) {
   961         if (!m) {
   931             return isArray(this._months) ? this._months :
   962             return isArray(this._months)
   932                 this._months['standalone'];
   963                 ? this._months
   933         }
   964                 : this._months['standalone'];
   934         return isArray(this._months) ? this._months[m.month()] :
   965         }
   935             this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
   966         return isArray(this._months)
   936     }
   967             ? this._months[m.month()]
   937 
   968             : this._months[
   938     var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
   969                   (this._months.isFormat || MONTHS_IN_FORMAT).test(format)
   939     function localeMonthsShort (m, format) {
   970                       ? 'format'
       
   971                       : 'standalone'
       
   972               ][m.month()];
       
   973     }
       
   974 
       
   975     function localeMonthsShort(m, format) {
   940         if (!m) {
   976         if (!m) {
   941             return isArray(this._monthsShort) ? this._monthsShort :
   977             return isArray(this._monthsShort)
   942                 this._monthsShort['standalone'];
   978                 ? this._monthsShort
   943         }
   979                 : this._monthsShort['standalone'];
   944         return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
   980         }
   945             this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
   981         return isArray(this._monthsShort)
       
   982             ? this._monthsShort[m.month()]
       
   983             : this._monthsShort[
       
   984                   MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'
       
   985               ][m.month()];
   946     }
   986     }
   947 
   987 
   948     function handleStrictParse(monthName, format, strict) {
   988     function handleStrictParse(monthName, format, strict) {
   949         var i, ii, mom, llc = monthName.toLocaleLowerCase();
   989         var i,
       
   990             ii,
       
   991             mom,
       
   992             llc = monthName.toLocaleLowerCase();
   950         if (!this._monthsParse) {
   993         if (!this._monthsParse) {
   951             // this is not used
   994             // this is not used
   952             this._monthsParse = [];
   995             this._monthsParse = [];
   953             this._longMonthsParse = [];
   996             this._longMonthsParse = [];
   954             this._shortMonthsParse = [];
   997             this._shortMonthsParse = [];
   955             for (i = 0; i < 12; ++i) {
   998             for (i = 0; i < 12; ++i) {
   956                 mom = createUTC([2000, i]);
   999                 mom = createUTC([2000, i]);
   957                 this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  1000                 this._shortMonthsParse[i] = this.monthsShort(
       
  1001                     mom,
       
  1002                     ''
       
  1003                 ).toLocaleLowerCase();
   958                 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  1004                 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
   959             }
  1005             }
   960         }
  1006         }
   961 
  1007 
   962         if (strict) {
  1008         if (strict) {
   984                 return ii !== -1 ? ii : null;
  1030                 return ii !== -1 ? ii : null;
   985             }
  1031             }
   986         }
  1032         }
   987     }
  1033     }
   988 
  1034 
   989     function localeMonthsParse (monthName, format, strict) {
  1035     function localeMonthsParse(monthName, format, strict) {
   990         var i, mom, regex;
  1036         var i, mom, regex;
   991 
  1037 
   992         if (this._monthsParseExact) {
  1038         if (this._monthsParseExact) {
   993             return handleStrictParse.call(this, monthName, format, strict);
  1039             return handleStrictParse.call(this, monthName, format, strict);
   994         }
  1040         }
  1004         // see sorting in computeMonthsParse
  1050         // see sorting in computeMonthsParse
  1005         for (i = 0; i < 12; i++) {
  1051         for (i = 0; i < 12; i++) {
  1006             // make the regex if we don't have it already
  1052             // make the regex if we don't have it already
  1007             mom = createUTC([2000, i]);
  1053             mom = createUTC([2000, i]);
  1008             if (strict && !this._longMonthsParse[i]) {
  1054             if (strict && !this._longMonthsParse[i]) {
  1009                 this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  1055                 this._longMonthsParse[i] = new RegExp(
  1010                 this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  1056                     '^' + this.months(mom, '').replace('.', '') + '$',
       
  1057                     'i'
       
  1058                 );
       
  1059                 this._shortMonthsParse[i] = new RegExp(
       
  1060                     '^' + this.monthsShort(mom, '').replace('.', '') + '$',
       
  1061                     'i'
       
  1062                 );
  1011             }
  1063             }
  1012             if (!strict && !this._monthsParse[i]) {
  1064             if (!strict && !this._monthsParse[i]) {
  1013                 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  1065                 regex =
       
  1066                     '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  1014                 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1067                 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1015             }
  1068             }
  1016             // test the regex
  1069             // test the regex
  1017             if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  1070             if (
       
  1071                 strict &&
       
  1072                 format === 'MMMM' &&
       
  1073                 this._longMonthsParse[i].test(monthName)
       
  1074             ) {
  1018                 return i;
  1075                 return i;
  1019             } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  1076             } else if (
       
  1077                 strict &&
       
  1078                 format === 'MMM' &&
       
  1079                 this._shortMonthsParse[i].test(monthName)
       
  1080             ) {
  1020                 return i;
  1081                 return i;
  1021             } else if (!strict && this._monthsParse[i].test(monthName)) {
  1082             } else if (!strict && this._monthsParse[i].test(monthName)) {
  1022                 return i;
  1083                 return i;
  1023             }
  1084             }
  1024         }
  1085         }
  1025     }
  1086     }
  1026 
  1087 
  1027     // MOMENTS
  1088     // MOMENTS
  1028 
  1089 
  1029     function setMonth (mom, value) {
  1090     function setMonth(mom, value) {
  1030         var dayOfMonth;
  1091         var dayOfMonth;
  1031 
  1092 
  1032         if (!mom.isValid()) {
  1093         if (!mom.isValid()) {
  1033             // No op
  1094             // No op
  1034             return mom;
  1095             return mom;
  1049         dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  1110         dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  1050         mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  1111         mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  1051         return mom;
  1112         return mom;
  1052     }
  1113     }
  1053 
  1114 
  1054     function getSetMonth (value) {
  1115     function getSetMonth(value) {
  1055         if (value != null) {
  1116         if (value != null) {
  1056             setMonth(this, value);
  1117             setMonth(this, value);
  1057             hooks.updateOffset(this, true);
  1118             hooks.updateOffset(this, true);
  1058             return this;
  1119             return this;
  1059         } else {
  1120         } else {
  1060             return get(this, 'Month');
  1121             return get(this, 'Month');
  1061         }
  1122         }
  1062     }
  1123     }
  1063 
  1124 
  1064     function getDaysInMonth () {
  1125     function getDaysInMonth() {
  1065         return daysInMonth(this.year(), this.month());
  1126         return daysInMonth(this.year(), this.month());
  1066     }
  1127     }
  1067 
  1128 
  1068     var defaultMonthsShortRegex = matchWord;
  1129     function monthsShortRegex(isStrict) {
  1069     function monthsShortRegex (isStrict) {
       
  1070         if (this._monthsParseExact) {
  1130         if (this._monthsParseExact) {
  1071             if (!hasOwnProp(this, '_monthsRegex')) {
  1131             if (!hasOwnProp(this, '_monthsRegex')) {
  1072                 computeMonthsParse.call(this);
  1132                 computeMonthsParse.call(this);
  1073             }
  1133             }
  1074             if (isStrict) {
  1134             if (isStrict) {
  1078             }
  1138             }
  1079         } else {
  1139         } else {
  1080             if (!hasOwnProp(this, '_monthsShortRegex')) {
  1140             if (!hasOwnProp(this, '_monthsShortRegex')) {
  1081                 this._monthsShortRegex = defaultMonthsShortRegex;
  1141                 this._monthsShortRegex = defaultMonthsShortRegex;
  1082             }
  1142             }
  1083             return this._monthsShortStrictRegex && isStrict ?
  1143             return this._monthsShortStrictRegex && isStrict
  1084                 this._monthsShortStrictRegex : this._monthsShortRegex;
  1144                 ? this._monthsShortStrictRegex
  1085         }
  1145                 : this._monthsShortRegex;
  1086     }
  1146         }
  1087 
  1147     }
  1088     var defaultMonthsRegex = matchWord;
  1148 
  1089     function monthsRegex (isStrict) {
  1149     function monthsRegex(isStrict) {
  1090         if (this._monthsParseExact) {
  1150         if (this._monthsParseExact) {
  1091             if (!hasOwnProp(this, '_monthsRegex')) {
  1151             if (!hasOwnProp(this, '_monthsRegex')) {
  1092                 computeMonthsParse.call(this);
  1152                 computeMonthsParse.call(this);
  1093             }
  1153             }
  1094             if (isStrict) {
  1154             if (isStrict) {
  1098             }
  1158             }
  1099         } else {
  1159         } else {
  1100             if (!hasOwnProp(this, '_monthsRegex')) {
  1160             if (!hasOwnProp(this, '_monthsRegex')) {
  1101                 this._monthsRegex = defaultMonthsRegex;
  1161                 this._monthsRegex = defaultMonthsRegex;
  1102             }
  1162             }
  1103             return this._monthsStrictRegex && isStrict ?
  1163             return this._monthsStrictRegex && isStrict
  1104                 this._monthsStrictRegex : this._monthsRegex;
  1164                 ? this._monthsStrictRegex
  1105         }
  1165                 : this._monthsRegex;
  1106     }
  1166         }
  1107 
  1167     }
  1108     function computeMonthsParse () {
  1168 
       
  1169     function computeMonthsParse() {
  1109         function cmpLenRev(a, b) {
  1170         function cmpLenRev(a, b) {
  1110             return b.length - a.length;
  1171             return b.length - a.length;
  1111         }
  1172         }
  1112 
  1173 
  1113         var shortPieces = [], longPieces = [], mixedPieces = [],
  1174         var shortPieces = [],
  1114             i, mom;
  1175             longPieces = [],
       
  1176             mixedPieces = [],
       
  1177             i,
       
  1178             mom;
  1115         for (i = 0; i < 12; i++) {
  1179         for (i = 0; i < 12; i++) {
  1116             // make the regex if we don't have it already
  1180             // make the regex if we don't have it already
  1117             mom = createUTC([2000, i]);
  1181             mom = createUTC([2000, i]);
  1118             shortPieces.push(this.monthsShort(mom, ''));
  1182             shortPieces.push(this.monthsShort(mom, ''));
  1119             longPieces.push(this.months(mom, ''));
  1183             longPieces.push(this.months(mom, ''));
  1133             mixedPieces[i] = regexEscape(mixedPieces[i]);
  1197             mixedPieces[i] = regexEscape(mixedPieces[i]);
  1134         }
  1198         }
  1135 
  1199 
  1136         this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  1200         this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  1137         this._monthsShortRegex = this._monthsRegex;
  1201         this._monthsShortRegex = this._monthsRegex;
  1138         this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  1202         this._monthsStrictRegex = new RegExp(
  1139         this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  1203             '^(' + longPieces.join('|') + ')',
  1140     }
  1204             'i'
  1141 
  1205         );
  1142     function createDate (y, m, d, h, M, s, ms) {
  1206         this._monthsShortStrictRegex = new RegExp(
       
  1207             '^(' + shortPieces.join('|') + ')',
       
  1208             'i'
       
  1209         );
       
  1210     }
       
  1211 
       
  1212     // FORMATTING
       
  1213 
       
  1214     addFormatToken('Y', 0, 0, function () {
       
  1215         var y = this.year();
       
  1216         return y <= 9999 ? zeroFill(y, 4) : '+' + y;
       
  1217     });
       
  1218 
       
  1219     addFormatToken(0, ['YY', 2], 0, function () {
       
  1220         return this.year() % 100;
       
  1221     });
       
  1222 
       
  1223     addFormatToken(0, ['YYYY', 4], 0, 'year');
       
  1224     addFormatToken(0, ['YYYYY', 5], 0, 'year');
       
  1225     addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
       
  1226 
       
  1227     // ALIASES
       
  1228 
       
  1229     addUnitAlias('year', 'y');
       
  1230 
       
  1231     // PRIORITIES
       
  1232 
       
  1233     addUnitPriority('year', 1);
       
  1234 
       
  1235     // PARSING
       
  1236 
       
  1237     addRegexToken('Y', matchSigned);
       
  1238     addRegexToken('YY', match1to2, match2);
       
  1239     addRegexToken('YYYY', match1to4, match4);
       
  1240     addRegexToken('YYYYY', match1to6, match6);
       
  1241     addRegexToken('YYYYYY', match1to6, match6);
       
  1242 
       
  1243     addParseToken(['YYYYY', 'YYYYYY'], YEAR);
       
  1244     addParseToken('YYYY', function (input, array) {
       
  1245         array[YEAR] =
       
  1246             input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
       
  1247     });
       
  1248     addParseToken('YY', function (input, array) {
       
  1249         array[YEAR] = hooks.parseTwoDigitYear(input);
       
  1250     });
       
  1251     addParseToken('Y', function (input, array) {
       
  1252         array[YEAR] = parseInt(input, 10);
       
  1253     });
       
  1254 
       
  1255     // HELPERS
       
  1256 
       
  1257     function daysInYear(year) {
       
  1258         return isLeapYear(year) ? 366 : 365;
       
  1259     }
       
  1260 
       
  1261     // HOOKS
       
  1262 
       
  1263     hooks.parseTwoDigitYear = function (input) {
       
  1264         return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
       
  1265     };
       
  1266 
       
  1267     // MOMENTS
       
  1268 
       
  1269     var getSetYear = makeGetSet('FullYear', true);
       
  1270 
       
  1271     function getIsLeapYear() {
       
  1272         return isLeapYear(this.year());
       
  1273     }
       
  1274 
       
  1275     function createDate(y, m, d, h, M, s, ms) {
  1143         // can't just apply() to create a date:
  1276         // can't just apply() to create a date:
  1144         // https://stackoverflow.com/q/181348
  1277         // https://stackoverflow.com/q/181348
  1145         var date = new Date(y, m, d, h, M, s, ms);
  1278         var date;
  1146 
       
  1147         // the date constructor remaps years 0-99 to 1900-1999
  1279         // the date constructor remaps years 0-99 to 1900-1999
  1148         if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  1280         if (y < 100 && y >= 0) {
  1149             date.setFullYear(y);
  1281             // preserve leap years using a full 400 year cycle, then reset
  1150         }
  1282             date = new Date(y + 400, m, d, h, M, s, ms);
       
  1283             if (isFinite(date.getFullYear())) {
       
  1284                 date.setFullYear(y);
       
  1285             }
       
  1286         } else {
       
  1287             date = new Date(y, m, d, h, M, s, ms);
       
  1288         }
       
  1289 
  1151         return date;
  1290         return date;
  1152     }
  1291     }
  1153 
  1292 
  1154     function createUTCDate (y) {
  1293     function createUTCDate(y) {
  1155         var date = new Date(Date.UTC.apply(null, arguments));
  1294         var date, args;
  1156 
       
  1157         // the Date.UTC function remaps years 0-99 to 1900-1999
  1295         // the Date.UTC function remaps years 0-99 to 1900-1999
  1158         if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  1296         if (y < 100 && y >= 0) {
  1159             date.setUTCFullYear(y);
  1297             args = Array.prototype.slice.call(arguments);
  1160         }
  1298             // preserve leap years using a full 400 year cycle, then reset
       
  1299             args[0] = y + 400;
       
  1300             date = new Date(Date.UTC.apply(null, args));
       
  1301             if (isFinite(date.getUTCFullYear())) {
       
  1302                 date.setUTCFullYear(y);
       
  1303             }
       
  1304         } else {
       
  1305             date = new Date(Date.UTC.apply(null, arguments));
       
  1306         }
       
  1307 
  1161         return date;
  1308         return date;
  1162     }
  1309     }
  1163 
  1310 
  1164     // start-of-first-week - start-of-year
  1311     // start-of-first-week - start-of-year
  1165     function firstWeekOffset(year, dow, doy) {
  1312     function firstWeekOffset(year, dow, doy) {
  1174     // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1321     // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1175     function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  1322     function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  1176         var localWeekday = (7 + weekday - dow) % 7,
  1323         var localWeekday = (7 + weekday - dow) % 7,
  1177             weekOffset = firstWeekOffset(year, dow, doy),
  1324             weekOffset = firstWeekOffset(year, dow, doy),
  1178             dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  1325             dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  1179             resYear, resDayOfYear;
  1326             resYear,
       
  1327             resDayOfYear;
  1180 
  1328 
  1181         if (dayOfYear <= 0) {
  1329         if (dayOfYear <= 0) {
  1182             resYear = year - 1;
  1330             resYear = year - 1;
  1183             resDayOfYear = daysInYear(resYear) + dayOfYear;
  1331             resDayOfYear = daysInYear(resYear) + dayOfYear;
  1184         } else if (dayOfYear > daysInYear(year)) {
  1332         } else if (dayOfYear > daysInYear(year)) {
  1189             resDayOfYear = dayOfYear;
  1337             resDayOfYear = dayOfYear;
  1190         }
  1338         }
  1191 
  1339 
  1192         return {
  1340         return {
  1193             year: resYear,
  1341             year: resYear,
  1194             dayOfYear: resDayOfYear
  1342             dayOfYear: resDayOfYear,
  1195         };
  1343         };
  1196     }
  1344     }
  1197 
  1345 
  1198     function weekOfYear(mom, dow, doy) {
  1346     function weekOfYear(mom, dow, doy) {
  1199         var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  1347         var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  1200             week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  1348             week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  1201             resWeek, resYear;
  1349             resWeek,
       
  1350             resYear;
  1202 
  1351 
  1203         if (week < 1) {
  1352         if (week < 1) {
  1204             resYear = mom.year() - 1;
  1353             resYear = mom.year() - 1;
  1205             resWeek = week + weeksInYear(resYear, dow, doy);
  1354             resWeek = week + weeksInYear(resYear, dow, doy);
  1206         } else if (week > weeksInYear(mom.year(), dow, doy)) {
  1355         } else if (week > weeksInYear(mom.year(), dow, doy)) {
  1211             resWeek = week;
  1360             resWeek = week;
  1212         }
  1361         }
  1213 
  1362 
  1214         return {
  1363         return {
  1215             week: resWeek,
  1364             week: resWeek,
  1216             year: resYear
  1365             year: resYear,
  1217         };
  1366         };
  1218     }
  1367     }
  1219 
  1368 
  1220     function weeksInYear(year, dow, doy) {
  1369     function weeksInYear(year, dow, doy) {
  1221         var weekOffset = firstWeekOffset(year, dow, doy),
  1370         var weekOffset = firstWeekOffset(year, dow, doy),
  1238     addUnitPriority('week', 5);
  1387     addUnitPriority('week', 5);
  1239     addUnitPriority('isoWeek', 5);
  1388     addUnitPriority('isoWeek', 5);
  1240 
  1389 
  1241     // PARSING
  1390     // PARSING
  1242 
  1391 
  1243     addRegexToken('w',  match1to2);
  1392     addRegexToken('w', match1to2);
  1244     addRegexToken('ww', match1to2, match2);
  1393     addRegexToken('ww', match1to2, match2);
  1245     addRegexToken('W',  match1to2);
  1394     addRegexToken('W', match1to2);
  1246     addRegexToken('WW', match1to2, match2);
  1395     addRegexToken('WW', match1to2, match2);
  1247 
  1396 
  1248     addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  1397     addWeekParseToken(['w', 'ww', 'W', 'WW'], function (
       
  1398         input,
       
  1399         week,
       
  1400         config,
       
  1401         token
       
  1402     ) {
  1249         week[token.substr(0, 1)] = toInt(input);
  1403         week[token.substr(0, 1)] = toInt(input);
  1250     });
  1404     });
  1251 
  1405 
  1252     // HELPERS
  1406     // HELPERS
  1253 
  1407 
  1254     // LOCALES
  1408     // LOCALES
  1255 
  1409 
  1256     function localeWeek (mom) {
  1410     function localeWeek(mom) {
  1257         return weekOfYear(mom, this._week.dow, this._week.doy).week;
  1411         return weekOfYear(mom, this._week.dow, this._week.doy).week;
  1258     }
  1412     }
  1259 
  1413 
  1260     var defaultLocaleWeek = {
  1414     var defaultLocaleWeek = {
  1261         dow : 0, // Sunday is the first day of the week.
  1415         dow: 0, // Sunday is the first day of the week.
  1262         doy : 6  // The week that contains Jan 1st is the first week of the year.
  1416         doy: 6, // The week that contains Jan 6th is the first week of the year.
  1263     };
  1417     };
  1264 
  1418 
  1265     function localeFirstDayOfWeek () {
  1419     function localeFirstDayOfWeek() {
  1266         return this._week.dow;
  1420         return this._week.dow;
  1267     }
  1421     }
  1268 
  1422 
  1269     function localeFirstDayOfYear () {
  1423     function localeFirstDayOfYear() {
  1270         return this._week.doy;
  1424         return this._week.doy;
  1271     }
  1425     }
  1272 
  1426 
  1273     // MOMENTS
  1427     // MOMENTS
  1274 
  1428 
  1275     function getSetWeek (input) {
  1429     function getSetWeek(input) {
  1276         var week = this.localeData().week(this);
  1430         var week = this.localeData().week(this);
  1277         return input == null ? week : this.add((input - week) * 7, 'd');
  1431         return input == null ? week : this.add((input - week) * 7, 'd');
  1278     }
  1432     }
  1279 
  1433 
  1280     function getSetISOWeek (input) {
  1434     function getSetISOWeek(input) {
  1281         var week = weekOfYear(this, 1, 4).week;
  1435         var week = weekOfYear(this, 1, 4).week;
  1282         return input == null ? week : this.add((input - week) * 7, 'd');
  1436         return input == null ? week : this.add((input - week) * 7, 'd');
  1283     }
  1437     }
  1284 
  1438 
  1285     // FORMATTING
  1439     // FORMATTING
  1312     addUnitPriority('weekday', 11);
  1466     addUnitPriority('weekday', 11);
  1313     addUnitPriority('isoWeekday', 11);
  1467     addUnitPriority('isoWeekday', 11);
  1314 
  1468 
  1315     // PARSING
  1469     // PARSING
  1316 
  1470 
  1317     addRegexToken('d',    match1to2);
  1471     addRegexToken('d', match1to2);
  1318     addRegexToken('e',    match1to2);
  1472     addRegexToken('e', match1to2);
  1319     addRegexToken('E',    match1to2);
  1473     addRegexToken('E', match1to2);
  1320     addRegexToken('dd',   function (isStrict, locale) {
  1474     addRegexToken('dd', function (isStrict, locale) {
  1321         return locale.weekdaysMinRegex(isStrict);
  1475         return locale.weekdaysMinRegex(isStrict);
  1322     });
  1476     });
  1323     addRegexToken('ddd',   function (isStrict, locale) {
  1477     addRegexToken('ddd', function (isStrict, locale) {
  1324         return locale.weekdaysShortRegex(isStrict);
  1478         return locale.weekdaysShortRegex(isStrict);
  1325     });
  1479     });
  1326     addRegexToken('dddd',   function (isStrict, locale) {
  1480     addRegexToken('dddd', function (isStrict, locale) {
  1327         return locale.weekdaysRegex(isStrict);
  1481         return locale.weekdaysRegex(isStrict);
  1328     });
  1482     });
  1329 
  1483 
  1330     addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  1484     addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  1331         var weekday = config._locale.weekdaysParse(input, token, config._strict);
  1485         var weekday = config._locale.weekdaysParse(input, token, config._strict);
  1366         }
  1520         }
  1367         return isNaN(input) ? null : input;
  1521         return isNaN(input) ? null : input;
  1368     }
  1522     }
  1369 
  1523 
  1370     // LOCALES
  1524     // LOCALES
  1371 
  1525     function shiftWeekdays(ws, n) {
  1372     var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  1526         return ws.slice(n, 7).concat(ws.slice(0, n));
  1373     function localeWeekdays (m, format) {
  1527     }
  1374         if (!m) {
  1528 
  1375             return isArray(this._weekdays) ? this._weekdays :
  1529     var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split(
  1376                 this._weekdays['standalone'];
  1530             '_'
  1377         }
  1531         ),
  1378         return isArray(this._weekdays) ? this._weekdays[m.day()] :
  1532         defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
  1379             this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  1533         defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
  1380     }
  1534         defaultWeekdaysRegex = matchWord,
  1381 
  1535         defaultWeekdaysShortRegex = matchWord,
  1382     var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  1536         defaultWeekdaysMinRegex = matchWord;
  1383     function localeWeekdaysShort (m) {
  1537 
  1384         return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
  1538     function localeWeekdays(m, format) {
  1385     }
  1539         var weekdays = isArray(this._weekdays)
  1386 
  1540             ? this._weekdays
  1387     var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  1541             : this._weekdays[
  1388     function localeWeekdaysMin (m) {
  1542                   m && m !== true && this._weekdays.isFormat.test(format)
  1389         return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
  1543                       ? 'format'
       
  1544                       : 'standalone'
       
  1545               ];
       
  1546         return m === true
       
  1547             ? shiftWeekdays(weekdays, this._week.dow)
       
  1548             : m
       
  1549             ? weekdays[m.day()]
       
  1550             : weekdays;
       
  1551     }
       
  1552 
       
  1553     function localeWeekdaysShort(m) {
       
  1554         return m === true
       
  1555             ? shiftWeekdays(this._weekdaysShort, this._week.dow)
       
  1556             : m
       
  1557             ? this._weekdaysShort[m.day()]
       
  1558             : this._weekdaysShort;
       
  1559     }
       
  1560 
       
  1561     function localeWeekdaysMin(m) {
       
  1562         return m === true
       
  1563             ? shiftWeekdays(this._weekdaysMin, this._week.dow)
       
  1564             : m
       
  1565             ? this._weekdaysMin[m.day()]
       
  1566             : this._weekdaysMin;
  1390     }
  1567     }
  1391 
  1568 
  1392     function handleStrictParse$1(weekdayName, format, strict) {
  1569     function handleStrictParse$1(weekdayName, format, strict) {
  1393         var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  1570         var i,
       
  1571             ii,
       
  1572             mom,
       
  1573             llc = weekdayName.toLocaleLowerCase();
  1394         if (!this._weekdaysParse) {
  1574         if (!this._weekdaysParse) {
  1395             this._weekdaysParse = [];
  1575             this._weekdaysParse = [];
  1396             this._shortWeekdaysParse = [];
  1576             this._shortWeekdaysParse = [];
  1397             this._minWeekdaysParse = [];
  1577             this._minWeekdaysParse = [];
  1398 
  1578 
  1399             for (i = 0; i < 7; ++i) {
  1579             for (i = 0; i < 7; ++i) {
  1400                 mom = createUTC([2000, 1]).day(i);
  1580                 mom = createUTC([2000, 1]).day(i);
  1401                 this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  1581                 this._minWeekdaysParse[i] = this.weekdaysMin(
  1402                 this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  1582                     mom,
       
  1583                     ''
       
  1584                 ).toLocaleLowerCase();
       
  1585                 this._shortWeekdaysParse[i] = this.weekdaysShort(
       
  1586                     mom,
       
  1587                     ''
       
  1588                 ).toLocaleLowerCase();
  1403                 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  1589                 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  1404             }
  1590             }
  1405         }
  1591         }
  1406 
  1592 
  1407         if (strict) {
  1593         if (strict) {
  1451                 return ii !== -1 ? ii : null;
  1637                 return ii !== -1 ? ii : null;
  1452             }
  1638             }
  1453         }
  1639         }
  1454     }
  1640     }
  1455 
  1641 
  1456     function localeWeekdaysParse (weekdayName, format, strict) {
  1642     function localeWeekdaysParse(weekdayName, format, strict) {
  1457         var i, mom, regex;
  1643         var i, mom, regex;
  1458 
  1644 
  1459         if (this._weekdaysParseExact) {
  1645         if (this._weekdaysParseExact) {
  1460             return handleStrictParse$1.call(this, weekdayName, format, strict);
  1646             return handleStrictParse$1.call(this, weekdayName, format, strict);
  1461         }
  1647         }
  1470         for (i = 0; i < 7; i++) {
  1656         for (i = 0; i < 7; i++) {
  1471             // make the regex if we don't have it already
  1657             // make the regex if we don't have it already
  1472 
  1658 
  1473             mom = createUTC([2000, 1]).day(i);
  1659             mom = createUTC([2000, 1]).day(i);
  1474             if (strict && !this._fullWeekdaysParse[i]) {
  1660             if (strict && !this._fullWeekdaysParse[i]) {
  1475                 this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 'i');
  1661                 this._fullWeekdaysParse[i] = new RegExp(
  1476                 this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 'i');
  1662                     '^' + this.weekdays(mom, '').replace('.', '\\.?') + '$',
  1477                 this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 'i');
  1663                     'i'
       
  1664                 );
       
  1665                 this._shortWeekdaysParse[i] = new RegExp(
       
  1666                     '^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$',
       
  1667                     'i'
       
  1668                 );
       
  1669                 this._minWeekdaysParse[i] = new RegExp(
       
  1670                     '^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$',
       
  1671                     'i'
       
  1672                 );
  1478             }
  1673             }
  1479             if (!this._weekdaysParse[i]) {
  1674             if (!this._weekdaysParse[i]) {
  1480                 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  1675                 regex =
       
  1676                     '^' +
       
  1677                     this.weekdays(mom, '') +
       
  1678                     '|^' +
       
  1679                     this.weekdaysShort(mom, '') +
       
  1680                     '|^' +
       
  1681                     this.weekdaysMin(mom, '');
  1481                 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1682                 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1482             }
  1683             }
  1483             // test the regex
  1684             // test the regex
  1484             if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  1685             if (
       
  1686                 strict &&
       
  1687                 format === 'dddd' &&
       
  1688                 this._fullWeekdaysParse[i].test(weekdayName)
       
  1689             ) {
  1485                 return i;
  1690                 return i;
  1486             } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  1691             } else if (
       
  1692                 strict &&
       
  1693                 format === 'ddd' &&
       
  1694                 this._shortWeekdaysParse[i].test(weekdayName)
       
  1695             ) {
  1487                 return i;
  1696                 return i;
  1488             } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  1697             } else if (
       
  1698                 strict &&
       
  1699                 format === 'dd' &&
       
  1700                 this._minWeekdaysParse[i].test(weekdayName)
       
  1701             ) {
  1489                 return i;
  1702                 return i;
  1490             } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  1703             } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  1491                 return i;
  1704                 return i;
  1492             }
  1705             }
  1493         }
  1706         }
  1494     }
  1707     }
  1495 
  1708 
  1496     // MOMENTS
  1709     // MOMENTS
  1497 
  1710 
  1498     function getSetDayOfWeek (input) {
  1711     function getSetDayOfWeek(input) {
  1499         if (!this.isValid()) {
  1712         if (!this.isValid()) {
  1500             return input != null ? this : NaN;
  1713             return input != null ? this : NaN;
  1501         }
  1714         }
  1502         var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1715         var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1503         if (input != null) {
  1716         if (input != null) {
  1506         } else {
  1719         } else {
  1507             return day;
  1720             return day;
  1508         }
  1721         }
  1509     }
  1722     }
  1510 
  1723 
  1511     function getSetLocaleDayOfWeek (input) {
  1724     function getSetLocaleDayOfWeek(input) {
  1512         if (!this.isValid()) {
  1725         if (!this.isValid()) {
  1513             return input != null ? this : NaN;
  1726             return input != null ? this : NaN;
  1514         }
  1727         }
  1515         var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  1728         var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  1516         return input == null ? weekday : this.add(input - weekday, 'd');
  1729         return input == null ? weekday : this.add(input - weekday, 'd');
  1517     }
  1730     }
  1518 
  1731 
  1519     function getSetISODayOfWeek (input) {
  1732     function getSetISODayOfWeek(input) {
  1520         if (!this.isValid()) {
  1733         if (!this.isValid()) {
  1521             return input != null ? this : NaN;
  1734             return input != null ? this : NaN;
  1522         }
  1735         }
  1523 
  1736 
  1524         // behaves the same as moment#day except
  1737         // behaves the same as moment#day except
  1531         } else {
  1744         } else {
  1532             return this.day() || 7;
  1745             return this.day() || 7;
  1533         }
  1746         }
  1534     }
  1747     }
  1535 
  1748 
  1536     var defaultWeekdaysRegex = matchWord;
  1749     function weekdaysRegex(isStrict) {
  1537     function weekdaysRegex (isStrict) {
       
  1538         if (this._weekdaysParseExact) {
  1750         if (this._weekdaysParseExact) {
  1539             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1751             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1540                 computeWeekdaysParse.call(this);
  1752                 computeWeekdaysParse.call(this);
  1541             }
  1753             }
  1542             if (isStrict) {
  1754             if (isStrict) {
  1546             }
  1758             }
  1547         } else {
  1759         } else {
  1548             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1760             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1549                 this._weekdaysRegex = defaultWeekdaysRegex;
  1761                 this._weekdaysRegex = defaultWeekdaysRegex;
  1550             }
  1762             }
  1551             return this._weekdaysStrictRegex && isStrict ?
  1763             return this._weekdaysStrictRegex && isStrict
  1552                 this._weekdaysStrictRegex : this._weekdaysRegex;
  1764                 ? this._weekdaysStrictRegex
  1553         }
  1765                 : this._weekdaysRegex;
  1554     }
  1766         }
  1555 
  1767     }
  1556     var defaultWeekdaysShortRegex = matchWord;
  1768 
  1557     function weekdaysShortRegex (isStrict) {
  1769     function weekdaysShortRegex(isStrict) {
  1558         if (this._weekdaysParseExact) {
  1770         if (this._weekdaysParseExact) {
  1559             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1771             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1560                 computeWeekdaysParse.call(this);
  1772                 computeWeekdaysParse.call(this);
  1561             }
  1773             }
  1562             if (isStrict) {
  1774             if (isStrict) {
  1566             }
  1778             }
  1567         } else {
  1779         } else {
  1568             if (!hasOwnProp(this, '_weekdaysShortRegex')) {
  1780             if (!hasOwnProp(this, '_weekdaysShortRegex')) {
  1569                 this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  1781                 this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  1570             }
  1782             }
  1571             return this._weekdaysShortStrictRegex && isStrict ?
  1783             return this._weekdaysShortStrictRegex && isStrict
  1572                 this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  1784                 ? this._weekdaysShortStrictRegex
  1573         }
  1785                 : this._weekdaysShortRegex;
  1574     }
  1786         }
  1575 
  1787     }
  1576     var defaultWeekdaysMinRegex = matchWord;
  1788 
  1577     function weekdaysMinRegex (isStrict) {
  1789     function weekdaysMinRegex(isStrict) {
  1578         if (this._weekdaysParseExact) {
  1790         if (this._weekdaysParseExact) {
  1579             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1791             if (!hasOwnProp(this, '_weekdaysRegex')) {
  1580                 computeWeekdaysParse.call(this);
  1792                 computeWeekdaysParse.call(this);
  1581             }
  1793             }
  1582             if (isStrict) {
  1794             if (isStrict) {
  1586             }
  1798             }
  1587         } else {
  1799         } else {
  1588             if (!hasOwnProp(this, '_weekdaysMinRegex')) {
  1800             if (!hasOwnProp(this, '_weekdaysMinRegex')) {
  1589                 this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  1801                 this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  1590             }
  1802             }
  1591             return this._weekdaysMinStrictRegex && isStrict ?
  1803             return this._weekdaysMinStrictRegex && isStrict
  1592                 this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  1804                 ? this._weekdaysMinStrictRegex
  1593         }
  1805                 : this._weekdaysMinRegex;
  1594     }
  1806         }
  1595 
  1807     }
  1596 
  1808 
  1597     function computeWeekdaysParse () {
  1809     function computeWeekdaysParse() {
  1598         function cmpLenRev(a, b) {
  1810         function cmpLenRev(a, b) {
  1599             return b.length - a.length;
  1811             return b.length - a.length;
  1600         }
  1812         }
  1601 
  1813 
  1602         var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  1814         var minPieces = [],
  1603             i, mom, minp, shortp, longp;
  1815             shortPieces = [],
       
  1816             longPieces = [],
       
  1817             mixedPieces = [],
       
  1818             i,
       
  1819             mom,
       
  1820             minp,
       
  1821             shortp,
       
  1822             longp;
  1604         for (i = 0; i < 7; i++) {
  1823         for (i = 0; i < 7; i++) {
  1605             // make the regex if we don't have it already
  1824             // make the regex if we don't have it already
  1606             mom = createUTC([2000, 1]).day(i);
  1825             mom = createUTC([2000, 1]).day(i);
  1607             minp = this.weekdaysMin(mom, '');
  1826             minp = regexEscape(this.weekdaysMin(mom, ''));
  1608             shortp = this.weekdaysShort(mom, '');
  1827             shortp = regexEscape(this.weekdaysShort(mom, ''));
  1609             longp = this.weekdays(mom, '');
  1828             longp = regexEscape(this.weekdays(mom, ''));
  1610             minPieces.push(minp);
  1829             minPieces.push(minp);
  1611             shortPieces.push(shortp);
  1830             shortPieces.push(shortp);
  1612             longPieces.push(longp);
  1831             longPieces.push(longp);
  1613             mixedPieces.push(minp);
  1832             mixedPieces.push(minp);
  1614             mixedPieces.push(shortp);
  1833             mixedPieces.push(shortp);
  1618         // will match the longer piece.
  1837         // will match the longer piece.
  1619         minPieces.sort(cmpLenRev);
  1838         minPieces.sort(cmpLenRev);
  1620         shortPieces.sort(cmpLenRev);
  1839         shortPieces.sort(cmpLenRev);
  1621         longPieces.sort(cmpLenRev);
  1840         longPieces.sort(cmpLenRev);
  1622         mixedPieces.sort(cmpLenRev);
  1841         mixedPieces.sort(cmpLenRev);
  1623         for (i = 0; i < 7; i++) {
       
  1624             shortPieces[i] = regexEscape(shortPieces[i]);
       
  1625             longPieces[i] = regexEscape(longPieces[i]);
       
  1626             mixedPieces[i] = regexEscape(mixedPieces[i]);
       
  1627         }
       
  1628 
  1842 
  1629         this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  1843         this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  1630         this._weekdaysShortRegex = this._weekdaysRegex;
  1844         this._weekdaysShortRegex = this._weekdaysRegex;
  1631         this._weekdaysMinRegex = this._weekdaysRegex;
  1845         this._weekdaysMinRegex = this._weekdaysRegex;
  1632 
  1846 
  1633         this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  1847         this._weekdaysStrictRegex = new RegExp(
  1634         this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  1848             '^(' + longPieces.join('|') + ')',
  1635         this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  1849             'i'
       
  1850         );
       
  1851         this._weekdaysShortStrictRegex = new RegExp(
       
  1852             '^(' + shortPieces.join('|') + ')',
       
  1853             'i'
       
  1854         );
       
  1855         this._weekdaysMinStrictRegex = new RegExp(
       
  1856             '^(' + minPieces.join('|') + ')',
       
  1857             'i'
       
  1858         );
  1636     }
  1859     }
  1637 
  1860 
  1638     // FORMATTING
  1861     // FORMATTING
  1639 
  1862 
  1640     function hFormat() {
  1863     function hFormat() {
  1652     addFormatToken('hmm', 0, 0, function () {
  1875     addFormatToken('hmm', 0, 0, function () {
  1653         return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  1876         return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  1654     });
  1877     });
  1655 
  1878 
  1656     addFormatToken('hmmss', 0, 0, function () {
  1879     addFormatToken('hmmss', 0, 0, function () {
  1657         return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  1880         return (
  1658             zeroFill(this.seconds(), 2);
  1881             '' +
       
  1882             hFormat.apply(this) +
       
  1883             zeroFill(this.minutes(), 2) +
       
  1884             zeroFill(this.seconds(), 2)
       
  1885         );
  1659     });
  1886     });
  1660 
  1887 
  1661     addFormatToken('Hmm', 0, 0, function () {
  1888     addFormatToken('Hmm', 0, 0, function () {
  1662         return '' + this.hours() + zeroFill(this.minutes(), 2);
  1889         return '' + this.hours() + zeroFill(this.minutes(), 2);
  1663     });
  1890     });
  1664 
  1891 
  1665     addFormatToken('Hmmss', 0, 0, function () {
  1892     addFormatToken('Hmmss', 0, 0, function () {
  1666         return '' + this.hours() + zeroFill(this.minutes(), 2) +
  1893         return (
  1667             zeroFill(this.seconds(), 2);
  1894             '' +
       
  1895             this.hours() +
       
  1896             zeroFill(this.minutes(), 2) +
       
  1897             zeroFill(this.seconds(), 2)
       
  1898         );
  1668     });
  1899     });
  1669 
  1900 
  1670     function meridiem (token, lowercase) {
  1901     function meridiem(token, lowercase) {
  1671         addFormatToken(token, 0, 0, function () {
  1902         addFormatToken(token, 0, 0, function () {
  1672             return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  1903             return this.localeData().meridiem(
       
  1904                 this.hours(),
       
  1905                 this.minutes(),
       
  1906                 lowercase
       
  1907             );
  1673         });
  1908         });
  1674     }
  1909     }
  1675 
  1910 
  1676     meridiem('a', true);
  1911     meridiem('a', true);
  1677     meridiem('A', false);
  1912     meridiem('A', false);
  1683     // PRIORITY
  1918     // PRIORITY
  1684     addUnitPriority('hour', 13);
  1919     addUnitPriority('hour', 13);
  1685 
  1920 
  1686     // PARSING
  1921     // PARSING
  1687 
  1922 
  1688     function matchMeridiem (isStrict, locale) {
  1923     function matchMeridiem(isStrict, locale) {
  1689         return locale._meridiemParse;
  1924         return locale._meridiemParse;
  1690     }
  1925     }
  1691 
  1926 
  1692     addRegexToken('a',  matchMeridiem);
  1927     addRegexToken('a', matchMeridiem);
  1693     addRegexToken('A',  matchMeridiem);
  1928     addRegexToken('A', matchMeridiem);
  1694     addRegexToken('H',  match1to2);
  1929     addRegexToken('H', match1to2);
  1695     addRegexToken('h',  match1to2);
  1930     addRegexToken('h', match1to2);
  1696     addRegexToken('k',  match1to2);
  1931     addRegexToken('k', match1to2);
  1697     addRegexToken('HH', match1to2, match2);
  1932     addRegexToken('HH', match1to2, match2);
  1698     addRegexToken('hh', match1to2, match2);
  1933     addRegexToken('hh', match1to2, match2);
  1699     addRegexToken('kk', match1to2, match2);
  1934     addRegexToken('kk', match1to2, match2);
  1700 
  1935 
  1701     addRegexToken('hmm', match3to4);
  1936     addRegexToken('hmm', match3to4);
  1721         array[HOUR] = toInt(input.substr(0, pos));
  1956         array[HOUR] = toInt(input.substr(0, pos));
  1722         array[MINUTE] = toInt(input.substr(pos));
  1957         array[MINUTE] = toInt(input.substr(pos));
  1723         getParsingFlags(config).bigHour = true;
  1958         getParsingFlags(config).bigHour = true;
  1724     });
  1959     });
  1725     addParseToken('hmmss', function (input, array, config) {
  1960     addParseToken('hmmss', function (input, array, config) {
  1726         var pos1 = input.length - 4;
  1961         var pos1 = input.length - 4,
  1727         var pos2 = input.length - 2;
  1962             pos2 = input.length - 2;
  1728         array[HOUR] = toInt(input.substr(0, pos1));
  1963         array[HOUR] = toInt(input.substr(0, pos1));
  1729         array[MINUTE] = toInt(input.substr(pos1, 2));
  1964         array[MINUTE] = toInt(input.substr(pos1, 2));
  1730         array[SECOND] = toInt(input.substr(pos2));
  1965         array[SECOND] = toInt(input.substr(pos2));
  1731         getParsingFlags(config).bigHour = true;
  1966         getParsingFlags(config).bigHour = true;
  1732     });
  1967     });
  1734         var pos = input.length - 2;
  1969         var pos = input.length - 2;
  1735         array[HOUR] = toInt(input.substr(0, pos));
  1970         array[HOUR] = toInt(input.substr(0, pos));
  1736         array[MINUTE] = toInt(input.substr(pos));
  1971         array[MINUTE] = toInt(input.substr(pos));
  1737     });
  1972     });
  1738     addParseToken('Hmmss', function (input, array, config) {
  1973     addParseToken('Hmmss', function (input, array, config) {
  1739         var pos1 = input.length - 4;
  1974         var pos1 = input.length - 4,
  1740         var pos2 = input.length - 2;
  1975             pos2 = input.length - 2;
  1741         array[HOUR] = toInt(input.substr(0, pos1));
  1976         array[HOUR] = toInt(input.substr(0, pos1));
  1742         array[MINUTE] = toInt(input.substr(pos1, 2));
  1977         array[MINUTE] = toInt(input.substr(pos1, 2));
  1743         array[SECOND] = toInt(input.substr(pos2));
  1978         array[SECOND] = toInt(input.substr(pos2));
  1744     });
  1979     });
  1745 
  1980 
  1746     // LOCALES
  1981     // LOCALES
  1747 
  1982 
  1748     function localeIsPM (input) {
  1983     function localeIsPM(input) {
  1749         // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  1984         // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  1750         // Using charAt should be more compatible.
  1985         // Using charAt should be more compatible.
  1751         return ((input + '').toLowerCase().charAt(0) === 'p');
  1986         return (input + '').toLowerCase().charAt(0) === 'p';
  1752     }
  1987     }
  1753 
  1988 
  1754     var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  1989     var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
  1755     function localeMeridiem (hours, minutes, isLower) {
  1990         // Setting the hour should keep the time, because the user explicitly
       
  1991         // specified which hour they want. So trying to maintain the same hour (in
       
  1992         // a new timezone) makes sense. Adding/subtracting hours does not follow
       
  1993         // this rule.
       
  1994         getSetHour = makeGetSet('Hours', true);
       
  1995 
       
  1996     function localeMeridiem(hours, minutes, isLower) {
  1756         if (hours > 11) {
  1997         if (hours > 11) {
  1757             return isLower ? 'pm' : 'PM';
  1998             return isLower ? 'pm' : 'PM';
  1758         } else {
  1999         } else {
  1759             return isLower ? 'am' : 'AM';
  2000             return isLower ? 'am' : 'AM';
  1760         }
  2001         }
  1761     }
  2002     }
  1762 
       
  1763 
       
  1764     // MOMENTS
       
  1765 
       
  1766     // Setting the hour should keep the time, because the user explicitly
       
  1767     // specified which hour they want. So trying to maintain the same hour (in
       
  1768     // a new timezone) makes sense. Adding/subtracting hours does not follow
       
  1769     // this rule.
       
  1770     var getSetHour = makeGetSet('Hours', true);
       
  1771 
  2003 
  1772     var baseConfig = {
  2004     var baseConfig = {
  1773         calendar: defaultCalendar,
  2005         calendar: defaultCalendar,
  1774         longDateFormat: defaultLongDateFormat,
  2006         longDateFormat: defaultLongDateFormat,
  1775         invalidDate: defaultInvalidDate,
  2007         invalidDate: defaultInvalidDate,
  1784 
  2016 
  1785         weekdays: defaultLocaleWeekdays,
  2017         weekdays: defaultLocaleWeekdays,
  1786         weekdaysMin: defaultLocaleWeekdaysMin,
  2018         weekdaysMin: defaultLocaleWeekdaysMin,
  1787         weekdaysShort: defaultLocaleWeekdaysShort,
  2019         weekdaysShort: defaultLocaleWeekdaysShort,
  1788 
  2020 
  1789         meridiemParse: defaultLocaleMeridiemParse
  2021         meridiemParse: defaultLocaleMeridiemParse,
  1790     };
  2022     };
  1791 
  2023 
  1792     // internal storage for locale config files
  2024     // internal storage for locale config files
  1793     var locales = {};
  2025     var locales = {},
  1794     var localeFamilies = {};
  2026         localeFamilies = {},
  1795     var globalLocale;
  2027         globalLocale;
       
  2028 
       
  2029     function commonPrefix(arr1, arr2) {
       
  2030         var i,
       
  2031             minl = Math.min(arr1.length, arr2.length);
       
  2032         for (i = 0; i < minl; i += 1) {
       
  2033             if (arr1[i] !== arr2[i]) {
       
  2034                 return i;
       
  2035             }
       
  2036         }
       
  2037         return minl;
       
  2038     }
  1796 
  2039 
  1797     function normalizeLocale(key) {
  2040     function normalizeLocale(key) {
  1798         return key ? key.toLowerCase().replace('_', '-') : key;
  2041         return key ? key.toLowerCase().replace('_', '-') : key;
  1799     }
  2042     }
  1800 
  2043 
  1801     // pick the locale from the array
  2044     // pick the locale from the array
  1802     // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  2045     // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  1803     // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  2046     // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  1804     function chooseLocale(names) {
  2047     function chooseLocale(names) {
  1805         var i = 0, j, next, locale, split;
  2048         var i = 0,
       
  2049             j,
       
  2050             next,
       
  2051             locale,
       
  2052             split;
  1806 
  2053 
  1807         while (i < names.length) {
  2054         while (i < names.length) {
  1808             split = normalizeLocale(names[i]).split('-');
  2055             split = normalizeLocale(names[i]).split('-');
  1809             j = split.length;
  2056             j = split.length;
  1810             next = normalizeLocale(names[i + 1]);
  2057             next = normalizeLocale(names[i + 1]);
  1812             while (j > 0) {
  2059             while (j > 0) {
  1813                 locale = loadLocale(split.slice(0, j).join('-'));
  2060                 locale = loadLocale(split.slice(0, j).join('-'));
  1814                 if (locale) {
  2061                 if (locale) {
  1815                     return locale;
  2062                     return locale;
  1816                 }
  2063                 }
  1817                 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  2064                 if (
       
  2065                     next &&
       
  2066                     next.length >= j &&
       
  2067                     commonPrefix(split, next) >= j - 1
       
  2068                 ) {
  1818                     //the next array item is better than a shallower substring of this one
  2069                     //the next array item is better than a shallower substring of this one
  1819                     break;
  2070                     break;
  1820                 }
  2071                 }
  1821                 j--;
  2072                 j--;
  1822             }
  2073             }
  1824         }
  2075         }
  1825         return globalLocale;
  2076         return globalLocale;
  1826     }
  2077     }
  1827 
  2078 
  1828     function loadLocale(name) {
  2079     function loadLocale(name) {
  1829         var oldLocale = null;
  2080         var oldLocale = null,
       
  2081             aliasedRequire;
  1830         // TODO: Find a better way to register and load all the locales in Node
  2082         // TODO: Find a better way to register and load all the locales in Node
  1831         if (!locales[name] && (typeof module !== 'undefined') &&
  2083         if (
  1832                 module && module.exports) {
  2084             locales[name] === undefined &&
       
  2085             typeof module !== 'undefined' &&
       
  2086             module &&
       
  2087             module.exports
       
  2088         ) {
  1833             try {
  2089             try {
  1834                 oldLocale = globalLocale._abbr;
  2090                 oldLocale = globalLocale._abbr;
  1835                 var aliasedRequire = require;
  2091                 aliasedRequire = require;
  1836                 aliasedRequire('./locale/' + name);
  2092                 aliasedRequire('./locale/' + name);
  1837                 getSetGlobalLocale(oldLocale);
  2093                 getSetGlobalLocale(oldLocale);
  1838             } catch (e) {}
  2094             } catch (e) {
       
  2095                 // mark as not found to avoid repeating expensive file require call causing high CPU
       
  2096                 // when trying to find en-US, en_US, en-us for every format call
       
  2097                 locales[name] = null; // null means not found
       
  2098             }
  1839         }
  2099         }
  1840         return locales[name];
  2100         return locales[name];
  1841     }
  2101     }
  1842 
  2102 
  1843     // This function will load locale and then set the global locale.  If
  2103     // This function will load locale and then set the global locale.  If
  1844     // no arguments are passed in, it will simply return the current global
  2104     // no arguments are passed in, it will simply return the current global
  1845     // locale key.
  2105     // locale key.
  1846     function getSetGlobalLocale (key, values) {
  2106     function getSetGlobalLocale(key, values) {
  1847         var data;
  2107         var data;
  1848         if (key) {
  2108         if (key) {
  1849             if (isUndefined(values)) {
  2109             if (isUndefined(values)) {
  1850                 data = getLocale(key);
  2110                 data = getLocale(key);
  1851             }
  2111             } else {
  1852             else {
       
  1853                 data = defineLocale(key, values);
  2112                 data = defineLocale(key, values);
  1854             }
  2113             }
  1855 
  2114 
  1856             if (data) {
  2115             if (data) {
  1857                 // moment.duration._locale = moment._locale = data;
  2116                 // moment.duration._locale = moment._locale = data;
  1858                 globalLocale = data;
  2117                 globalLocale = data;
  1859             }
  2118             } else {
  1860             else {
  2119                 if (typeof console !== 'undefined' && console.warn) {
  1861                 if ((typeof console !==  'undefined') && console.warn) {
       
  1862                     //warn user if arguments are passed but the locale could not be set
  2120                     //warn user if arguments are passed but the locale could not be set
  1863                     console.warn('Locale ' + key +  ' not found. Did you forget to load it?');
  2121                     console.warn(
       
  2122                         'Locale ' + key + ' not found. Did you forget to load it?'
       
  2123                     );
  1864                 }
  2124                 }
  1865             }
  2125             }
  1866         }
  2126         }
  1867 
  2127 
  1868         return globalLocale._abbr;
  2128         return globalLocale._abbr;
  1869     }
  2129     }
  1870 
  2130 
  1871     function defineLocale (name, config) {
  2131     function defineLocale(name, config) {
  1872         if (config !== null) {
  2132         if (config !== null) {
  1873             var locale, parentConfig = baseConfig;
  2133             var locale,
       
  2134                 parentConfig = baseConfig;
  1874             config.abbr = name;
  2135             config.abbr = name;
  1875             if (locales[name] != null) {
  2136             if (locales[name] != null) {
  1876                 deprecateSimple('defineLocaleOverride',
  2137                 deprecateSimple(
  1877                         'use moment.updateLocale(localeName, config) to change ' +
  2138                     'defineLocaleOverride',
       
  2139                     'use moment.updateLocale(localeName, config) to change ' +
  1878                         'an existing locale. moment.defineLocale(localeName, ' +
  2140                         'an existing locale. moment.defineLocale(localeName, ' +
  1879                         'config) should only be used for creating a new locale ' +
  2141                         'config) should only be used for creating a new locale ' +
  1880                         'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
  2142                         'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'
       
  2143                 );
  1881                 parentConfig = locales[name]._config;
  2144                 parentConfig = locales[name]._config;
  1882             } else if (config.parentLocale != null) {
  2145             } else if (config.parentLocale != null) {
  1883                 if (locales[config.parentLocale] != null) {
  2146                 if (locales[config.parentLocale] != null) {
  1884                     parentConfig = locales[config.parentLocale]._config;
  2147                     parentConfig = locales[config.parentLocale]._config;
  1885                 } else {
  2148                 } else {
  1890                         if (!localeFamilies[config.parentLocale]) {
  2153                         if (!localeFamilies[config.parentLocale]) {
  1891                             localeFamilies[config.parentLocale] = [];
  2154                             localeFamilies[config.parentLocale] = [];
  1892                         }
  2155                         }
  1893                         localeFamilies[config.parentLocale].push({
  2156                         localeFamilies[config.parentLocale].push({
  1894                             name: name,
  2157                             name: name,
  1895                             config: config
  2158                             config: config,
  1896                         });
  2159                         });
  1897                         return null;
  2160                         return null;
  1898                     }
  2161                     }
  1899                 }
  2162                 }
  1900             }
  2163             }
  1908 
  2171 
  1909             // backwards compat for now: also set the locale
  2172             // backwards compat for now: also set the locale
  1910             // make sure we set the locale AFTER all child locales have been
  2173             // make sure we set the locale AFTER all child locales have been
  1911             // created, so we won't end up with the child locale set.
  2174             // created, so we won't end up with the child locale set.
  1912             getSetGlobalLocale(name);
  2175             getSetGlobalLocale(name);
  1913 
       
  1914 
  2176 
  1915             return locales[name];
  2177             return locales[name];
  1916         } else {
  2178         } else {
  1917             // useful for testing
  2179             // useful for testing
  1918             delete locales[name];
  2180             delete locales[name];
  1920         }
  2182         }
  1921     }
  2183     }
  1922 
  2184 
  1923     function updateLocale(name, config) {
  2185     function updateLocale(name, config) {
  1924         if (config != null) {
  2186         if (config != null) {
  1925             var locale, tmpLocale, parentConfig = baseConfig;
  2187             var locale,
  1926             // MERGE
  2188                 tmpLocale,
  1927             tmpLocale = loadLocale(name);
  2189                 parentConfig = baseConfig;
  1928             if (tmpLocale != null) {
  2190 
  1929                 parentConfig = tmpLocale._config;
  2191             if (locales[name] != null && locales[name].parentLocale != null) {
  1930             }
  2192                 // Update existing child locale in-place to avoid memory-leaks
  1931             config = mergeConfigs(parentConfig, config);
  2193                 locales[name].set(mergeConfigs(locales[name]._config, config));
  1932             locale = new Locale(config);
  2194             } else {
  1933             locale.parentLocale = locales[name];
  2195                 // MERGE
  1934             locales[name] = locale;
  2196                 tmpLocale = loadLocale(name);
       
  2197                 if (tmpLocale != null) {
       
  2198                     parentConfig = tmpLocale._config;
       
  2199                 }
       
  2200                 config = mergeConfigs(parentConfig, config);
       
  2201                 if (tmpLocale == null) {
       
  2202                     // updateLocale is called for creating a new locale
       
  2203                     // Set abbr so it will have a name (getters return
       
  2204                     // undefined otherwise).
       
  2205                     config.abbr = name;
       
  2206                 }
       
  2207                 locale = new Locale(config);
       
  2208                 locale.parentLocale = locales[name];
       
  2209                 locales[name] = locale;
       
  2210             }
  1935 
  2211 
  1936             // backwards compat for now: also set the locale
  2212             // backwards compat for now: also set the locale
  1937             getSetGlobalLocale(name);
  2213             getSetGlobalLocale(name);
  1938         } else {
  2214         } else {
  1939             // pass null for config to unupdate, useful for tests
  2215             // pass null for config to unupdate, useful for tests
  1940             if (locales[name] != null) {
  2216             if (locales[name] != null) {
  1941                 if (locales[name].parentLocale != null) {
  2217                 if (locales[name].parentLocale != null) {
  1942                     locales[name] = locales[name].parentLocale;
  2218                     locales[name] = locales[name].parentLocale;
       
  2219                     if (name === getSetGlobalLocale()) {
       
  2220                         getSetGlobalLocale(name);
       
  2221                     }
  1943                 } else if (locales[name] != null) {
  2222                 } else if (locales[name] != null) {
  1944                     delete locales[name];
  2223                     delete locales[name];
  1945                 }
  2224                 }
  1946             }
  2225             }
  1947         }
  2226         }
  1948         return locales[name];
  2227         return locales[name];
  1949     }
  2228     }
  1950 
  2229 
  1951     // returns locale data
  2230     // returns locale data
  1952     function getLocale (key) {
  2231     function getLocale(key) {
  1953         var locale;
  2232         var locale;
  1954 
  2233 
  1955         if (key && key._locale && key._locale._abbr) {
  2234         if (key && key._locale && key._locale._abbr) {
  1956             key = key._locale._abbr;
  2235             key = key._locale._abbr;
  1957         }
  2236         }
  1974 
  2253 
  1975     function listLocales() {
  2254     function listLocales() {
  1976         return keys(locales);
  2255         return keys(locales);
  1977     }
  2256     }
  1978 
  2257 
  1979     function checkOverflow (m) {
  2258     function checkOverflow(m) {
  1980         var overflow;
  2259         var overflow,
  1981         var a = m._a;
  2260             a = m._a;
  1982 
  2261 
  1983         if (a && getParsingFlags(m).overflow === -2) {
  2262         if (a && getParsingFlags(m).overflow === -2) {
  1984             overflow =
  2263             overflow =
  1985                 a[MONTH]       < 0 || a[MONTH]       > 11  ? MONTH :
  2264                 a[MONTH] < 0 || a[MONTH] > 11
  1986                 a[DATE]        < 1 || a[DATE]        > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  2265                     ? MONTH
  1987                 a[HOUR]        < 0 || a[HOUR]        > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  2266                     : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
  1988                 a[MINUTE]      < 0 || a[MINUTE]      > 59  ? MINUTE :
  2267                     ? DATE
  1989                 a[SECOND]      < 0 || a[SECOND]      > 59  ? SECOND :
  2268                     : a[HOUR] < 0 ||
  1990                 a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  2269                       a[HOUR] > 24 ||
  1991                 -1;
  2270                       (a[HOUR] === 24 &&
  1992 
  2271                           (a[MINUTE] !== 0 ||
  1993             if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  2272                               a[SECOND] !== 0 ||
       
  2273                               a[MILLISECOND] !== 0))
       
  2274                     ? HOUR
       
  2275                     : a[MINUTE] < 0 || a[MINUTE] > 59
       
  2276                     ? MINUTE
       
  2277                     : a[SECOND] < 0 || a[SECOND] > 59
       
  2278                     ? SECOND
       
  2279                     : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
       
  2280                     ? MILLISECOND
       
  2281                     : -1;
       
  2282 
       
  2283             if (
       
  2284                 getParsingFlags(m)._overflowDayOfYear &&
       
  2285                 (overflow < YEAR || overflow > DATE)
       
  2286             ) {
  1994                 overflow = DATE;
  2287                 overflow = DATE;
  1995             }
  2288             }
  1996             if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  2289             if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  1997                 overflow = WEEK;
  2290                 overflow = WEEK;
  1998             }
  2291             }
  2004         }
  2297         }
  2005 
  2298 
  2006         return m;
  2299         return m;
  2007     }
  2300     }
  2008 
  2301 
  2009     // Pick the first defined of two or three arguments.
       
  2010     function defaults(a, b, c) {
       
  2011         if (a != null) {
       
  2012             return a;
       
  2013         }
       
  2014         if (b != null) {
       
  2015             return b;
       
  2016         }
       
  2017         return c;
       
  2018     }
       
  2019 
       
  2020     function currentDateArray(config) {
       
  2021         // hooks is actually the exported moment object
       
  2022         var nowValue = new Date(hooks.now());
       
  2023         if (config._useUTC) {
       
  2024             return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
       
  2025         }
       
  2026         return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
       
  2027     }
       
  2028 
       
  2029     // convert an array to a date.
       
  2030     // the array should mirror the parameters below
       
  2031     // note: all values past the year are optional and will default to the lowest possible value.
       
  2032     // [year, month, day , hour, minute, second, millisecond]
       
  2033     function configFromArray (config) {
       
  2034         var i, date, input = [], currentDate, expectedWeekday, yearToUse;
       
  2035 
       
  2036         if (config._d) {
       
  2037             return;
       
  2038         }
       
  2039 
       
  2040         currentDate = currentDateArray(config);
       
  2041 
       
  2042         //compute day of the year from weeks and weekdays
       
  2043         if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
       
  2044             dayOfYearFromWeekInfo(config);
       
  2045         }
       
  2046 
       
  2047         //if the day of the year is set, figure out what it is
       
  2048         if (config._dayOfYear != null) {
       
  2049             yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
       
  2050 
       
  2051             if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
       
  2052                 getParsingFlags(config)._overflowDayOfYear = true;
       
  2053             }
       
  2054 
       
  2055             date = createUTCDate(yearToUse, 0, config._dayOfYear);
       
  2056             config._a[MONTH] = date.getUTCMonth();
       
  2057             config._a[DATE] = date.getUTCDate();
       
  2058         }
       
  2059 
       
  2060         // Default to current date.
       
  2061         // * if no year, month, day of month are given, default to today
       
  2062         // * if day of month is given, default month and year
       
  2063         // * if month is given, default only year
       
  2064         // * if year is given, don't default anything
       
  2065         for (i = 0; i < 3 && config._a[i] == null; ++i) {
       
  2066             config._a[i] = input[i] = currentDate[i];
       
  2067         }
       
  2068 
       
  2069         // Zero out whatever was not defaulted, including time
       
  2070         for (; i < 7; i++) {
       
  2071             config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
       
  2072         }
       
  2073 
       
  2074         // Check for 24:00:00.000
       
  2075         if (config._a[HOUR] === 24 &&
       
  2076                 config._a[MINUTE] === 0 &&
       
  2077                 config._a[SECOND] === 0 &&
       
  2078                 config._a[MILLISECOND] === 0) {
       
  2079             config._nextDay = true;
       
  2080             config._a[HOUR] = 0;
       
  2081         }
       
  2082 
       
  2083         config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
       
  2084         expectedWeekday = config._useUTC ? config._d.getUTCDay() : config._d.getDay();
       
  2085 
       
  2086         // Apply timezone offset from input. The actual utcOffset can be changed
       
  2087         // with parseZone.
       
  2088         if (config._tzm != null) {
       
  2089             config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
       
  2090         }
       
  2091 
       
  2092         if (config._nextDay) {
       
  2093             config._a[HOUR] = 24;
       
  2094         }
       
  2095 
       
  2096         // check for mismatching day of week
       
  2097         if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== expectedWeekday) {
       
  2098             getParsingFlags(config).weekdayMismatch = true;
       
  2099         }
       
  2100     }
       
  2101 
       
  2102     function dayOfYearFromWeekInfo(config) {
       
  2103         var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
       
  2104 
       
  2105         w = config._w;
       
  2106         if (w.GG != null || w.W != null || w.E != null) {
       
  2107             dow = 1;
       
  2108             doy = 4;
       
  2109 
       
  2110             // TODO: We need to take the current isoWeekYear, but that depends on
       
  2111             // how we interpret now (local, utc, fixed offset). So create
       
  2112             // a now version of current config (take local/utc/offset flags, and
       
  2113             // create now).
       
  2114             weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(createLocal(), 1, 4).year);
       
  2115             week = defaults(w.W, 1);
       
  2116             weekday = defaults(w.E, 1);
       
  2117             if (weekday < 1 || weekday > 7) {
       
  2118                 weekdayOverflow = true;
       
  2119             }
       
  2120         } else {
       
  2121             dow = config._locale._week.dow;
       
  2122             doy = config._locale._week.doy;
       
  2123 
       
  2124             var curWeek = weekOfYear(createLocal(), dow, doy);
       
  2125 
       
  2126             weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
       
  2127 
       
  2128             // Default to current week.
       
  2129             week = defaults(w.w, curWeek.week);
       
  2130 
       
  2131             if (w.d != null) {
       
  2132                 // weekday -- low day numbers are considered next week
       
  2133                 weekday = w.d;
       
  2134                 if (weekday < 0 || weekday > 6) {
       
  2135                     weekdayOverflow = true;
       
  2136                 }
       
  2137             } else if (w.e != null) {
       
  2138                 // local weekday -- counting starts from begining of week
       
  2139                 weekday = w.e + dow;
       
  2140                 if (w.e < 0 || w.e > 6) {
       
  2141                     weekdayOverflow = true;
       
  2142                 }
       
  2143             } else {
       
  2144                 // default to begining of week
       
  2145                 weekday = dow;
       
  2146             }
       
  2147         }
       
  2148         if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
       
  2149             getParsingFlags(config)._overflowWeeks = true;
       
  2150         } else if (weekdayOverflow != null) {
       
  2151             getParsingFlags(config)._overflowWeekday = true;
       
  2152         } else {
       
  2153             temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
       
  2154             config._a[YEAR] = temp.year;
       
  2155             config._dayOfYear = temp.dayOfYear;
       
  2156         }
       
  2157     }
       
  2158 
       
  2159     // iso 8601 regex
  2302     // iso 8601 regex
  2160     // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  2303     // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  2161     var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
  2304     var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
  2162     var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
  2305         basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
  2163 
  2306         tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
  2164     var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  2307         isoDates = [
  2165 
  2308             ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  2166     var isoDates = [
  2309             ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  2167         ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  2310             ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  2168         ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  2311             ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  2169         ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  2312             ['YYYY-DDD', /\d{4}-\d{3}/],
  2170         ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  2313             ['YYYY-MM', /\d{4}-\d\d/, false],
  2171         ['YYYY-DDD', /\d{4}-\d{3}/],
  2314             ['YYYYYYMMDD', /[+-]\d{10}/],
  2172         ['YYYY-MM', /\d{4}-\d\d/, false],
  2315             ['YYYYMMDD', /\d{8}/],
  2173         ['YYYYYYMMDD', /[+-]\d{10}/],
  2316             ['GGGG[W]WWE', /\d{4}W\d{3}/],
  2174         ['YYYYMMDD', /\d{8}/],
  2317             ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  2175         // YYYYMM is NOT allowed by the standard
  2318             ['YYYYDDD', /\d{7}/],
  2176         ['GGGG[W]WWE', /\d{4}W\d{3}/],
  2319             ['YYYYMM', /\d{6}/, false],
  2177         ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  2320             ['YYYY', /\d{4}/, false],
  2178         ['YYYYDDD', /\d{7}/]
  2321         ],
  2179     ];
  2322         // iso time formats and regexes
  2180 
  2323         isoTimes = [
  2181     // iso time formats and regexes
  2324             ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  2182     var isoTimes = [
  2325             ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  2183         ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  2326             ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  2184         ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  2327             ['HH:mm', /\d\d:\d\d/],
  2185         ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  2328             ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  2186         ['HH:mm', /\d\d:\d\d/],
  2329             ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  2187         ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  2330             ['HHmmss', /\d\d\d\d\d\d/],
  2188         ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  2331             ['HHmm', /\d\d\d\d/],
  2189         ['HHmmss', /\d\d\d\d\d\d/],
  2332             ['HH', /\d\d/],
  2190         ['HHmm', /\d\d\d\d/],
  2333         ],
  2191         ['HH', /\d\d/]
  2334         aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
  2192     ];
  2335         // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
  2193 
  2336         rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
  2194     var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  2337         obsOffsets = {
       
  2338             UT: 0,
       
  2339             GMT: 0,
       
  2340             EDT: -4 * 60,
       
  2341             EST: -5 * 60,
       
  2342             CDT: -5 * 60,
       
  2343             CST: -6 * 60,
       
  2344             MDT: -6 * 60,
       
  2345             MST: -7 * 60,
       
  2346             PDT: -7 * 60,
       
  2347             PST: -8 * 60,
       
  2348         };
  2195 
  2349 
  2196     // date from iso format
  2350     // date from iso format
  2197     function configFromISO(config) {
  2351     function configFromISO(config) {
  2198         var i, l,
  2352         var i,
       
  2353             l,
  2199             string = config._i,
  2354             string = config._i,
  2200             match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  2355             match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  2201             allowTime, dateFormat, timeFormat, tzFormat;
  2356             allowTime,
       
  2357             dateFormat,
       
  2358             timeFormat,
       
  2359             tzFormat;
  2202 
  2360 
  2203         if (match) {
  2361         if (match) {
  2204             getParsingFlags(config).iso = true;
  2362             getParsingFlags(config).iso = true;
  2205 
  2363 
  2206             for (i = 0, l = isoDates.length; i < l; i++) {
  2364             for (i = 0, l = isoDates.length; i < l; i++) {
  2244         } else {
  2402         } else {
  2245             config._isValid = false;
  2403             config._isValid = false;
  2246         }
  2404         }
  2247     }
  2405     }
  2248 
  2406 
  2249     // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
  2407     function extractFromRFC2822Strings(
  2250     var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/;
  2408         yearStr,
  2251 
  2409         monthStr,
  2252     function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
  2410         dayStr,
       
  2411         hourStr,
       
  2412         minuteStr,
       
  2413         secondStr
       
  2414     ) {
  2253         var result = [
  2415         var result = [
  2254             untruncateYear(yearStr),
  2416             untruncateYear(yearStr),
  2255             defaultLocaleMonthsShort.indexOf(monthStr),
  2417             defaultLocaleMonthsShort.indexOf(monthStr),
  2256             parseInt(dayStr, 10),
  2418             parseInt(dayStr, 10),
  2257             parseInt(hourStr, 10),
  2419             parseInt(hourStr, 10),
  2258             parseInt(minuteStr, 10)
  2420             parseInt(minuteStr, 10),
  2259         ];
  2421         ];
  2260 
  2422 
  2261         if (secondStr) {
  2423         if (secondStr) {
  2262             result.push(parseInt(secondStr, 10));
  2424             result.push(parseInt(secondStr, 10));
  2263         }
  2425         }
  2275         return year;
  2437         return year;
  2276     }
  2438     }
  2277 
  2439 
  2278     function preprocessRFC2822(s) {
  2440     function preprocessRFC2822(s) {
  2279         // Remove comments and folding whitespace and replace multiple-spaces with a single space
  2441         // Remove comments and folding whitespace and replace multiple-spaces with a single space
  2280         return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  2442         return s
       
  2443             .replace(/\([^)]*\)|[\n\t]/g, ' ')
       
  2444             .replace(/(\s\s+)/g, ' ')
       
  2445             .replace(/^\s\s*/, '')
       
  2446             .replace(/\s\s*$/, '');
  2281     }
  2447     }
  2282 
  2448 
  2283     function checkWeekday(weekdayStr, parsedInput, config) {
  2449     function checkWeekday(weekdayStr, parsedInput, config) {
  2284         if (weekdayStr) {
  2450         if (weekdayStr) {
  2285             // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
  2451             // TODO: Replace the vanilla JS Date object with an independent day-of-week check.
  2286             var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
  2452             var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
  2287                 weekdayActual = new Date(parsedInput[0], parsedInput[1], parsedInput[2]).getDay();
  2453                 weekdayActual = new Date(
       
  2454                     parsedInput[0],
       
  2455                     parsedInput[1],
       
  2456                     parsedInput[2]
       
  2457                 ).getDay();
  2288             if (weekdayProvided !== weekdayActual) {
  2458             if (weekdayProvided !== weekdayActual) {
  2289                 getParsingFlags(config).weekdayMismatch = true;
  2459                 getParsingFlags(config).weekdayMismatch = true;
  2290                 config._isValid = false;
  2460                 config._isValid = false;
  2291                 return false;
  2461                 return false;
  2292             }
  2462             }
  2293         }
  2463         }
  2294         return true;
  2464         return true;
  2295     }
  2465     }
  2296 
       
  2297     var obsOffsets = {
       
  2298         UT: 0,
       
  2299         GMT: 0,
       
  2300         EDT: -4 * 60,
       
  2301         EST: -5 * 60,
       
  2302         CDT: -5 * 60,
       
  2303         CST: -6 * 60,
       
  2304         MDT: -6 * 60,
       
  2305         MST: -7 * 60,
       
  2306         PDT: -7 * 60,
       
  2307         PST: -8 * 60
       
  2308     };
       
  2309 
  2466 
  2310     function calculateOffset(obsOffset, militaryOffset, numOffset) {
  2467     function calculateOffset(obsOffset, militaryOffset, numOffset) {
  2311         if (obsOffset) {
  2468         if (obsOffset) {
  2312             return obsOffsets[obsOffset];
  2469             return obsOffsets[obsOffset];
  2313         } else if (militaryOffset) {
  2470         } else if (militaryOffset) {
  2314             // the only allowed military tz is Z
  2471             // the only allowed military tz is Z
  2315             return 0;
  2472             return 0;
  2316         } else {
  2473         } else {
  2317             var hm = parseInt(numOffset, 10);
  2474             var hm = parseInt(numOffset, 10),
  2318             var m = hm % 100, h = (hm - m) / 100;
  2475                 m = hm % 100,
       
  2476                 h = (hm - m) / 100;
  2319             return h * 60 + m;
  2477             return h * 60 + m;
  2320         }
  2478         }
  2321     }
  2479     }
  2322 
  2480 
  2323     // date and time from ref 2822 format
  2481     // date and time from ref 2822 format
  2324     function configFromRFC2822(config) {
  2482     function configFromRFC2822(config) {
  2325         var match = rfc2822.exec(preprocessRFC2822(config._i));
  2483         var match = rfc2822.exec(preprocessRFC2822(config._i)),
       
  2484             parsedArray;
  2326         if (match) {
  2485         if (match) {
  2327             var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
  2486             parsedArray = extractFromRFC2822Strings(
       
  2487                 match[4],
       
  2488                 match[3],
       
  2489                 match[2],
       
  2490                 match[5],
       
  2491                 match[6],
       
  2492                 match[7]
       
  2493             );
  2328             if (!checkWeekday(match[1], parsedArray, config)) {
  2494             if (!checkWeekday(match[1], parsedArray, config)) {
  2329                 return;
  2495                 return;
  2330             }
  2496             }
  2331 
  2497 
  2332             config._a = parsedArray;
  2498             config._a = parsedArray;
  2339         } else {
  2505         } else {
  2340             config._isValid = false;
  2506             config._isValid = false;
  2341         }
  2507         }
  2342     }
  2508     }
  2343 
  2509 
  2344     // date from iso format or fallback
  2510     // date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict
  2345     function configFromString(config) {
  2511     function configFromString(config) {
  2346         var matched = aspNetJsonRegex.exec(config._i);
  2512         var matched = aspNetJsonRegex.exec(config._i);
  2347 
       
  2348         if (matched !== null) {
  2513         if (matched !== null) {
  2349             config._d = new Date(+matched[1]);
  2514             config._d = new Date(+matched[1]);
  2350             return;
  2515             return;
  2351         }
  2516         }
  2352 
  2517 
  2362             delete config._isValid;
  2527             delete config._isValid;
  2363         } else {
  2528         } else {
  2364             return;
  2529             return;
  2365         }
  2530         }
  2366 
  2531 
  2367         // Final attempt, use Input Fallback
  2532         if (config._strict) {
  2368         hooks.createFromInputFallback(config);
  2533             config._isValid = false;
       
  2534         } else {
       
  2535             // Final attempt, use Input Fallback
       
  2536             hooks.createFromInputFallback(config);
       
  2537         }
  2369     }
  2538     }
  2370 
  2539 
  2371     hooks.createFromInputFallback = deprecate(
  2540     hooks.createFromInputFallback = deprecate(
  2372         'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
  2541         'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
  2373         'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
  2542             'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
  2374         'discouraged and will be removed in an upcoming major release. Please refer to ' +
  2543             'discouraged and will be removed in an upcoming major release. Please refer to ' +
  2375         'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  2544             'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  2376         function (config) {
  2545         function (config) {
  2377             config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  2546             config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  2378         }
  2547         }
  2379     );
  2548     );
       
  2549 
       
  2550     // Pick the first defined of two or three arguments.
       
  2551     function defaults(a, b, c) {
       
  2552         if (a != null) {
       
  2553             return a;
       
  2554         }
       
  2555         if (b != null) {
       
  2556             return b;
       
  2557         }
       
  2558         return c;
       
  2559     }
       
  2560 
       
  2561     function currentDateArray(config) {
       
  2562         // hooks is actually the exported moment object
       
  2563         var nowValue = new Date(hooks.now());
       
  2564         if (config._useUTC) {
       
  2565             return [
       
  2566                 nowValue.getUTCFullYear(),
       
  2567                 nowValue.getUTCMonth(),
       
  2568                 nowValue.getUTCDate(),
       
  2569             ];
       
  2570         }
       
  2571         return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
       
  2572     }
       
  2573 
       
  2574     // convert an array to a date.
       
  2575     // the array should mirror the parameters below
       
  2576     // note: all values past the year are optional and will default to the lowest possible value.
       
  2577     // [year, month, day , hour, minute, second, millisecond]
       
  2578     function configFromArray(config) {
       
  2579         var i,
       
  2580             date,
       
  2581             input = [],
       
  2582             currentDate,
       
  2583             expectedWeekday,
       
  2584             yearToUse;
       
  2585 
       
  2586         if (config._d) {
       
  2587             return;
       
  2588         }
       
  2589 
       
  2590         currentDate = currentDateArray(config);
       
  2591 
       
  2592         //compute day of the year from weeks and weekdays
       
  2593         if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
       
  2594             dayOfYearFromWeekInfo(config);
       
  2595         }
       
  2596 
       
  2597         //if the day of the year is set, figure out what it is
       
  2598         if (config._dayOfYear != null) {
       
  2599             yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
       
  2600 
       
  2601             if (
       
  2602                 config._dayOfYear > daysInYear(yearToUse) ||
       
  2603                 config._dayOfYear === 0
       
  2604             ) {
       
  2605                 getParsingFlags(config)._overflowDayOfYear = true;
       
  2606             }
       
  2607 
       
  2608             date = createUTCDate(yearToUse, 0, config._dayOfYear);
       
  2609             config._a[MONTH] = date.getUTCMonth();
       
  2610             config._a[DATE] = date.getUTCDate();
       
  2611         }
       
  2612 
       
  2613         // Default to current date.
       
  2614         // * if no year, month, day of month are given, default to today
       
  2615         // * if day of month is given, default month and year
       
  2616         // * if month is given, default only year
       
  2617         // * if year is given, don't default anything
       
  2618         for (i = 0; i < 3 && config._a[i] == null; ++i) {
       
  2619             config._a[i] = input[i] = currentDate[i];
       
  2620         }
       
  2621 
       
  2622         // Zero out whatever was not defaulted, including time
       
  2623         for (; i < 7; i++) {
       
  2624             config._a[i] = input[i] =
       
  2625                 config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
       
  2626         }
       
  2627 
       
  2628         // Check for 24:00:00.000
       
  2629         if (
       
  2630             config._a[HOUR] === 24 &&
       
  2631             config._a[MINUTE] === 0 &&
       
  2632             config._a[SECOND] === 0 &&
       
  2633             config._a[MILLISECOND] === 0
       
  2634         ) {
       
  2635             config._nextDay = true;
       
  2636             config._a[HOUR] = 0;
       
  2637         }
       
  2638 
       
  2639         config._d = (config._useUTC ? createUTCDate : createDate).apply(
       
  2640             null,
       
  2641             input
       
  2642         );
       
  2643         expectedWeekday = config._useUTC
       
  2644             ? config._d.getUTCDay()
       
  2645             : config._d.getDay();
       
  2646 
       
  2647         // Apply timezone offset from input. The actual utcOffset can be changed
       
  2648         // with parseZone.
       
  2649         if (config._tzm != null) {
       
  2650             config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
       
  2651         }
       
  2652 
       
  2653         if (config._nextDay) {
       
  2654             config._a[HOUR] = 24;
       
  2655         }
       
  2656 
       
  2657         // check for mismatching day of week
       
  2658         if (
       
  2659             config._w &&
       
  2660             typeof config._w.d !== 'undefined' &&
       
  2661             config._w.d !== expectedWeekday
       
  2662         ) {
       
  2663             getParsingFlags(config).weekdayMismatch = true;
       
  2664         }
       
  2665     }
       
  2666 
       
  2667     function dayOfYearFromWeekInfo(config) {
       
  2668         var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
       
  2669 
       
  2670         w = config._w;
       
  2671         if (w.GG != null || w.W != null || w.E != null) {
       
  2672             dow = 1;
       
  2673             doy = 4;
       
  2674 
       
  2675             // TODO: We need to take the current isoWeekYear, but that depends on
       
  2676             // how we interpret now (local, utc, fixed offset). So create
       
  2677             // a now version of current config (take local/utc/offset flags, and
       
  2678             // create now).
       
  2679             weekYear = defaults(
       
  2680                 w.GG,
       
  2681                 config._a[YEAR],
       
  2682                 weekOfYear(createLocal(), 1, 4).year
       
  2683             );
       
  2684             week = defaults(w.W, 1);
       
  2685             weekday = defaults(w.E, 1);
       
  2686             if (weekday < 1 || weekday > 7) {
       
  2687                 weekdayOverflow = true;
       
  2688             }
       
  2689         } else {
       
  2690             dow = config._locale._week.dow;
       
  2691             doy = config._locale._week.doy;
       
  2692 
       
  2693             curWeek = weekOfYear(createLocal(), dow, doy);
       
  2694 
       
  2695             weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
       
  2696 
       
  2697             // Default to current week.
       
  2698             week = defaults(w.w, curWeek.week);
       
  2699 
       
  2700             if (w.d != null) {
       
  2701                 // weekday -- low day numbers are considered next week
       
  2702                 weekday = w.d;
       
  2703                 if (weekday < 0 || weekday > 6) {
       
  2704                     weekdayOverflow = true;
       
  2705                 }
       
  2706             } else if (w.e != null) {
       
  2707                 // local weekday -- counting starts from beginning of week
       
  2708                 weekday = w.e + dow;
       
  2709                 if (w.e < 0 || w.e > 6) {
       
  2710                     weekdayOverflow = true;
       
  2711                 }
       
  2712             } else {
       
  2713                 // default to beginning of week
       
  2714                 weekday = dow;
       
  2715             }
       
  2716         }
       
  2717         if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
       
  2718             getParsingFlags(config)._overflowWeeks = true;
       
  2719         } else if (weekdayOverflow != null) {
       
  2720             getParsingFlags(config)._overflowWeekday = true;
       
  2721         } else {
       
  2722             temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
       
  2723             config._a[YEAR] = temp.year;
       
  2724             config._dayOfYear = temp.dayOfYear;
       
  2725         }
       
  2726     }
  2380 
  2727 
  2381     // constant that refers to the ISO standard
  2728     // constant that refers to the ISO standard
  2382     hooks.ISO_8601 = function () {};
  2729     hooks.ISO_8601 = function () {};
  2383 
  2730 
  2384     // constant that refers to the RFC 2822 form
  2731     // constant that refers to the RFC 2822 form
  2398         config._a = [];
  2745         config._a = [];
  2399         getParsingFlags(config).empty = true;
  2746         getParsingFlags(config).empty = true;
  2400 
  2747 
  2401         // This array is used to make a Date, either with `new Date` or `Date.UTC`
  2748         // This array is used to make a Date, either with `new Date` or `Date.UTC`
  2402         var string = '' + config._i,
  2749         var string = '' + config._i,
  2403             i, parsedInput, tokens, token, skipped,
  2750             i,
       
  2751             parsedInput,
       
  2752             tokens,
       
  2753             token,
       
  2754             skipped,
  2404             stringLength = string.length,
  2755             stringLength = string.length,
  2405             totalParsedInputLength = 0;
  2756             totalParsedInputLength = 0,
  2406 
  2757             era;
  2407         tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  2758 
       
  2759         tokens =
       
  2760             expandFormat(config._f, config._locale).match(formattingTokens) || [];
  2408 
  2761 
  2409         for (i = 0; i < tokens.length; i++) {
  2762         for (i = 0; i < tokens.length; i++) {
  2410             token = tokens[i];
  2763             token = tokens[i];
  2411             parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  2764             parsedInput = (string.match(getParseRegexForToken(token, config)) ||
  2412             // console.log('token', token, 'parsedInput', parsedInput,
  2765                 [])[0];
  2413             //         'regex', getParseRegexForToken(token, config));
       
  2414             if (parsedInput) {
  2766             if (parsedInput) {
  2415                 skipped = string.substr(0, string.indexOf(parsedInput));
  2767                 skipped = string.substr(0, string.indexOf(parsedInput));
  2416                 if (skipped.length > 0) {
  2768                 if (skipped.length > 0) {
  2417                     getParsingFlags(config).unusedInput.push(skipped);
  2769                     getParsingFlags(config).unusedInput.push(skipped);
  2418                 }
  2770                 }
  2419                 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  2771                 string = string.slice(
       
  2772                     string.indexOf(parsedInput) + parsedInput.length
       
  2773                 );
  2420                 totalParsedInputLength += parsedInput.length;
  2774                 totalParsedInputLength += parsedInput.length;
  2421             }
  2775             }
  2422             // don't parse if it's not a known token
  2776             // don't parse if it's not a known token
  2423             if (formatTokenFunctions[token]) {
  2777             if (formatTokenFunctions[token]) {
  2424                 if (parsedInput) {
  2778                 if (parsedInput) {
  2425                     getParsingFlags(config).empty = false;
  2779                     getParsingFlags(config).empty = false;
  2426                 }
  2780                 } else {
  2427                 else {
       
  2428                     getParsingFlags(config).unusedTokens.push(token);
  2781                     getParsingFlags(config).unusedTokens.push(token);
  2429                 }
  2782                 }
  2430                 addTimeToArrayFromToken(token, parsedInput, config);
  2783                 addTimeToArrayFromToken(token, parsedInput, config);
  2431             }
  2784             } else if (config._strict && !parsedInput) {
  2432             else if (config._strict && !parsedInput) {
       
  2433                 getParsingFlags(config).unusedTokens.push(token);
  2785                 getParsingFlags(config).unusedTokens.push(token);
  2434             }
  2786             }
  2435         }
  2787         }
  2436 
  2788 
  2437         // add remaining unparsed input length to the string
  2789         // add remaining unparsed input length to the string
  2438         getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  2790         getParsingFlags(config).charsLeftOver =
       
  2791             stringLength - totalParsedInputLength;
  2439         if (string.length > 0) {
  2792         if (string.length > 0) {
  2440             getParsingFlags(config).unusedInput.push(string);
  2793             getParsingFlags(config).unusedInput.push(string);
  2441         }
  2794         }
  2442 
  2795 
  2443         // clear _12h flag if hour is <= 12
  2796         // clear _12h flag if hour is <= 12
  2444         if (config._a[HOUR] <= 12 &&
  2797         if (
       
  2798             config._a[HOUR] <= 12 &&
  2445             getParsingFlags(config).bigHour === true &&
  2799             getParsingFlags(config).bigHour === true &&
  2446             config._a[HOUR] > 0) {
  2800             config._a[HOUR] > 0
       
  2801         ) {
  2447             getParsingFlags(config).bigHour = undefined;
  2802             getParsingFlags(config).bigHour = undefined;
  2448         }
  2803         }
  2449 
  2804 
  2450         getParsingFlags(config).parsedDateParts = config._a.slice(0);
  2805         getParsingFlags(config).parsedDateParts = config._a.slice(0);
  2451         getParsingFlags(config).meridiem = config._meridiem;
  2806         getParsingFlags(config).meridiem = config._meridiem;
  2452         // handle meridiem
  2807         // handle meridiem
  2453         config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  2808         config._a[HOUR] = meridiemFixWrap(
       
  2809             config._locale,
       
  2810             config._a[HOUR],
       
  2811             config._meridiem
       
  2812         );
       
  2813 
       
  2814         // handle era
       
  2815         era = getParsingFlags(config).era;
       
  2816         if (era !== null) {
       
  2817             config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
       
  2818         }
  2454 
  2819 
  2455         configFromArray(config);
  2820         configFromArray(config);
  2456         checkOverflow(config);
  2821         checkOverflow(config);
  2457     }
  2822     }
  2458 
  2823 
  2459 
  2824     function meridiemFixWrap(locale, hour, meridiem) {
  2460     function meridiemFixWrap (locale, hour, meridiem) {
       
  2461         var isPm;
  2825         var isPm;
  2462 
  2826 
  2463         if (meridiem == null) {
  2827         if (meridiem == null) {
  2464             // nothing to do
  2828             // nothing to do
  2465             return hour;
  2829             return hour;
  2484 
  2848 
  2485     // date from string and array of format strings
  2849     // date from string and array of format strings
  2486     function configFromStringAndArray(config) {
  2850     function configFromStringAndArray(config) {
  2487         var tempConfig,
  2851         var tempConfig,
  2488             bestMoment,
  2852             bestMoment,
  2489 
       
  2490             scoreToBeat,
  2853             scoreToBeat,
  2491             i,
  2854             i,
  2492             currentScore;
  2855             currentScore,
       
  2856             validFormatFound,
       
  2857             bestFormatIsValid = false;
  2493 
  2858 
  2494         if (config._f.length === 0) {
  2859         if (config._f.length === 0) {
  2495             getParsingFlags(config).invalidFormat = true;
  2860             getParsingFlags(config).invalidFormat = true;
  2496             config._d = new Date(NaN);
  2861             config._d = new Date(NaN);
  2497             return;
  2862             return;
  2498         }
  2863         }
  2499 
  2864 
  2500         for (i = 0; i < config._f.length; i++) {
  2865         for (i = 0; i < config._f.length; i++) {
  2501             currentScore = 0;
  2866             currentScore = 0;
       
  2867             validFormatFound = false;
  2502             tempConfig = copyConfig({}, config);
  2868             tempConfig = copyConfig({}, config);
  2503             if (config._useUTC != null) {
  2869             if (config._useUTC != null) {
  2504                 tempConfig._useUTC = config._useUTC;
  2870                 tempConfig._useUTC = config._useUTC;
  2505             }
  2871             }
  2506             tempConfig._f = config._f[i];
  2872             tempConfig._f = config._f[i];
  2507             configFromStringAndFormat(tempConfig);
  2873             configFromStringAndFormat(tempConfig);
  2508 
  2874 
  2509             if (!isValid(tempConfig)) {
  2875             if (isValid(tempConfig)) {
  2510                 continue;
  2876                 validFormatFound = true;
  2511             }
  2877             }
  2512 
  2878 
  2513             // if there is any input that was not parsed add a penalty for that format
  2879             // if there is any input that was not parsed add a penalty for that format
  2514             currentScore += getParsingFlags(tempConfig).charsLeftOver;
  2880             currentScore += getParsingFlags(tempConfig).charsLeftOver;
  2515 
  2881 
  2516             //or tokens
  2882             //or tokens
  2517             currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  2883             currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  2518 
  2884 
  2519             getParsingFlags(tempConfig).score = currentScore;
  2885             getParsingFlags(tempConfig).score = currentScore;
  2520 
  2886 
  2521             if (scoreToBeat == null || currentScore < scoreToBeat) {
  2887             if (!bestFormatIsValid) {
  2522                 scoreToBeat = currentScore;
  2888                 if (
  2523                 bestMoment = tempConfig;
  2889                     scoreToBeat == null ||
       
  2890                     currentScore < scoreToBeat ||
       
  2891                     validFormatFound
       
  2892                 ) {
       
  2893                     scoreToBeat = currentScore;
       
  2894                     bestMoment = tempConfig;
       
  2895                     if (validFormatFound) {
       
  2896                         bestFormatIsValid = true;
       
  2897                     }
       
  2898                 }
       
  2899             } else {
       
  2900                 if (currentScore < scoreToBeat) {
       
  2901                     scoreToBeat = currentScore;
       
  2902                     bestMoment = tempConfig;
       
  2903                 }
  2524             }
  2904             }
  2525         }
  2905         }
  2526 
  2906 
  2527         extend(config, bestMoment || tempConfig);
  2907         extend(config, bestMoment || tempConfig);
  2528     }
  2908     }
  2530     function configFromObject(config) {
  2910     function configFromObject(config) {
  2531         if (config._d) {
  2911         if (config._d) {
  2532             return;
  2912             return;
  2533         }
  2913         }
  2534 
  2914 
  2535         var i = normalizeObjectUnits(config._i);
  2915         var i = normalizeObjectUnits(config._i),
  2536         config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  2916             dayOrDate = i.day === undefined ? i.date : i.day;
  2537             return obj && parseInt(obj, 10);
  2917         config._a = map(
  2538         });
  2918             [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
       
  2919             function (obj) {
       
  2920                 return obj && parseInt(obj, 10);
       
  2921             }
       
  2922         );
  2539 
  2923 
  2540         configFromArray(config);
  2924         configFromArray(config);
  2541     }
  2925     }
  2542 
  2926 
  2543     function createFromConfig (config) {
  2927     function createFromConfig(config) {
  2544         var res = new Moment(checkOverflow(prepareConfig(config)));
  2928         var res = new Moment(checkOverflow(prepareConfig(config)));
  2545         if (res._nextDay) {
  2929         if (res._nextDay) {
  2546             // Adding is smart enough around DST
  2930             // Adding is smart enough around DST
  2547             res.add(1, 'd');
  2931             res.add(1, 'd');
  2548             res._nextDay = undefined;
  2932             res._nextDay = undefined;
  2549         }
  2933         }
  2550 
  2934 
  2551         return res;
  2935         return res;
  2552     }
  2936     }
  2553 
  2937 
  2554     function prepareConfig (config) {
  2938     function prepareConfig(config) {
  2555         var input = config._i,
  2939         var input = config._i,
  2556             format = config._f;
  2940             format = config._f;
  2557 
  2941 
  2558         config._locale = config._locale || getLocale(config._l);
  2942         config._locale = config._locale || getLocale(config._l);
  2559 
  2943 
  2560         if (input === null || (format === undefined && input === '')) {
  2944         if (input === null || (format === undefined && input === '')) {
  2561             return createInvalid({nullInput: true});
  2945             return createInvalid({ nullInput: true });
  2562         }
  2946         }
  2563 
  2947 
  2564         if (typeof input === 'string') {
  2948         if (typeof input === 'string') {
  2565             config._i = input = config._locale.preparse(input);
  2949             config._i = input = config._locale.preparse(input);
  2566         }
  2950         }
  2571             config._d = input;
  2955             config._d = input;
  2572         } else if (isArray(format)) {
  2956         } else if (isArray(format)) {
  2573             configFromStringAndArray(config);
  2957             configFromStringAndArray(config);
  2574         } else if (format) {
  2958         } else if (format) {
  2575             configFromStringAndFormat(config);
  2959             configFromStringAndFormat(config);
  2576         }  else {
  2960         } else {
  2577             configFromInput(config);
  2961             configFromInput(config);
  2578         }
  2962         }
  2579 
  2963 
  2580         if (!isValid(config)) {
  2964         if (!isValid(config)) {
  2581             config._d = null;
  2965             config._d = null;
  2605         } else {
  2989         } else {
  2606             hooks.createFromInputFallback(config);
  2990             hooks.createFromInputFallback(config);
  2607         }
  2991         }
  2608     }
  2992     }
  2609 
  2993 
  2610     function createLocalOrUTC (input, format, locale, strict, isUTC) {
  2994     function createLocalOrUTC(input, format, locale, strict, isUTC) {
  2611         var c = {};
  2995         var c = {};
       
  2996 
       
  2997         if (format === true || format === false) {
       
  2998             strict = format;
       
  2999             format = undefined;
       
  3000         }
  2612 
  3001 
  2613         if (locale === true || locale === false) {
  3002         if (locale === true || locale === false) {
  2614             strict = locale;
  3003             strict = locale;
  2615             locale = undefined;
  3004             locale = undefined;
  2616         }
  3005         }
  2617 
  3006 
  2618         if ((isObject(input) && isObjectEmpty(input)) ||
  3007         if (
  2619                 (isArray(input) && input.length === 0)) {
  3008             (isObject(input) && isObjectEmpty(input)) ||
       
  3009             (isArray(input) && input.length === 0)
       
  3010         ) {
  2620             input = undefined;
  3011             input = undefined;
  2621         }
  3012         }
  2622         // object construction must be done this way.
  3013         // object construction must be done this way.
  2623         // https://github.com/moment/moment/issues/1423
  3014         // https://github.com/moment/moment/issues/1423
  2624         c._isAMomentObject = true;
  3015         c._isAMomentObject = true;
  2629         c._strict = strict;
  3020         c._strict = strict;
  2630 
  3021 
  2631         return createFromConfig(c);
  3022         return createFromConfig(c);
  2632     }
  3023     }
  2633 
  3024 
  2634     function createLocal (input, format, locale, strict) {
  3025     function createLocal(input, format, locale, strict) {
  2635         return createLocalOrUTC(input, format, locale, strict, false);
  3026         return createLocalOrUTC(input, format, locale, strict, false);
  2636     }
  3027     }
  2637 
  3028 
  2638     var prototypeMin = deprecate(
  3029     var prototypeMin = deprecate(
  2639         'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  3030             'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  2640         function () {
  3031             function () {
  2641             var other = createLocal.apply(null, arguments);
  3032                 var other = createLocal.apply(null, arguments);
  2642             if (this.isValid() && other.isValid()) {
  3033                 if (this.isValid() && other.isValid()) {
  2643                 return other < this ? this : other;
  3034                     return other < this ? this : other;
  2644             } else {
  3035                 } else {
  2645                 return createInvalid();
  3036                     return createInvalid();
  2646             }
  3037                 }
  2647         }
  3038             }
  2648     );
  3039         ),
  2649 
  3040         prototypeMax = deprecate(
  2650     var prototypeMax = deprecate(
  3041             'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  2651         'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  3042             function () {
  2652         function () {
  3043                 var other = createLocal.apply(null, arguments);
  2653             var other = createLocal.apply(null, arguments);
  3044                 if (this.isValid() && other.isValid()) {
  2654             if (this.isValid() && other.isValid()) {
  3045                     return other > this ? this : other;
  2655                 return other > this ? this : other;
  3046                 } else {
  2656             } else {
  3047                     return createInvalid();
  2657                 return createInvalid();
  3048                 }
  2658             }
  3049             }
  2659         }
  3050         );
  2660     );
       
  2661 
  3051 
  2662     // Pick a moment m from moments so that m[fn](other) is true for all
  3052     // Pick a moment m from moments so that m[fn](other) is true for all
  2663     // other. This relies on the function fn to be transitive.
  3053     // other. This relies on the function fn to be transitive.
  2664     //
  3054     //
  2665     // moments should either be an array of moment objects or an array, whose
  3055     // moments should either be an array of moment objects or an array, whose
  2680         }
  3070         }
  2681         return res;
  3071         return res;
  2682     }
  3072     }
  2683 
  3073 
  2684     // TODO: Use [].sort instead?
  3074     // TODO: Use [].sort instead?
  2685     function min () {
  3075     function min() {
  2686         var args = [].slice.call(arguments, 0);
  3076         var args = [].slice.call(arguments, 0);
  2687 
  3077 
  2688         return pickBy('isBefore', args);
  3078         return pickBy('isBefore', args);
  2689     }
  3079     }
  2690 
  3080 
  2691     function max () {
  3081     function max() {
  2692         var args = [].slice.call(arguments, 0);
  3082         var args = [].slice.call(arguments, 0);
  2693 
  3083 
  2694         return pickBy('isAfter', args);
  3084         return pickBy('isAfter', args);
  2695     }
  3085     }
  2696 
  3086 
  2697     var now = function () {
  3087     var now = function () {
  2698         return Date.now ? Date.now() : +(new Date());
  3088         return Date.now ? Date.now() : +new Date();
  2699     };
  3089     };
  2700 
  3090 
  2701     var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
  3091     var ordering = [
       
  3092         'year',
       
  3093         'quarter',
       
  3094         'month',
       
  3095         'week',
       
  3096         'day',
       
  3097         'hour',
       
  3098         'minute',
       
  3099         'second',
       
  3100         'millisecond',
       
  3101     ];
  2702 
  3102 
  2703     function isDurationValid(m) {
  3103     function isDurationValid(m) {
  2704         for (var key in m) {
  3104         var key,
  2705             if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
  3105             unitHasDecimal = false,
       
  3106             i;
       
  3107         for (key in m) {
       
  3108             if (
       
  3109                 hasOwnProp(m, key) &&
       
  3110                 !(
       
  3111                     indexOf.call(ordering, key) !== -1 &&
       
  3112                     (m[key] == null || !isNaN(m[key]))
       
  3113                 )
       
  3114             ) {
  2706                 return false;
  3115                 return false;
  2707             }
  3116             }
  2708         }
  3117         }
  2709 
  3118 
  2710         var unitHasDecimal = false;
  3119         for (i = 0; i < ordering.length; ++i) {
  2711         for (var i = 0; i < ordering.length; ++i) {
       
  2712             if (m[ordering[i]]) {
  3120             if (m[ordering[i]]) {
  2713                 if (unitHasDecimal) {
  3121                 if (unitHasDecimal) {
  2714                     return false; // only allow non-integers for smallest unit
  3122                     return false; // only allow non-integers for smallest unit
  2715                 }
  3123                 }
  2716                 if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  3124                 if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  2728 
  3136 
  2729     function createInvalid$1() {
  3137     function createInvalid$1() {
  2730         return createDuration(NaN);
  3138         return createDuration(NaN);
  2731     }
  3139     }
  2732 
  3140 
  2733     function Duration (duration) {
  3141     function Duration(duration) {
  2734         var normalizedInput = normalizeObjectUnits(duration),
  3142         var normalizedInput = normalizeObjectUnits(duration),
  2735             years = normalizedInput.year || 0,
  3143             years = normalizedInput.year || 0,
  2736             quarters = normalizedInput.quarter || 0,
  3144             quarters = normalizedInput.quarter || 0,
  2737             months = normalizedInput.month || 0,
  3145             months = normalizedInput.month || 0,
  2738             weeks = normalizedInput.week || 0,
  3146             weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
  2739             days = normalizedInput.day || 0,
  3147             days = normalizedInput.day || 0,
  2740             hours = normalizedInput.hour || 0,
  3148             hours = normalizedInput.hour || 0,
  2741             minutes = normalizedInput.minute || 0,
  3149             minutes = normalizedInput.minute || 0,
  2742             seconds = normalizedInput.second || 0,
  3150             seconds = normalizedInput.second || 0,
  2743             milliseconds = normalizedInput.millisecond || 0;
  3151             milliseconds = normalizedInput.millisecond || 0;
  2744 
  3152 
  2745         this._isValid = isDurationValid(normalizedInput);
  3153         this._isValid = isDurationValid(normalizedInput);
  2746 
  3154 
  2747         // representation for dateAddRemove
  3155         // representation for dateAddRemove
  2748         this._milliseconds = +milliseconds +
  3156         this._milliseconds =
       
  3157             +milliseconds +
  2749             seconds * 1e3 + // 1000
  3158             seconds * 1e3 + // 1000
  2750             minutes * 6e4 + // 1000 * 60
  3159             minutes * 6e4 + // 1000 * 60
  2751             hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  3160             hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  2752         // Because of dateAddRemove treats 24 hours as different from a
  3161         // Because of dateAddRemove treats 24 hours as different from a
  2753         // day when working around DST, we need to store them separately
  3162         // day when working around DST, we need to store them separately
  2754         this._days = +days +
  3163         this._days = +days + weeks * 7;
  2755             weeks * 7;
       
  2756         // It is impossible to translate months into days without knowing
  3164         // It is impossible to translate months into days without knowing
  2757         // which months you are are talking about, so we have to store
  3165         // which months you are are talking about, so we have to store
  2758         // it separately.
  3166         // it separately.
  2759         this._months = +months +
  3167         this._months = +months + quarters * 3 + years * 12;
  2760             quarters * 3 +
       
  2761             years * 12;
       
  2762 
  3168 
  2763         this._data = {};
  3169         this._data = {};
  2764 
  3170 
  2765         this._locale = getLocale();
  3171         this._locale = getLocale();
  2766 
  3172 
  2767         this._bubble();
  3173         this._bubble();
  2768     }
  3174     }
  2769 
  3175 
  2770     function isDuration (obj) {
  3176     function isDuration(obj) {
  2771         return obj instanceof Duration;
  3177         return obj instanceof Duration;
  2772     }
  3178     }
  2773 
  3179 
  2774     function absRound (number) {
  3180     function absRound(number) {
  2775         if (number < 0) {
  3181         if (number < 0) {
  2776             return Math.round(-1 * number) * -1;
  3182             return Math.round(-1 * number) * -1;
  2777         } else {
  3183         } else {
  2778             return Math.round(number);
  3184             return Math.round(number);
  2779         }
  3185         }
  2780     }
  3186     }
  2781 
  3187 
       
  3188     // compare two arrays, return the number of differences
       
  3189     function compareArrays(array1, array2, dontConvert) {
       
  3190         var len = Math.min(array1.length, array2.length),
       
  3191             lengthDiff = Math.abs(array1.length - array2.length),
       
  3192             diffs = 0,
       
  3193             i;
       
  3194         for (i = 0; i < len; i++) {
       
  3195             if (
       
  3196                 (dontConvert && array1[i] !== array2[i]) ||
       
  3197                 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))
       
  3198             ) {
       
  3199                 diffs++;
       
  3200             }
       
  3201         }
       
  3202         return diffs + lengthDiff;
       
  3203     }
       
  3204 
  2782     // FORMATTING
  3205     // FORMATTING
  2783 
  3206 
  2784     function offset (token, separator) {
  3207     function offset(token, separator) {
  2785         addFormatToken(token, 0, 0, function () {
  3208         addFormatToken(token, 0, 0, function () {
  2786             var offset = this.utcOffset();
  3209             var offset = this.utcOffset(),
  2787             var sign = '+';
  3210                 sign = '+';
  2788             if (offset < 0) {
  3211             if (offset < 0) {
  2789                 offset = -offset;
  3212                 offset = -offset;
  2790                 sign = '-';
  3213                 sign = '-';
  2791             }
  3214             }
  2792             return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  3215             return (
       
  3216                 sign +
       
  3217                 zeroFill(~~(offset / 60), 2) +
       
  3218                 separator +
       
  3219                 zeroFill(~~offset % 60, 2)
       
  3220             );
  2793         });
  3221         });
  2794     }
  3222     }
  2795 
  3223 
  2796     offset('Z', ':');
  3224     offset('Z', ':');
  2797     offset('ZZ', '');
  3225     offset('ZZ', '');
  2798 
  3226 
  2799     // PARSING
  3227     // PARSING
  2800 
  3228 
  2801     addRegexToken('Z',  matchShortOffset);
  3229     addRegexToken('Z', matchShortOffset);
  2802     addRegexToken('ZZ', matchShortOffset);
  3230     addRegexToken('ZZ', matchShortOffset);
  2803     addParseToken(['Z', 'ZZ'], function (input, array, config) {
  3231     addParseToken(['Z', 'ZZ'], function (input, array, config) {
  2804         config._useUTC = true;
  3232         config._useUTC = true;
  2805         config._tzm = offsetFromString(matchShortOffset, input);
  3233         config._tzm = offsetFromString(matchShortOffset, input);
  2806     });
  3234     });
  2811     // '+10:00' > ['10',  '00']
  3239     // '+10:00' > ['10',  '00']
  2812     // '-1530'  > ['-15', '30']
  3240     // '-1530'  > ['-15', '30']
  2813     var chunkOffset = /([\+\-]|\d\d)/gi;
  3241     var chunkOffset = /([\+\-]|\d\d)/gi;
  2814 
  3242 
  2815     function offsetFromString(matcher, string) {
  3243     function offsetFromString(matcher, string) {
  2816         var matches = (string || '').match(matcher);
  3244         var matches = (string || '').match(matcher),
       
  3245             chunk,
       
  3246             parts,
       
  3247             minutes;
  2817 
  3248 
  2818         if (matches === null) {
  3249         if (matches === null) {
  2819             return null;
  3250             return null;
  2820         }
  3251         }
  2821 
  3252 
  2822         var chunk   = matches[matches.length - 1] || [];
  3253         chunk = matches[matches.length - 1] || [];
  2823         var parts   = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  3254         parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  2824         var minutes = +(parts[1] * 60) + toInt(parts[2]);
  3255         minutes = +(parts[1] * 60) + toInt(parts[2]);
  2825 
  3256 
  2826         return minutes === 0 ?
  3257         return minutes === 0 ? 0 : parts[0] === '+' ? minutes : -minutes;
  2827           0 :
       
  2828           parts[0] === '+' ? minutes : -minutes;
       
  2829     }
  3258     }
  2830 
  3259 
  2831     // Return a moment from input, that is local/utc/zone equivalent to model.
  3260     // Return a moment from input, that is local/utc/zone equivalent to model.
  2832     function cloneWithOffset(input, model) {
  3261     function cloneWithOffset(input, model) {
  2833         var res, diff;
  3262         var res, diff;
  2834         if (model._isUTC) {
  3263         if (model._isUTC) {
  2835             res = model.clone();
  3264             res = model.clone();
  2836             diff = (isMoment(input) || isDate(input) ? input.valueOf() : createLocal(input).valueOf()) - res.valueOf();
  3265             diff =
       
  3266                 (isMoment(input) || isDate(input)
       
  3267                     ? input.valueOf()
       
  3268                     : createLocal(input).valueOf()) - res.valueOf();
  2837             // Use low-level api, because this fn is low-level api.
  3269             // Use low-level api, because this fn is low-level api.
  2838             res._d.setTime(res._d.valueOf() + diff);
  3270             res._d.setTime(res._d.valueOf() + diff);
  2839             hooks.updateOffset(res, false);
  3271             hooks.updateOffset(res, false);
  2840             return res;
  3272             return res;
  2841         } else {
  3273         } else {
  2842             return createLocal(input).local();
  3274             return createLocal(input).local();
  2843         }
  3275         }
  2844     }
  3276     }
  2845 
  3277 
  2846     function getDateOffset (m) {
  3278     function getDateOffset(m) {
  2847         // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  3279         // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  2848         // https://github.com/moment/moment/pull/1871
  3280         // https://github.com/moment/moment/pull/1871
  2849         return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  3281         return -Math.round(m._d.getTimezoneOffset());
  2850     }
  3282     }
  2851 
  3283 
  2852     // HOOKS
  3284     // HOOKS
  2853 
  3285 
  2854     // This function will be called whenever a moment is mutated.
  3286     // This function will be called whenever a moment is mutated.
  2865     // Keeping the time actually adds/subtracts (one hour)
  3297     // Keeping the time actually adds/subtracts (one hour)
  2866     // from the actual represented time. That is why we call updateOffset
  3298     // from the actual represented time. That is why we call updateOffset
  2867     // a second time. In case it wants us to change the offset again
  3299     // a second time. In case it wants us to change the offset again
  2868     // _changeInProgress == true case, then we have to adjust, because
  3300     // _changeInProgress == true case, then we have to adjust, because
  2869     // there is no such time in the given timezone.
  3301     // there is no such time in the given timezone.
  2870     function getSetOffset (input, keepLocalTime, keepMinutes) {
  3302     function getSetOffset(input, keepLocalTime, keepMinutes) {
  2871         var offset = this._offset || 0,
  3303         var offset = this._offset || 0,
  2872             localAdjust;
  3304             localAdjust;
  2873         if (!this.isValid()) {
  3305         if (!this.isValid()) {
  2874             return input != null ? this : NaN;
  3306             return input != null ? this : NaN;
  2875         }
  3307         }
  2890             if (localAdjust != null) {
  3322             if (localAdjust != null) {
  2891                 this.add(localAdjust, 'm');
  3323                 this.add(localAdjust, 'm');
  2892             }
  3324             }
  2893             if (offset !== input) {
  3325             if (offset !== input) {
  2894                 if (!keepLocalTime || this._changeInProgress) {
  3326                 if (!keepLocalTime || this._changeInProgress) {
  2895                     addSubtract(this, createDuration(input - offset, 'm'), 1, false);
  3327                     addSubtract(
       
  3328                         this,
       
  3329                         createDuration(input - offset, 'm'),
       
  3330                         1,
       
  3331                         false
       
  3332                     );
  2896                 } else if (!this._changeInProgress) {
  3333                 } else if (!this._changeInProgress) {
  2897                     this._changeInProgress = true;
  3334                     this._changeInProgress = true;
  2898                     hooks.updateOffset(this, true);
  3335                     hooks.updateOffset(this, true);
  2899                     this._changeInProgress = null;
  3336                     this._changeInProgress = null;
  2900                 }
  3337                 }
  2903         } else {
  3340         } else {
  2904             return this._isUTC ? offset : getDateOffset(this);
  3341             return this._isUTC ? offset : getDateOffset(this);
  2905         }
  3342         }
  2906     }
  3343     }
  2907 
  3344 
  2908     function getSetZone (input, keepLocalTime) {
  3345     function getSetZone(input, keepLocalTime) {
  2909         if (input != null) {
  3346         if (input != null) {
  2910             if (typeof input !== 'string') {
  3347             if (typeof input !== 'string') {
  2911                 input = -input;
  3348                 input = -input;
  2912             }
  3349             }
  2913 
  3350 
  2917         } else {
  3354         } else {
  2918             return -this.utcOffset();
  3355             return -this.utcOffset();
  2919         }
  3356         }
  2920     }
  3357     }
  2921 
  3358 
  2922     function setOffsetToUTC (keepLocalTime) {
  3359     function setOffsetToUTC(keepLocalTime) {
  2923         return this.utcOffset(0, keepLocalTime);
  3360         return this.utcOffset(0, keepLocalTime);
  2924     }
  3361     }
  2925 
  3362 
  2926     function setOffsetToLocal (keepLocalTime) {
  3363     function setOffsetToLocal(keepLocalTime) {
  2927         if (this._isUTC) {
  3364         if (this._isUTC) {
  2928             this.utcOffset(0, keepLocalTime);
  3365             this.utcOffset(0, keepLocalTime);
  2929             this._isUTC = false;
  3366             this._isUTC = false;
  2930 
  3367 
  2931             if (keepLocalTime) {
  3368             if (keepLocalTime) {
  2933             }
  3370             }
  2934         }
  3371         }
  2935         return this;
  3372         return this;
  2936     }
  3373     }
  2937 
  3374 
  2938     function setOffsetToParsedOffset () {
  3375     function setOffsetToParsedOffset() {
  2939         if (this._tzm != null) {
  3376         if (this._tzm != null) {
  2940             this.utcOffset(this._tzm, false, true);
  3377             this.utcOffset(this._tzm, false, true);
  2941         } else if (typeof this._i === 'string') {
  3378         } else if (typeof this._i === 'string') {
  2942             var tZone = offsetFromString(matchOffset, this._i);
  3379             var tZone = offsetFromString(matchOffset, this._i);
  2943             if (tZone != null) {
  3380             if (tZone != null) {
  2944                 this.utcOffset(tZone);
  3381                 this.utcOffset(tZone);
  2945             }
  3382             } else {
  2946             else {
       
  2947                 this.utcOffset(0, true);
  3383                 this.utcOffset(0, true);
  2948             }
  3384             }
  2949         }
  3385         }
  2950         return this;
  3386         return this;
  2951     }
  3387     }
  2952 
  3388 
  2953     function hasAlignedHourOffset (input) {
  3389     function hasAlignedHourOffset(input) {
  2954         if (!this.isValid()) {
  3390         if (!this.isValid()) {
  2955             return false;
  3391             return false;
  2956         }
  3392         }
  2957         input = input ? createLocal(input).utcOffset() : 0;
  3393         input = input ? createLocal(input).utcOffset() : 0;
  2958 
  3394 
  2959         return (this.utcOffset() - input) % 60 === 0;
  3395         return (this.utcOffset() - input) % 60 === 0;
  2960     }
  3396     }
  2961 
  3397 
  2962     function isDaylightSavingTime () {
  3398     function isDaylightSavingTime() {
  2963         return (
  3399         return (
  2964             this.utcOffset() > this.clone().month(0).utcOffset() ||
  3400             this.utcOffset() > this.clone().month(0).utcOffset() ||
  2965             this.utcOffset() > this.clone().month(5).utcOffset()
  3401             this.utcOffset() > this.clone().month(5).utcOffset()
  2966         );
  3402         );
  2967     }
  3403     }
  2968 
  3404 
  2969     function isDaylightSavingTimeShifted () {
  3405     function isDaylightSavingTimeShifted() {
  2970         if (!isUndefined(this._isDSTShifted)) {
  3406         if (!isUndefined(this._isDSTShifted)) {
  2971             return this._isDSTShifted;
  3407             return this._isDSTShifted;
  2972         }
  3408         }
  2973 
  3409 
  2974         var c = {};
  3410         var c = {},
       
  3411             other;
  2975 
  3412 
  2976         copyConfig(c, this);
  3413         copyConfig(c, this);
  2977         c = prepareConfig(c);
  3414         c = prepareConfig(c);
  2978 
  3415 
  2979         if (c._a) {
  3416         if (c._a) {
  2980             var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  3417             other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  2981             this._isDSTShifted = this.isValid() &&
  3418             this._isDSTShifted =
  2982                 compareArrays(c._a, other.toArray()) > 0;
  3419                 this.isValid() && compareArrays(c._a, other.toArray()) > 0;
  2983         } else {
  3420         } else {
  2984             this._isDSTShifted = false;
  3421             this._isDSTShifted = false;
  2985         }
  3422         }
  2986 
  3423 
  2987         return this._isDSTShifted;
  3424         return this._isDSTShifted;
  2988     }
  3425     }
  2989 
  3426 
  2990     function isLocal () {
  3427     function isLocal() {
  2991         return this.isValid() ? !this._isUTC : false;
  3428         return this.isValid() ? !this._isUTC : false;
  2992     }
  3429     }
  2993 
  3430 
  2994     function isUtcOffset () {
  3431     function isUtcOffset() {
  2995         return this.isValid() ? this._isUTC : false;
  3432         return this.isValid() ? this._isUTC : false;
  2996     }
  3433     }
  2997 
  3434 
  2998     function isUtc () {
  3435     function isUtc() {
  2999         return this.isValid() ? this._isUTC && this._offset === 0 : false;
  3436         return this.isValid() ? this._isUTC && this._offset === 0 : false;
  3000     }
  3437     }
  3001 
  3438 
  3002     // ASP.NET json date format regex
  3439     // ASP.NET json date format regex
  3003     var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
  3440     var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
  3004 
  3441         // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  3005     // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  3442         // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  3006     // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  3443         // and further modified to allow for strings containing both week and day
  3007     // and further modified to allow for strings containing both week and day
  3444         isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  3008     var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  3445 
  3009 
  3446     function createDuration(input, key) {
  3010     function createDuration (input, key) {
       
  3011         var duration = input,
  3447         var duration = input,
  3012             // matching against regexp is expensive, do it on demand
  3448             // matching against regexp is expensive, do it on demand
  3013             match = null,
  3449             match = null,
  3014             sign,
  3450             sign,
  3015             ret,
  3451             ret,
  3016             diffRes;
  3452             diffRes;
  3017 
  3453 
  3018         if (isDuration(input)) {
  3454         if (isDuration(input)) {
  3019             duration = {
  3455             duration = {
  3020                 ms : input._milliseconds,
  3456                 ms: input._milliseconds,
  3021                 d  : input._days,
  3457                 d: input._days,
  3022                 M  : input._months
  3458                 M: input._months,
  3023             };
  3459             };
  3024         } else if (isNumber(input)) {
  3460         } else if (isNumber(input) || !isNaN(+input)) {
  3025             duration = {};
  3461             duration = {};
  3026             if (key) {
  3462             if (key) {
  3027                 duration[key] = input;
  3463                 duration[key] = +input;
  3028             } else {
  3464             } else {
  3029                 duration.milliseconds = input;
  3465                 duration.milliseconds = +input;
  3030             }
  3466             }
  3031         } else if (!!(match = aspNetRegex.exec(input))) {
  3467         } else if ((match = aspNetRegex.exec(input))) {
  3032             sign = (match[1] === '-') ? -1 : 1;
  3468             sign = match[1] === '-' ? -1 : 1;
  3033             duration = {
  3469             duration = {
  3034                 y  : 0,
  3470                 y: 0,
  3035                 d  : toInt(match[DATE])                         * sign,
  3471                 d: toInt(match[DATE]) * sign,
  3036                 h  : toInt(match[HOUR])                         * sign,
  3472                 h: toInt(match[HOUR]) * sign,
  3037                 m  : toInt(match[MINUTE])                       * sign,
  3473                 m: toInt(match[MINUTE]) * sign,
  3038                 s  : toInt(match[SECOND])                       * sign,
  3474                 s: toInt(match[SECOND]) * sign,
  3039                 ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
  3475                 ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match
  3040             };
  3476             };
  3041         } else if (!!(match = isoRegex.exec(input))) {
  3477         } else if ((match = isoRegex.exec(input))) {
  3042             sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
  3478             sign = match[1] === '-' ? -1 : 1;
  3043             duration = {
  3479             duration = {
  3044                 y : parseIso(match[2], sign),
  3480                 y: parseIso(match[2], sign),
  3045                 M : parseIso(match[3], sign),
  3481                 M: parseIso(match[3], sign),
  3046                 w : parseIso(match[4], sign),
  3482                 w: parseIso(match[4], sign),
  3047                 d : parseIso(match[5], sign),
  3483                 d: parseIso(match[5], sign),
  3048                 h : parseIso(match[6], sign),
  3484                 h: parseIso(match[6], sign),
  3049                 m : parseIso(match[7], sign),
  3485                 m: parseIso(match[7], sign),
  3050                 s : parseIso(match[8], sign)
  3486                 s: parseIso(match[8], sign),
  3051             };
  3487             };
  3052         } else if (duration == null) {// checks for null or undefined
  3488         } else if (duration == null) {
       
  3489             // checks for null or undefined
  3053             duration = {};
  3490             duration = {};
  3054         } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  3491         } else if (
  3055             diffRes = momentsDifference(createLocal(duration.from), createLocal(duration.to));
  3492             typeof duration === 'object' &&
       
  3493             ('from' in duration || 'to' in duration)
       
  3494         ) {
       
  3495             diffRes = momentsDifference(
       
  3496                 createLocal(duration.from),
       
  3497                 createLocal(duration.to)
       
  3498             );
  3056 
  3499 
  3057             duration = {};
  3500             duration = {};
  3058             duration.ms = diffRes.milliseconds;
  3501             duration.ms = diffRes.milliseconds;
  3059             duration.M = diffRes.months;
  3502             duration.M = diffRes.months;
  3060         }
  3503         }
  3063 
  3506 
  3064         if (isDuration(input) && hasOwnProp(input, '_locale')) {
  3507         if (isDuration(input) && hasOwnProp(input, '_locale')) {
  3065             ret._locale = input._locale;
  3508             ret._locale = input._locale;
  3066         }
  3509         }
  3067 
  3510 
       
  3511         if (isDuration(input) && hasOwnProp(input, '_isValid')) {
       
  3512             ret._isValid = input._isValid;
       
  3513         }
       
  3514 
  3068         return ret;
  3515         return ret;
  3069     }
  3516     }
  3070 
  3517 
  3071     createDuration.fn = Duration.prototype;
  3518     createDuration.fn = Duration.prototype;
  3072     createDuration.invalid = createInvalid$1;
  3519     createDuration.invalid = createInvalid$1;
  3073 
  3520 
  3074     function parseIso (inp, sign) {
  3521     function parseIso(inp, sign) {
  3075         // We'd normally use ~~inp for this, but unfortunately it also
  3522         // We'd normally use ~~inp for this, but unfortunately it also
  3076         // converts floats to ints.
  3523         // converts floats to ints.
  3077         // inp may be undefined, so careful calling replace on it.
  3524         // inp may be undefined, so careful calling replace on it.
  3078         var res = inp && parseFloat(inp.replace(',', '.'));
  3525         var res = inp && parseFloat(inp.replace(',', '.'));
  3079         // apply sign while we're at it
  3526         // apply sign while we're at it
  3080         return (isNaN(res) ? 0 : res) * sign;
  3527         return (isNaN(res) ? 0 : res) * sign;
  3081     }
  3528     }
  3082 
  3529 
  3083     function positiveMomentsDifference(base, other) {
  3530     function positiveMomentsDifference(base, other) {
  3084         var res = {milliseconds: 0, months: 0};
  3531         var res = {};
  3085 
  3532 
  3086         res.months = other.month() - base.month() +
  3533         res.months =
  3087             (other.year() - base.year()) * 12;
  3534             other.month() - base.month() + (other.year() - base.year()) * 12;
  3088         if (base.clone().add(res.months, 'M').isAfter(other)) {
  3535         if (base.clone().add(res.months, 'M').isAfter(other)) {
  3089             --res.months;
  3536             --res.months;
  3090         }
  3537         }
  3091 
  3538 
  3092         res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  3539         res.milliseconds = +other - +base.clone().add(res.months, 'M');
  3093 
  3540 
  3094         return res;
  3541         return res;
  3095     }
  3542     }
  3096 
  3543 
  3097     function momentsDifference(base, other) {
  3544     function momentsDifference(base, other) {
  3098         var res;
  3545         var res;
  3099         if (!(base.isValid() && other.isValid())) {
  3546         if (!(base.isValid() && other.isValid())) {
  3100             return {milliseconds: 0, months: 0};
  3547             return { milliseconds: 0, months: 0 };
  3101         }
  3548         }
  3102 
  3549 
  3103         other = cloneWithOffset(other, base);
  3550         other = cloneWithOffset(other, base);
  3104         if (base.isBefore(other)) {
  3551         if (base.isBefore(other)) {
  3105             res = positiveMomentsDifference(base, other);
  3552             res = positiveMomentsDifference(base, other);
  3116     function createAdder(direction, name) {
  3563     function createAdder(direction, name) {
  3117         return function (val, period) {
  3564         return function (val, period) {
  3118             var dur, tmp;
  3565             var dur, tmp;
  3119             //invert the arguments, but complain about it
  3566             //invert the arguments, but complain about it
  3120             if (period !== null && !isNaN(+period)) {
  3567             if (period !== null && !isNaN(+period)) {
  3121                 deprecateSimple(name, 'moment().' + name  + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
  3568                 deprecateSimple(
  3122                 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
  3569                     name,
  3123                 tmp = val; val = period; period = tmp;
  3570                     'moment().' +
  3124             }
  3571                         name +
  3125 
  3572                         '(period, number) is deprecated. Please use moment().' +
  3126             val = typeof val === 'string' ? +val : val;
  3573                         name +
       
  3574                         '(number, period). ' +
       
  3575                         'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'
       
  3576                 );
       
  3577                 tmp = val;
       
  3578                 val = period;
       
  3579                 period = tmp;
       
  3580             }
       
  3581 
  3127             dur = createDuration(val, period);
  3582             dur = createDuration(val, period);
  3128             addSubtract(this, dur, direction);
  3583             addSubtract(this, dur, direction);
  3129             return this;
  3584             return this;
  3130         };
  3585         };
  3131     }
  3586     }
  3132 
  3587 
  3133     function addSubtract (mom, duration, isAdding, updateOffset) {
  3588     function addSubtract(mom, duration, isAdding, updateOffset) {
  3134         var milliseconds = duration._milliseconds,
  3589         var milliseconds = duration._milliseconds,
  3135             days = absRound(duration._days),
  3590             days = absRound(duration._days),
  3136             months = absRound(duration._months);
  3591             months = absRound(duration._months);
  3137 
  3592 
  3138         if (!mom.isValid()) {
  3593         if (!mom.isValid()) {
  3154         if (updateOffset) {
  3609         if (updateOffset) {
  3155             hooks.updateOffset(mom, days || months);
  3610             hooks.updateOffset(mom, days || months);
  3156         }
  3611         }
  3157     }
  3612     }
  3158 
  3613 
  3159     var add      = createAdder(1, 'add');
  3614     var add = createAdder(1, 'add'),
  3160     var subtract = createAdder(-1, 'subtract');
  3615         subtract = createAdder(-1, 'subtract');
       
  3616 
       
  3617     function isString(input) {
       
  3618         return typeof input === 'string' || input instanceof String;
       
  3619     }
       
  3620 
       
  3621     // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
       
  3622     function isMomentInput(input) {
       
  3623         return (
       
  3624             isMoment(input) ||
       
  3625             isDate(input) ||
       
  3626             isString(input) ||
       
  3627             isNumber(input) ||
       
  3628             isNumberOrStringArray(input) ||
       
  3629             isMomentInputObject(input) ||
       
  3630             input === null ||
       
  3631             input === undefined
       
  3632         );
       
  3633     }
       
  3634 
       
  3635     function isMomentInputObject(input) {
       
  3636         var objectTest = isObject(input) && !isObjectEmpty(input),
       
  3637             propertyTest = false,
       
  3638             properties = [
       
  3639                 'years',
       
  3640                 'year',
       
  3641                 'y',
       
  3642                 'months',
       
  3643                 'month',
       
  3644                 'M',
       
  3645                 'days',
       
  3646                 'day',
       
  3647                 'd',
       
  3648                 'dates',
       
  3649                 'date',
       
  3650                 'D',
       
  3651                 'hours',
       
  3652                 'hour',
       
  3653                 'h',
       
  3654                 'minutes',
       
  3655                 'minute',
       
  3656                 'm',
       
  3657                 'seconds',
       
  3658                 'second',
       
  3659                 's',
       
  3660                 'milliseconds',
       
  3661                 'millisecond',
       
  3662                 'ms',
       
  3663             ],
       
  3664             i,
       
  3665             property;
       
  3666 
       
  3667         for (i = 0; i < properties.length; i += 1) {
       
  3668             property = properties[i];
       
  3669             propertyTest = propertyTest || hasOwnProp(input, property);
       
  3670         }
       
  3671 
       
  3672         return objectTest && propertyTest;
       
  3673     }
       
  3674 
       
  3675     function isNumberOrStringArray(input) {
       
  3676         var arrayTest = isArray(input),
       
  3677             dataTypeTest = false;
       
  3678         if (arrayTest) {
       
  3679             dataTypeTest =
       
  3680                 input.filter(function (item) {
       
  3681                     return !isNumber(item) && isString(input);
       
  3682                 }).length === 0;
       
  3683         }
       
  3684         return arrayTest && dataTypeTest;
       
  3685     }
       
  3686 
       
  3687     function isCalendarSpec(input) {
       
  3688         var objectTest = isObject(input) && !isObjectEmpty(input),
       
  3689             propertyTest = false,
       
  3690             properties = [
       
  3691                 'sameDay',
       
  3692                 'nextDay',
       
  3693                 'lastDay',
       
  3694                 'nextWeek',
       
  3695                 'lastWeek',
       
  3696                 'sameElse',
       
  3697             ],
       
  3698             i,
       
  3699             property;
       
  3700 
       
  3701         for (i = 0; i < properties.length; i += 1) {
       
  3702             property = properties[i];
       
  3703             propertyTest = propertyTest || hasOwnProp(input, property);
       
  3704         }
       
  3705 
       
  3706         return objectTest && propertyTest;
       
  3707     }
  3161 
  3708 
  3162     function getCalendarFormat(myMoment, now) {
  3709     function getCalendarFormat(myMoment, now) {
  3163         var diff = myMoment.diff(now, 'days', true);
  3710         var diff = myMoment.diff(now, 'days', true);
  3164         return diff < -6 ? 'sameElse' :
  3711         return diff < -6
  3165                 diff < -1 ? 'lastWeek' :
  3712             ? 'sameElse'
  3166                 diff < 0 ? 'lastDay' :
  3713             : diff < -1
  3167                 diff < 1 ? 'sameDay' :
  3714             ? 'lastWeek'
  3168                 diff < 2 ? 'nextDay' :
  3715             : diff < 0
  3169                 diff < 7 ? 'nextWeek' : 'sameElse';
  3716             ? 'lastDay'
  3170     }
  3717             : diff < 1
  3171 
  3718             ? 'sameDay'
  3172     function calendar$1 (time, formats) {
  3719             : diff < 2
       
  3720             ? 'nextDay'
       
  3721             : diff < 7
       
  3722             ? 'nextWeek'
       
  3723             : 'sameElse';
       
  3724     }
       
  3725 
       
  3726     function calendar$1(time, formats) {
       
  3727         // Support for single parameter, formats only overload to the calendar function
       
  3728         if (arguments.length === 1) {
       
  3729             if (isMomentInput(arguments[0])) {
       
  3730                 time = arguments[0];
       
  3731                 formats = undefined;
       
  3732             } else if (isCalendarSpec(arguments[0])) {
       
  3733                 formats = arguments[0];
       
  3734                 time = undefined;
       
  3735             }
       
  3736         }
  3173         // We want to compare the start of today, vs this.
  3737         // We want to compare the start of today, vs this.
  3174         // Getting start-of-today depends on whether we're local/utc/offset or not.
  3738         // Getting start-of-today depends on whether we're local/utc/offset or not.
  3175         var now = time || createLocal(),
  3739         var now = time || createLocal(),
  3176             sod = cloneWithOffset(now, this).startOf('day'),
  3740             sod = cloneWithOffset(now, this).startOf('day'),
  3177             format = hooks.calendarFormat(this, sod) || 'sameElse';
  3741             format = hooks.calendarFormat(this, sod) || 'sameElse',
  3178 
  3742             output =
  3179         var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
  3743                 formats &&
  3180 
  3744                 (isFunction(formats[format])
  3181         return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
  3745                     ? formats[format].call(this, now)
  3182     }
  3746                     : formats[format]);
  3183 
  3747 
  3184     function clone () {
  3748         return this.format(
       
  3749             output || this.localeData().calendar(format, this, createLocal(now))
       
  3750         );
       
  3751     }
       
  3752 
       
  3753     function clone() {
  3185         return new Moment(this);
  3754         return new Moment(this);
  3186     }
  3755     }
  3187 
  3756 
  3188     function isAfter (input, units) {
  3757     function isAfter(input, units) {
  3189         var localInput = isMoment(input) ? input : createLocal(input);
  3758         var localInput = isMoment(input) ? input : createLocal(input);
  3190         if (!(this.isValid() && localInput.isValid())) {
  3759         if (!(this.isValid() && localInput.isValid())) {
  3191             return false;
  3760             return false;
  3192         }
  3761         }
  3193         units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  3762         units = normalizeUnits(units) || 'millisecond';
  3194         if (units === 'millisecond') {
  3763         if (units === 'millisecond') {
  3195             return this.valueOf() > localInput.valueOf();
  3764             return this.valueOf() > localInput.valueOf();
  3196         } else {
  3765         } else {
  3197             return localInput.valueOf() < this.clone().startOf(units).valueOf();
  3766             return localInput.valueOf() < this.clone().startOf(units).valueOf();
  3198         }
  3767         }
  3199     }
  3768     }
  3200 
  3769 
  3201     function isBefore (input, units) {
  3770     function isBefore(input, units) {
  3202         var localInput = isMoment(input) ? input : createLocal(input);
  3771         var localInput = isMoment(input) ? input : createLocal(input);
  3203         if (!(this.isValid() && localInput.isValid())) {
  3772         if (!(this.isValid() && localInput.isValid())) {
  3204             return false;
  3773             return false;
  3205         }
  3774         }
  3206         units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  3775         units = normalizeUnits(units) || 'millisecond';
  3207         if (units === 'millisecond') {
  3776         if (units === 'millisecond') {
  3208             return this.valueOf() < localInput.valueOf();
  3777             return this.valueOf() < localInput.valueOf();
  3209         } else {
  3778         } else {
  3210             return this.clone().endOf(units).valueOf() < localInput.valueOf();
  3779             return this.clone().endOf(units).valueOf() < localInput.valueOf();
  3211         }
  3780         }
  3212     }
  3781     }
  3213 
  3782 
  3214     function isBetween (from, to, units, inclusivity) {
  3783     function isBetween(from, to, units, inclusivity) {
       
  3784         var localFrom = isMoment(from) ? from : createLocal(from),
       
  3785             localTo = isMoment(to) ? to : createLocal(to);
       
  3786         if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
       
  3787             return false;
       
  3788         }
  3215         inclusivity = inclusivity || '()';
  3789         inclusivity = inclusivity || '()';
  3216         return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  3790         return (
  3217             (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  3791             (inclusivity[0] === '('
  3218     }
  3792                 ? this.isAfter(localFrom, units)
  3219 
  3793                 : !this.isBefore(localFrom, units)) &&
  3220     function isSame (input, units) {
  3794             (inclusivity[1] === ')'
       
  3795                 ? this.isBefore(localTo, units)
       
  3796                 : !this.isAfter(localTo, units))
       
  3797         );
       
  3798     }
       
  3799 
       
  3800     function isSame(input, units) {
  3221         var localInput = isMoment(input) ? input : createLocal(input),
  3801         var localInput = isMoment(input) ? input : createLocal(input),
  3222             inputMs;
  3802             inputMs;
  3223         if (!(this.isValid() && localInput.isValid())) {
  3803         if (!(this.isValid() && localInput.isValid())) {
  3224             return false;
  3804             return false;
  3225         }
  3805         }
  3226         units = normalizeUnits(units || 'millisecond');
  3806         units = normalizeUnits(units) || 'millisecond';
  3227         if (units === 'millisecond') {
  3807         if (units === 'millisecond') {
  3228             return this.valueOf() === localInput.valueOf();
  3808             return this.valueOf() === localInput.valueOf();
  3229         } else {
  3809         } else {
  3230             inputMs = localInput.valueOf();
  3810             inputMs = localInput.valueOf();
  3231             return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  3811             return (
  3232         }
  3812                 this.clone().startOf(units).valueOf() <= inputMs &&
  3233     }
  3813                 inputMs <= this.clone().endOf(units).valueOf()
  3234 
  3814             );
  3235     function isSameOrAfter (input, units) {
  3815         }
  3236         return this.isSame(input, units) || this.isAfter(input,units);
  3816     }
  3237     }
  3817 
  3238 
  3818     function isSameOrAfter(input, units) {
  3239     function isSameOrBefore (input, units) {
  3819         return this.isSame(input, units) || this.isAfter(input, units);
  3240         return this.isSame(input, units) || this.isBefore(input,units);
  3820     }
  3241     }
  3821 
  3242 
  3822     function isSameOrBefore(input, units) {
  3243     function diff (input, units, asFloat) {
  3823         return this.isSame(input, units) || this.isBefore(input, units);
  3244         var that,
  3824     }
  3245             zoneDelta,
  3825 
  3246             output;
  3826     function diff(input, units, asFloat) {
       
  3827         var that, zoneDelta, output;
  3247 
  3828 
  3248         if (!this.isValid()) {
  3829         if (!this.isValid()) {
  3249             return NaN;
  3830             return NaN;
  3250         }
  3831         }
  3251 
  3832 
  3258         zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  3839         zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  3259 
  3840 
  3260         units = normalizeUnits(units);
  3841         units = normalizeUnits(units);
  3261 
  3842 
  3262         switch (units) {
  3843         switch (units) {
  3263             case 'year': output = monthDiff(this, that) / 12; break;
  3844             case 'year':
  3264             case 'month': output = monthDiff(this, that); break;
  3845                 output = monthDiff(this, that) / 12;
  3265             case 'quarter': output = monthDiff(this, that) / 3; break;
  3846                 break;
  3266             case 'second': output = (this - that) / 1e3; break; // 1000
  3847             case 'month':
  3267             case 'minute': output = (this - that) / 6e4; break; // 1000 * 60
  3848                 output = monthDiff(this, that);
  3268             case 'hour': output = (this - that) / 36e5; break; // 1000 * 60 * 60
  3849                 break;
  3269             case 'day': output = (this - that - zoneDelta) / 864e5; break; // 1000 * 60 * 60 * 24, negate dst
  3850             case 'quarter':
  3270             case 'week': output = (this - that - zoneDelta) / 6048e5; break; // 1000 * 60 * 60 * 24 * 7, negate dst
  3851                 output = monthDiff(this, that) / 3;
  3271             default: output = this - that;
  3852                 break;
       
  3853             case 'second':
       
  3854                 output = (this - that) / 1e3;
       
  3855                 break; // 1000
       
  3856             case 'minute':
       
  3857                 output = (this - that) / 6e4;
       
  3858                 break; // 1000 * 60
       
  3859             case 'hour':
       
  3860                 output = (this - that) / 36e5;
       
  3861                 break; // 1000 * 60 * 60
       
  3862             case 'day':
       
  3863                 output = (this - that - zoneDelta) / 864e5;
       
  3864                 break; // 1000 * 60 * 60 * 24, negate dst
       
  3865             case 'week':
       
  3866                 output = (this - that - zoneDelta) / 6048e5;
       
  3867                 break; // 1000 * 60 * 60 * 24 * 7, negate dst
       
  3868             default:
       
  3869                 output = this - that;
  3272         }
  3870         }
  3273 
  3871 
  3274         return asFloat ? output : absFloor(output);
  3872         return asFloat ? output : absFloor(output);
  3275     }
  3873     }
  3276 
  3874 
  3277     function monthDiff (a, b) {
  3875     function monthDiff(a, b) {
       
  3876         if (a.date() < b.date()) {
       
  3877             // end-of-month calculations work correct when the start month has more
       
  3878             // days than the end month.
       
  3879             return -monthDiff(b, a);
       
  3880         }
  3278         // difference in months
  3881         // difference in months
  3279         var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  3882         var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
  3280             // b is in (anchor - 1 month, anchor + 1 month)
  3883             // b is in (anchor - 1 month, anchor + 1 month)
  3281             anchor = a.clone().add(wholeMonthDiff, 'months'),
  3884             anchor = a.clone().add(wholeMonthDiff, 'months'),
  3282             anchor2, adjust;
  3885             anchor2,
       
  3886             adjust;
  3283 
  3887 
  3284         if (b - anchor < 0) {
  3888         if (b - anchor < 0) {
  3285             anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  3889             anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  3286             // linear across the month
  3890             // linear across the month
  3287             adjust = (b - anchor) / (anchor - anchor2);
  3891             adjust = (b - anchor) / (anchor - anchor2);
  3296     }
  3900     }
  3297 
  3901 
  3298     hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  3902     hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  3299     hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  3903     hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  3300 
  3904 
  3301     function toString () {
  3905     function toString() {
  3302         return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  3906         return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  3303     }
  3907     }
  3304 
  3908 
  3305     function toISOString(keepOffset) {
  3909     function toISOString(keepOffset) {
  3306         if (!this.isValid()) {
  3910         if (!this.isValid()) {
  3307             return null;
  3911             return null;
  3308         }
  3912         }
  3309         var utc = keepOffset !== true;
  3913         var utc = keepOffset !== true,
  3310         var m = utc ? this.clone().utc() : this;
  3914             m = utc ? this.clone().utc() : this;
  3311         if (m.year() < 0 || m.year() > 9999) {
  3915         if (m.year() < 0 || m.year() > 9999) {
  3312             return formatMoment(m, utc ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ');
  3916             return formatMoment(
       
  3917                 m,
       
  3918                 utc
       
  3919                     ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'
       
  3920                     : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'
       
  3921             );
  3313         }
  3922         }
  3314         if (isFunction(Date.prototype.toISOString)) {
  3923         if (isFunction(Date.prototype.toISOString)) {
  3315             // native implementation is ~50x faster, use it when we can
  3924             // native implementation is ~50x faster, use it when we can
  3316             if (utc) {
  3925             if (utc) {
  3317                 return this.toDate().toISOString();
  3926                 return this.toDate().toISOString();
  3318             } else {
  3927             } else {
  3319                 return new Date(this.valueOf() + this.utcOffset() * 60 * 1000).toISOString().replace('Z', formatMoment(m, 'Z'));
  3928                 return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
  3320             }
  3929                     .toISOString()
  3321         }
  3930                     .replace('Z', formatMoment(m, 'Z'));
  3322         return formatMoment(m, utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ');
  3931             }
       
  3932         }
       
  3933         return formatMoment(
       
  3934             m,
       
  3935             utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ'
       
  3936         );
  3323     }
  3937     }
  3324 
  3938 
  3325     /**
  3939     /**
  3326      * Return a human readable representation of a moment that can
  3940      * Return a human readable representation of a moment that can
  3327      * also be evaluated to get a new moment which is the same
  3941      * also be evaluated to get a new moment which is the same
  3328      *
  3942      *
  3329      * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  3943      * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  3330      */
  3944      */
  3331     function inspect () {
  3945     function inspect() {
  3332         if (!this.isValid()) {
  3946         if (!this.isValid()) {
  3333             return 'moment.invalid(/* ' + this._i + ' */)';
  3947             return 'moment.invalid(/* ' + this._i + ' */)';
  3334         }
  3948         }
  3335         var func = 'moment';
  3949         var func = 'moment',
  3336         var zone = '';
  3950             zone = '',
       
  3951             prefix,
       
  3952             year,
       
  3953             datetime,
       
  3954             suffix;
  3337         if (!this.isLocal()) {
  3955         if (!this.isLocal()) {
  3338             func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
  3956             func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
  3339             zone = 'Z';
  3957             zone = 'Z';
  3340         }
  3958         }
  3341         var prefix = '[' + func + '("]';
  3959         prefix = '[' + func + '("]';
  3342         var year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
  3960         year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY';
  3343         var datetime = '-MM-DD[T]HH:mm:ss.SSS';
  3961         datetime = '-MM-DD[T]HH:mm:ss.SSS';
  3344         var suffix = zone + '[")]';
  3962         suffix = zone + '[")]';
  3345 
  3963 
  3346         return this.format(prefix + year + datetime + suffix);
  3964         return this.format(prefix + year + datetime + suffix);
  3347     }
  3965     }
  3348 
  3966 
  3349     function format (inputString) {
  3967     function format(inputString) {
  3350         if (!inputString) {
  3968         if (!inputString) {
  3351             inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
  3969             inputString = this.isUtc()
       
  3970                 ? hooks.defaultFormatUtc
       
  3971                 : hooks.defaultFormat;
  3352         }
  3972         }
  3353         var output = formatMoment(this, inputString);
  3973         var output = formatMoment(this, inputString);
  3354         return this.localeData().postformat(output);
  3974         return this.localeData().postformat(output);
  3355     }
  3975     }
  3356 
  3976 
  3357     function from (time, withoutSuffix) {
  3977     function from(time, withoutSuffix) {
  3358         if (this.isValid() &&
  3978         if (
  3359                 ((isMoment(time) && time.isValid()) ||
  3979             this.isValid() &&
  3360                  createLocal(time).isValid())) {
  3980             ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3361             return createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  3981         ) {
       
  3982             return createDuration({ to: this, from: time })
       
  3983                 .locale(this.locale())
       
  3984                 .humanize(!withoutSuffix);
  3362         } else {
  3985         } else {
  3363             return this.localeData().invalidDate();
  3986             return this.localeData().invalidDate();
  3364         }
  3987         }
  3365     }
  3988     }
  3366 
  3989 
  3367     function fromNow (withoutSuffix) {
  3990     function fromNow(withoutSuffix) {
  3368         return this.from(createLocal(), withoutSuffix);
  3991         return this.from(createLocal(), withoutSuffix);
  3369     }
  3992     }
  3370 
  3993 
  3371     function to (time, withoutSuffix) {
  3994     function to(time, withoutSuffix) {
  3372         if (this.isValid() &&
  3995         if (
  3373                 ((isMoment(time) && time.isValid()) ||
  3996             this.isValid() &&
  3374                  createLocal(time).isValid())) {
  3997             ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3375             return createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  3998         ) {
       
  3999             return createDuration({ from: this, to: time })
       
  4000                 .locale(this.locale())
       
  4001                 .humanize(!withoutSuffix);
  3376         } else {
  4002         } else {
  3377             return this.localeData().invalidDate();
  4003             return this.localeData().invalidDate();
  3378         }
  4004         }
  3379     }
  4005     }
  3380 
  4006 
  3381     function toNow (withoutSuffix) {
  4007     function toNow(withoutSuffix) {
  3382         return this.to(createLocal(), withoutSuffix);
  4008         return this.to(createLocal(), withoutSuffix);
  3383     }
  4009     }
  3384 
  4010 
  3385     // If passed a locale key, it will set the locale for this
  4011     // If passed a locale key, it will set the locale for this
  3386     // instance.  Otherwise, it will return the locale configuration
  4012     // instance.  Otherwise, it will return the locale configuration
  3387     // variables for this instance.
  4013     // variables for this instance.
  3388     function locale (key) {
  4014     function locale(key) {
  3389         var newLocaleData;
  4015         var newLocaleData;
  3390 
  4016 
  3391         if (key === undefined) {
  4017         if (key === undefined) {
  3392             return this._locale._abbr;
  4018             return this._locale._abbr;
  3393         } else {
  4019         } else {
  3408                 return this.locale(key);
  4034                 return this.locale(key);
  3409             }
  4035             }
  3410         }
  4036         }
  3411     );
  4037     );
  3412 
  4038 
  3413     function localeData () {
  4039     function localeData() {
  3414         return this._locale;
  4040         return this._locale;
  3415     }
  4041     }
  3416 
  4042 
  3417     function startOf (units) {
  4043     var MS_PER_SECOND = 1000,
       
  4044         MS_PER_MINUTE = 60 * MS_PER_SECOND,
       
  4045         MS_PER_HOUR = 60 * MS_PER_MINUTE,
       
  4046         MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
       
  4047 
       
  4048     // actual modulo - handles negative numbers (for dates before 1970):
       
  4049     function mod$1(dividend, divisor) {
       
  4050         return ((dividend % divisor) + divisor) % divisor;
       
  4051     }
       
  4052 
       
  4053     function localStartOfDate(y, m, d) {
       
  4054         // the date constructor remaps years 0-99 to 1900-1999
       
  4055         if (y < 100 && y >= 0) {
       
  4056             // preserve leap years using a full 400 year cycle, then reset
       
  4057             return new Date(y + 400, m, d) - MS_PER_400_YEARS;
       
  4058         } else {
       
  4059             return new Date(y, m, d).valueOf();
       
  4060         }
       
  4061     }
       
  4062 
       
  4063     function utcStartOfDate(y, m, d) {
       
  4064         // Date.UTC remaps years 0-99 to 1900-1999
       
  4065         if (y < 100 && y >= 0) {
       
  4066             // preserve leap years using a full 400 year cycle, then reset
       
  4067             return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
       
  4068         } else {
       
  4069             return Date.UTC(y, m, d);
       
  4070         }
       
  4071     }
       
  4072 
       
  4073     function startOf(units) {
       
  4074         var time, startOfDate;
  3418         units = normalizeUnits(units);
  4075         units = normalizeUnits(units);
  3419         // the following switch intentionally omits break keywords
  4076         if (units === undefined || units === 'millisecond' || !this.isValid()) {
  3420         // to utilize falling through the cases.
  4077             return this;
       
  4078         }
       
  4079 
       
  4080         startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
       
  4081 
  3421         switch (units) {
  4082         switch (units) {
  3422             case 'year':
  4083             case 'year':
  3423                 this.month(0);
  4084                 time = startOfDate(this.year(), 0, 1);
  3424                 /* falls through */
  4085                 break;
  3425             case 'quarter':
  4086             case 'quarter':
       
  4087                 time = startOfDate(
       
  4088                     this.year(),
       
  4089                     this.month() - (this.month() % 3),
       
  4090                     1
       
  4091                 );
       
  4092                 break;
  3426             case 'month':
  4093             case 'month':
  3427                 this.date(1);
  4094                 time = startOfDate(this.year(), this.month(), 1);
  3428                 /* falls through */
  4095                 break;
  3429             case 'week':
  4096             case 'week':
       
  4097                 time = startOfDate(
       
  4098                     this.year(),
       
  4099                     this.month(),
       
  4100                     this.date() - this.weekday()
       
  4101                 );
       
  4102                 break;
  3430             case 'isoWeek':
  4103             case 'isoWeek':
       
  4104                 time = startOfDate(
       
  4105                     this.year(),
       
  4106                     this.month(),
       
  4107                     this.date() - (this.isoWeekday() - 1)
       
  4108                 );
       
  4109                 break;
  3431             case 'day':
  4110             case 'day':
  3432             case 'date':
  4111             case 'date':
  3433                 this.hours(0);
  4112                 time = startOfDate(this.year(), this.month(), this.date());
  3434                 /* falls through */
  4113                 break;
  3435             case 'hour':
  4114             case 'hour':
  3436                 this.minutes(0);
  4115                 time = this._d.valueOf();
  3437                 /* falls through */
  4116                 time -= mod$1(
       
  4117                     time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
       
  4118                     MS_PER_HOUR
       
  4119                 );
       
  4120                 break;
  3438             case 'minute':
  4121             case 'minute':
  3439                 this.seconds(0);
  4122                 time = this._d.valueOf();
  3440                 /* falls through */
  4123                 time -= mod$1(time, MS_PER_MINUTE);
       
  4124                 break;
  3441             case 'second':
  4125             case 'second':
  3442                 this.milliseconds(0);
  4126                 time = this._d.valueOf();
  3443         }
  4127                 time -= mod$1(time, MS_PER_SECOND);
  3444 
  4128                 break;
  3445         // weeks are a special case
  4129         }
  3446         if (units === 'week') {
  4130 
  3447             this.weekday(0);
  4131         this._d.setTime(time);
  3448         }
  4132         hooks.updateOffset(this, true);
  3449         if (units === 'isoWeek') {
       
  3450             this.isoWeekday(1);
       
  3451         }
       
  3452 
       
  3453         // quarters are also special
       
  3454         if (units === 'quarter') {
       
  3455             this.month(Math.floor(this.month() / 3) * 3);
       
  3456         }
       
  3457 
       
  3458         return this;
  4133         return this;
  3459     }
  4134     }
  3460 
  4135 
  3461     function endOf (units) {
  4136     function endOf(units) {
       
  4137         var time, startOfDate;
  3462         units = normalizeUnits(units);
  4138         units = normalizeUnits(units);
  3463         if (units === undefined || units === 'millisecond') {
  4139         if (units === undefined || units === 'millisecond' || !this.isValid()) {
  3464             return this;
  4140             return this;
  3465         }
  4141         }
  3466 
  4142 
  3467         // 'date' is an alias for 'day', so it should be considered as such.
  4143         startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
  3468         if (units === 'date') {
  4144 
  3469             units = 'day';
  4145         switch (units) {
  3470         }
  4146             case 'year':
  3471 
  4147                 time = startOfDate(this.year() + 1, 0, 1) - 1;
  3472         return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  4148                 break;
  3473     }
  4149             case 'quarter':
  3474 
  4150                 time =
  3475     function valueOf () {
  4151                     startOfDate(
  3476         return this._d.valueOf() - ((this._offset || 0) * 60000);
  4152                         this.year(),
  3477     }
  4153                         this.month() - (this.month() % 3) + 3,
  3478 
  4154                         1
  3479     function unix () {
  4155                     ) - 1;
       
  4156                 break;
       
  4157             case 'month':
       
  4158                 time = startOfDate(this.year(), this.month() + 1, 1) - 1;
       
  4159                 break;
       
  4160             case 'week':
       
  4161                 time =
       
  4162                     startOfDate(
       
  4163                         this.year(),
       
  4164                         this.month(),
       
  4165                         this.date() - this.weekday() + 7
       
  4166                     ) - 1;
       
  4167                 break;
       
  4168             case 'isoWeek':
       
  4169                 time =
       
  4170                     startOfDate(
       
  4171                         this.year(),
       
  4172                         this.month(),
       
  4173                         this.date() - (this.isoWeekday() - 1) + 7
       
  4174                     ) - 1;
       
  4175                 break;
       
  4176             case 'day':
       
  4177             case 'date':
       
  4178                 time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
       
  4179                 break;
       
  4180             case 'hour':
       
  4181                 time = this._d.valueOf();
       
  4182                 time +=
       
  4183                     MS_PER_HOUR -
       
  4184                     mod$1(
       
  4185                         time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
       
  4186                         MS_PER_HOUR
       
  4187                     ) -
       
  4188                     1;
       
  4189                 break;
       
  4190             case 'minute':
       
  4191                 time = this._d.valueOf();
       
  4192                 time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
       
  4193                 break;
       
  4194             case 'second':
       
  4195                 time = this._d.valueOf();
       
  4196                 time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
       
  4197                 break;
       
  4198         }
       
  4199 
       
  4200         this._d.setTime(time);
       
  4201         hooks.updateOffset(this, true);
       
  4202         return this;
       
  4203     }
       
  4204 
       
  4205     function valueOf() {
       
  4206         return this._d.valueOf() - (this._offset || 0) * 60000;
       
  4207     }
       
  4208 
       
  4209     function unix() {
  3480         return Math.floor(this.valueOf() / 1000);
  4210         return Math.floor(this.valueOf() / 1000);
  3481     }
  4211     }
  3482 
  4212 
  3483     function toDate () {
  4213     function toDate() {
  3484         return new Date(this.valueOf());
  4214         return new Date(this.valueOf());
  3485     }
  4215     }
  3486 
  4216 
  3487     function toArray () {
  4217     function toArray() {
  3488         var m = this;
  4218         var m = this;
  3489         return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  4219         return [
  3490     }
  4220             m.year(),
  3491 
  4221             m.month(),
  3492     function toObject () {
  4222             m.date(),
       
  4223             m.hour(),
       
  4224             m.minute(),
       
  4225             m.second(),
       
  4226             m.millisecond(),
       
  4227         ];
       
  4228     }
       
  4229 
       
  4230     function toObject() {
  3493         var m = this;
  4231         var m = this;
  3494         return {
  4232         return {
  3495             years: m.year(),
  4233             years: m.year(),
  3496             months: m.month(),
  4234             months: m.month(),
  3497             date: m.date(),
  4235             date: m.date(),
  3498             hours: m.hours(),
  4236             hours: m.hours(),
  3499             minutes: m.minutes(),
  4237             minutes: m.minutes(),
  3500             seconds: m.seconds(),
  4238             seconds: m.seconds(),
  3501             milliseconds: m.milliseconds()
  4239             milliseconds: m.milliseconds(),
  3502         };
  4240         };
  3503     }
  4241     }
  3504 
  4242 
  3505     function toJSON () {
  4243     function toJSON() {
  3506         // new Date(NaN).toJSON() === null
  4244         // new Date(NaN).toJSON() === null
  3507         return this.isValid() ? this.toISOString() : null;
  4245         return this.isValid() ? this.toISOString() : null;
  3508     }
  4246     }
  3509 
  4247 
  3510     function isValid$2 () {
  4248     function isValid$2() {
  3511         return isValid(this);
  4249         return isValid(this);
  3512     }
  4250     }
  3513 
  4251 
  3514     function parsingFlags () {
  4252     function parsingFlags() {
  3515         return extend({}, getParsingFlags(this));
  4253         return extend({}, getParsingFlags(this));
  3516     }
  4254     }
  3517 
  4255 
  3518     function invalidAt () {
  4256     function invalidAt() {
  3519         return getParsingFlags(this).overflow;
  4257         return getParsingFlags(this).overflow;
  3520     }
  4258     }
  3521 
  4259 
  3522     function creationData() {
  4260     function creationData() {
  3523         return {
  4261         return {
  3524             input: this._i,
  4262             input: this._i,
  3525             format: this._f,
  4263             format: this._f,
  3526             locale: this._locale,
  4264             locale: this._locale,
  3527             isUTC: this._isUTC,
  4265             isUTC: this._isUTC,
  3528             strict: this._strict
  4266             strict: this._strict,
  3529         };
  4267         };
       
  4268     }
       
  4269 
       
  4270     addFormatToken('N', 0, 0, 'eraAbbr');
       
  4271     addFormatToken('NN', 0, 0, 'eraAbbr');
       
  4272     addFormatToken('NNN', 0, 0, 'eraAbbr');
       
  4273     addFormatToken('NNNN', 0, 0, 'eraName');
       
  4274     addFormatToken('NNNNN', 0, 0, 'eraNarrow');
       
  4275 
       
  4276     addFormatToken('y', ['y', 1], 'yo', 'eraYear');
       
  4277     addFormatToken('y', ['yy', 2], 0, 'eraYear');
       
  4278     addFormatToken('y', ['yyy', 3], 0, 'eraYear');
       
  4279     addFormatToken('y', ['yyyy', 4], 0, 'eraYear');
       
  4280 
       
  4281     addRegexToken('N', matchEraAbbr);
       
  4282     addRegexToken('NN', matchEraAbbr);
       
  4283     addRegexToken('NNN', matchEraAbbr);
       
  4284     addRegexToken('NNNN', matchEraName);
       
  4285     addRegexToken('NNNNN', matchEraNarrow);
       
  4286 
       
  4287     addParseToken(['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], function (
       
  4288         input,
       
  4289         array,
       
  4290         config,
       
  4291         token
       
  4292     ) {
       
  4293         var era = config._locale.erasParse(input, token, config._strict);
       
  4294         if (era) {
       
  4295             getParsingFlags(config).era = era;
       
  4296         } else {
       
  4297             getParsingFlags(config).invalidEra = input;
       
  4298         }
       
  4299     });
       
  4300 
       
  4301     addRegexToken('y', matchUnsigned);
       
  4302     addRegexToken('yy', matchUnsigned);
       
  4303     addRegexToken('yyy', matchUnsigned);
       
  4304     addRegexToken('yyyy', matchUnsigned);
       
  4305     addRegexToken('yo', matchEraYearOrdinal);
       
  4306 
       
  4307     addParseToken(['y', 'yy', 'yyy', 'yyyy'], YEAR);
       
  4308     addParseToken(['yo'], function (input, array, config, token) {
       
  4309         var match;
       
  4310         if (config._locale._eraYearOrdinalRegex) {
       
  4311             match = input.match(config._locale._eraYearOrdinalRegex);
       
  4312         }
       
  4313 
       
  4314         if (config._locale.eraYearOrdinalParse) {
       
  4315             array[YEAR] = config._locale.eraYearOrdinalParse(input, match);
       
  4316         } else {
       
  4317             array[YEAR] = parseInt(input, 10);
       
  4318         }
       
  4319     });
       
  4320 
       
  4321     function localeEras(m, format) {
       
  4322         var i,
       
  4323             l,
       
  4324             date,
       
  4325             eras = this._eras || getLocale('en')._eras;
       
  4326         for (i = 0, l = eras.length; i < l; ++i) {
       
  4327             switch (typeof eras[i].since) {
       
  4328                 case 'string':
       
  4329                     // truncate time
       
  4330                     date = hooks(eras[i].since).startOf('day');
       
  4331                     eras[i].since = date.valueOf();
       
  4332                     break;
       
  4333             }
       
  4334 
       
  4335             switch (typeof eras[i].until) {
       
  4336                 case 'undefined':
       
  4337                     eras[i].until = +Infinity;
       
  4338                     break;
       
  4339                 case 'string':
       
  4340                     // truncate time
       
  4341                     date = hooks(eras[i].until).startOf('day').valueOf();
       
  4342                     eras[i].until = date.valueOf();
       
  4343                     break;
       
  4344             }
       
  4345         }
       
  4346         return eras;
       
  4347     }
       
  4348 
       
  4349     function localeErasParse(eraName, format, strict) {
       
  4350         var i,
       
  4351             l,
       
  4352             eras = this.eras(),
       
  4353             name,
       
  4354             abbr,
       
  4355             narrow;
       
  4356         eraName = eraName.toUpperCase();
       
  4357 
       
  4358         for (i = 0, l = eras.length; i < l; ++i) {
       
  4359             name = eras[i].name.toUpperCase();
       
  4360             abbr = eras[i].abbr.toUpperCase();
       
  4361             narrow = eras[i].narrow.toUpperCase();
       
  4362 
       
  4363             if (strict) {
       
  4364                 switch (format) {
       
  4365                     case 'N':
       
  4366                     case 'NN':
       
  4367                     case 'NNN':
       
  4368                         if (abbr === eraName) {
       
  4369                             return eras[i];
       
  4370                         }
       
  4371                         break;
       
  4372 
       
  4373                     case 'NNNN':
       
  4374                         if (name === eraName) {
       
  4375                             return eras[i];
       
  4376                         }
       
  4377                         break;
       
  4378 
       
  4379                     case 'NNNNN':
       
  4380                         if (narrow === eraName) {
       
  4381                             return eras[i];
       
  4382                         }
       
  4383                         break;
       
  4384                 }
       
  4385             } else if ([name, abbr, narrow].indexOf(eraName) >= 0) {
       
  4386                 return eras[i];
       
  4387             }
       
  4388         }
       
  4389     }
       
  4390 
       
  4391     function localeErasConvertYear(era, year) {
       
  4392         var dir = era.since <= era.until ? +1 : -1;
       
  4393         if (year === undefined) {
       
  4394             return hooks(era.since).year();
       
  4395         } else {
       
  4396             return hooks(era.since).year() + (year - era.offset) * dir;
       
  4397         }
       
  4398     }
       
  4399 
       
  4400     function getEraName() {
       
  4401         var i,
       
  4402             l,
       
  4403             val,
       
  4404             eras = this.localeData().eras();
       
  4405         for (i = 0, l = eras.length; i < l; ++i) {
       
  4406             // truncate time
       
  4407             val = this.startOf('day').valueOf();
       
  4408 
       
  4409             if (eras[i].since <= val && val <= eras[i].until) {
       
  4410                 return eras[i].name;
       
  4411             }
       
  4412             if (eras[i].until <= val && val <= eras[i].since) {
       
  4413                 return eras[i].name;
       
  4414             }
       
  4415         }
       
  4416 
       
  4417         return '';
       
  4418     }
       
  4419 
       
  4420     function getEraNarrow() {
       
  4421         var i,
       
  4422             l,
       
  4423             val,
       
  4424             eras = this.localeData().eras();
       
  4425         for (i = 0, l = eras.length; i < l; ++i) {
       
  4426             // truncate time
       
  4427             val = this.startOf('day').valueOf();
       
  4428 
       
  4429             if (eras[i].since <= val && val <= eras[i].until) {
       
  4430                 return eras[i].narrow;
       
  4431             }
       
  4432             if (eras[i].until <= val && val <= eras[i].since) {
       
  4433                 return eras[i].narrow;
       
  4434             }
       
  4435         }
       
  4436 
       
  4437         return '';
       
  4438     }
       
  4439 
       
  4440     function getEraAbbr() {
       
  4441         var i,
       
  4442             l,
       
  4443             val,
       
  4444             eras = this.localeData().eras();
       
  4445         for (i = 0, l = eras.length; i < l; ++i) {
       
  4446             // truncate time
       
  4447             val = this.startOf('day').valueOf();
       
  4448 
       
  4449             if (eras[i].since <= val && val <= eras[i].until) {
       
  4450                 return eras[i].abbr;
       
  4451             }
       
  4452             if (eras[i].until <= val && val <= eras[i].since) {
       
  4453                 return eras[i].abbr;
       
  4454             }
       
  4455         }
       
  4456 
       
  4457         return '';
       
  4458     }
       
  4459 
       
  4460     function getEraYear() {
       
  4461         var i,
       
  4462             l,
       
  4463             dir,
       
  4464             val,
       
  4465             eras = this.localeData().eras();
       
  4466         for (i = 0, l = eras.length; i < l; ++i) {
       
  4467             dir = eras[i].since <= eras[i].until ? +1 : -1;
       
  4468 
       
  4469             // truncate time
       
  4470             val = this.startOf('day').valueOf();
       
  4471 
       
  4472             if (
       
  4473                 (eras[i].since <= val && val <= eras[i].until) ||
       
  4474                 (eras[i].until <= val && val <= eras[i].since)
       
  4475             ) {
       
  4476                 return (
       
  4477                     (this.year() - hooks(eras[i].since).year()) * dir +
       
  4478                     eras[i].offset
       
  4479                 );
       
  4480             }
       
  4481         }
       
  4482 
       
  4483         return this.year();
       
  4484     }
       
  4485 
       
  4486     function erasNameRegex(isStrict) {
       
  4487         if (!hasOwnProp(this, '_erasNameRegex')) {
       
  4488             computeErasParse.call(this);
       
  4489         }
       
  4490         return isStrict ? this._erasNameRegex : this._erasRegex;
       
  4491     }
       
  4492 
       
  4493     function erasAbbrRegex(isStrict) {
       
  4494         if (!hasOwnProp(this, '_erasAbbrRegex')) {
       
  4495             computeErasParse.call(this);
       
  4496         }
       
  4497         return isStrict ? this._erasAbbrRegex : this._erasRegex;
       
  4498     }
       
  4499 
       
  4500     function erasNarrowRegex(isStrict) {
       
  4501         if (!hasOwnProp(this, '_erasNarrowRegex')) {
       
  4502             computeErasParse.call(this);
       
  4503         }
       
  4504         return isStrict ? this._erasNarrowRegex : this._erasRegex;
       
  4505     }
       
  4506 
       
  4507     function matchEraAbbr(isStrict, locale) {
       
  4508         return locale.erasAbbrRegex(isStrict);
       
  4509     }
       
  4510 
       
  4511     function matchEraName(isStrict, locale) {
       
  4512         return locale.erasNameRegex(isStrict);
       
  4513     }
       
  4514 
       
  4515     function matchEraNarrow(isStrict, locale) {
       
  4516         return locale.erasNarrowRegex(isStrict);
       
  4517     }
       
  4518 
       
  4519     function matchEraYearOrdinal(isStrict, locale) {
       
  4520         return locale._eraYearOrdinalRegex || matchUnsigned;
       
  4521     }
       
  4522 
       
  4523     function computeErasParse() {
       
  4524         var abbrPieces = [],
       
  4525             namePieces = [],
       
  4526             narrowPieces = [],
       
  4527             mixedPieces = [],
       
  4528             i,
       
  4529             l,
       
  4530             eras = this.eras();
       
  4531 
       
  4532         for (i = 0, l = eras.length; i < l; ++i) {
       
  4533             namePieces.push(regexEscape(eras[i].name));
       
  4534             abbrPieces.push(regexEscape(eras[i].abbr));
       
  4535             narrowPieces.push(regexEscape(eras[i].narrow));
       
  4536 
       
  4537             mixedPieces.push(regexEscape(eras[i].name));
       
  4538             mixedPieces.push(regexEscape(eras[i].abbr));
       
  4539             mixedPieces.push(regexEscape(eras[i].narrow));
       
  4540         }
       
  4541 
       
  4542         this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
       
  4543         this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i');
       
  4544         this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i');
       
  4545         this._erasNarrowRegex = new RegExp(
       
  4546             '^(' + narrowPieces.join('|') + ')',
       
  4547             'i'
       
  4548         );
  3530     }
  4549     }
  3531 
  4550 
  3532     // FORMATTING
  4551     // FORMATTING
  3533 
  4552 
  3534     addFormatToken(0, ['gg', 2], 0, function () {
  4553     addFormatToken(0, ['gg', 2], 0, function () {
  3537 
  4556 
  3538     addFormatToken(0, ['GG', 2], 0, function () {
  4557     addFormatToken(0, ['GG', 2], 0, function () {
  3539         return this.isoWeekYear() % 100;
  4558         return this.isoWeekYear() % 100;
  3540     });
  4559     });
  3541 
  4560 
  3542     function addWeekYearFormatToken (token, getter) {
  4561     function addWeekYearFormatToken(token, getter) {
  3543         addFormatToken(0, [token, token.length], 0, getter);
  4562         addFormatToken(0, [token, token.length], 0, getter);
  3544     }
  4563     }
  3545 
  4564 
  3546     addWeekYearFormatToken('gggg',     'weekYear');
  4565     addWeekYearFormatToken('gggg', 'weekYear');
  3547     addWeekYearFormatToken('ggggg',    'weekYear');
  4566     addWeekYearFormatToken('ggggg', 'weekYear');
  3548     addWeekYearFormatToken('GGGG',  'isoWeekYear');
  4567     addWeekYearFormatToken('GGGG', 'isoWeekYear');
  3549     addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  4568     addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  3550 
  4569 
  3551     // ALIASES
  4570     // ALIASES
  3552 
  4571 
  3553     addUnitAlias('weekYear', 'gg');
  4572     addUnitAlias('weekYear', 'gg');
  3556     // PRIORITY
  4575     // PRIORITY
  3557 
  4576 
  3558     addUnitPriority('weekYear', 1);
  4577     addUnitPriority('weekYear', 1);
  3559     addUnitPriority('isoWeekYear', 1);
  4578     addUnitPriority('isoWeekYear', 1);
  3560 
  4579 
  3561 
       
  3562     // PARSING
  4580     // PARSING
  3563 
  4581 
  3564     addRegexToken('G',      matchSigned);
  4582     addRegexToken('G', matchSigned);
  3565     addRegexToken('g',      matchSigned);
  4583     addRegexToken('g', matchSigned);
  3566     addRegexToken('GG',     match1to2, match2);
  4584     addRegexToken('GG', match1to2, match2);
  3567     addRegexToken('gg',     match1to2, match2);
  4585     addRegexToken('gg', match1to2, match2);
  3568     addRegexToken('GGGG',   match1to4, match4);
  4586     addRegexToken('GGGG', match1to4, match4);
  3569     addRegexToken('gggg',   match1to4, match4);
  4587     addRegexToken('gggg', match1to4, match4);
  3570     addRegexToken('GGGGG',  match1to6, match6);
  4588     addRegexToken('GGGGG', match1to6, match6);
  3571     addRegexToken('ggggg',  match1to6, match6);
  4589     addRegexToken('ggggg', match1to6, match6);
  3572 
  4590 
  3573     addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  4591     addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (
       
  4592         input,
       
  4593         week,
       
  4594         config,
       
  4595         token
       
  4596     ) {
  3574         week[token.substr(0, 2)] = toInt(input);
  4597         week[token.substr(0, 2)] = toInt(input);
  3575     });
  4598     });
  3576 
  4599 
  3577     addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  4600     addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  3578         week[token] = hooks.parseTwoDigitYear(input);
  4601         week[token] = hooks.parseTwoDigitYear(input);
  3579     });
  4602     });
  3580 
  4603 
  3581     // MOMENTS
  4604     // MOMENTS
  3582 
  4605 
  3583     function getSetWeekYear (input) {
  4606     function getSetWeekYear(input) {
  3584         return getSetWeekYearHelper.call(this,
  4607         return getSetWeekYearHelper.call(
  3585                 input,
  4608             this,
  3586                 this.week(),
  4609             input,
  3587                 this.weekday(),
  4610             this.week(),
  3588                 this.localeData()._week.dow,
  4611             this.weekday(),
  3589                 this.localeData()._week.doy);
  4612             this.localeData()._week.dow,
  3590     }
  4613             this.localeData()._week.doy
  3591 
  4614         );
  3592     function getSetISOWeekYear (input) {
  4615     }
  3593         return getSetWeekYearHelper.call(this,
  4616 
  3594                 input, this.isoWeek(), this.isoWeekday(), 1, 4);
  4617     function getSetISOWeekYear(input) {
  3595     }
  4618         return getSetWeekYearHelper.call(
  3596 
  4619             this,
  3597     function getISOWeeksInYear () {
  4620             input,
       
  4621             this.isoWeek(),
       
  4622             this.isoWeekday(),
       
  4623             1,
       
  4624             4
       
  4625         );
       
  4626     }
       
  4627 
       
  4628     function getISOWeeksInYear() {
  3598         return weeksInYear(this.year(), 1, 4);
  4629         return weeksInYear(this.year(), 1, 4);
  3599     }
  4630     }
  3600 
  4631 
  3601     function getWeeksInYear () {
  4632     function getISOWeeksInISOWeekYear() {
       
  4633         return weeksInYear(this.isoWeekYear(), 1, 4);
       
  4634     }
       
  4635 
       
  4636     function getWeeksInYear() {
  3602         var weekInfo = this.localeData()._week;
  4637         var weekInfo = this.localeData()._week;
  3603         return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  4638         return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
       
  4639     }
       
  4640 
       
  4641     function getWeeksInWeekYear() {
       
  4642         var weekInfo = this.localeData()._week;
       
  4643         return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
  3604     }
  4644     }
  3605 
  4645 
  3606     function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  4646     function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  3607         var weeksTarget;
  4647         var weeksTarget;
  3608         if (input == null) {
  4648         if (input == null) {
  3645         array[MONTH] = (toInt(input) - 1) * 3;
  4685         array[MONTH] = (toInt(input) - 1) * 3;
  3646     });
  4686     });
  3647 
  4687 
  3648     // MOMENTS
  4688     // MOMENTS
  3649 
  4689 
  3650     function getSetQuarter (input) {
  4690     function getSetQuarter(input) {
  3651         return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  4691         return input == null
       
  4692             ? Math.ceil((this.month() + 1) / 3)
       
  4693             : this.month((input - 1) * 3 + (this.month() % 3));
  3652     }
  4694     }
  3653 
  4695 
  3654     // FORMATTING
  4696     // FORMATTING
  3655 
  4697 
  3656     addFormatToken('D', ['DD', 2], 'Do', 'date');
  4698     addFormatToken('D', ['DD', 2], 'Do', 'date');
  3662     // PRIORITY
  4704     // PRIORITY
  3663     addUnitPriority('date', 9);
  4705     addUnitPriority('date', 9);
  3664 
  4706 
  3665     // PARSING
  4707     // PARSING
  3666 
  4708 
  3667     addRegexToken('D',  match1to2);
  4709     addRegexToken('D', match1to2);
  3668     addRegexToken('DD', match1to2, match2);
  4710     addRegexToken('DD', match1to2, match2);
  3669     addRegexToken('Do', function (isStrict, locale) {
  4711     addRegexToken('Do', function (isStrict, locale) {
  3670         // TODO: Remove "ordinalParse" fallback in next major release.
  4712         // TODO: Remove "ordinalParse" fallback in next major release.
  3671         return isStrict ?
  4713         return isStrict
  3672           (locale._dayOfMonthOrdinalParse || locale._ordinalParse) :
  4714             ? locale._dayOfMonthOrdinalParse || locale._ordinalParse
  3673           locale._dayOfMonthOrdinalParseLenient;
  4715             : locale._dayOfMonthOrdinalParseLenient;
  3674     });
  4716     });
  3675 
  4717 
  3676     addParseToken(['D', 'DD'], DATE);
  4718     addParseToken(['D', 'DD'], DATE);
  3677     addParseToken('Do', function (input, array) {
  4719     addParseToken('Do', function (input, array) {
  3678         array[DATE] = toInt(input.match(match1to2)[0]);
  4720         array[DATE] = toInt(input.match(match1to2)[0]);
  3693     // PRIORITY
  4735     // PRIORITY
  3694     addUnitPriority('dayOfYear', 4);
  4736     addUnitPriority('dayOfYear', 4);
  3695 
  4737 
  3696     // PARSING
  4738     // PARSING
  3697 
  4739 
  3698     addRegexToken('DDD',  match1to3);
  4740     addRegexToken('DDD', match1to3);
  3699     addRegexToken('DDDD', match3);
  4741     addRegexToken('DDDD', match3);
  3700     addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  4742     addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  3701         config._dayOfYear = toInt(input);
  4743         config._dayOfYear = toInt(input);
  3702     });
  4744     });
  3703 
  4745 
  3704     // HELPERS
  4746     // HELPERS
  3705 
  4747 
  3706     // MOMENTS
  4748     // MOMENTS
  3707 
  4749 
  3708     function getSetDayOfYear (input) {
  4750     function getSetDayOfYear(input) {
  3709         var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  4751         var dayOfYear =
  3710         return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  4752             Math.round(
       
  4753                 (this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
       
  4754             ) + 1;
       
  4755         return input == null ? dayOfYear : this.add(input - dayOfYear, 'd');
  3711     }
  4756     }
  3712 
  4757 
  3713     // FORMATTING
  4758     // FORMATTING
  3714 
  4759 
  3715     addFormatToken('m', ['mm', 2], 0, 'minute');
  4760     addFormatToken('m', ['mm', 2], 0, 'minute');
  3722 
  4767 
  3723     addUnitPriority('minute', 14);
  4768     addUnitPriority('minute', 14);
  3724 
  4769 
  3725     // PARSING
  4770     // PARSING
  3726 
  4771 
  3727     addRegexToken('m',  match1to2);
  4772     addRegexToken('m', match1to2);
  3728     addRegexToken('mm', match1to2, match2);
  4773     addRegexToken('mm', match1to2, match2);
  3729     addParseToken(['m', 'mm'], MINUTE);
  4774     addParseToken(['m', 'mm'], MINUTE);
  3730 
  4775 
  3731     // MOMENTS
  4776     // MOMENTS
  3732 
  4777 
  3744 
  4789 
  3745     addUnitPriority('second', 15);
  4790     addUnitPriority('second', 15);
  3746 
  4791 
  3747     // PARSING
  4792     // PARSING
  3748 
  4793 
  3749     addRegexToken('s',  match1to2);
  4794     addRegexToken('s', match1to2);
  3750     addRegexToken('ss', match1to2, match2);
  4795     addRegexToken('ss', match1to2, match2);
  3751     addParseToken(['s', 'ss'], SECOND);
  4796     addParseToken(['s', 'ss'], SECOND);
  3752 
  4797 
  3753     // MOMENTS
  4798     // MOMENTS
  3754 
  4799 
  3782     });
  4827     });
  3783     addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  4828     addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  3784         return this.millisecond() * 1000000;
  4829         return this.millisecond() * 1000000;
  3785     });
  4830     });
  3786 
  4831 
  3787 
       
  3788     // ALIASES
  4832     // ALIASES
  3789 
  4833 
  3790     addUnitAlias('millisecond', 'ms');
  4834     addUnitAlias('millisecond', 'ms');
  3791 
  4835 
  3792     // PRIORITY
  4836     // PRIORITY
  3793 
  4837 
  3794     addUnitPriority('millisecond', 16);
  4838     addUnitPriority('millisecond', 16);
  3795 
  4839 
  3796     // PARSING
  4840     // PARSING
  3797 
  4841 
  3798     addRegexToken('S',    match1to3, match1);
  4842     addRegexToken('S', match1to3, match1);
  3799     addRegexToken('SS',   match1to3, match2);
  4843     addRegexToken('SS', match1to3, match2);
  3800     addRegexToken('SSS',  match1to3, match3);
  4844     addRegexToken('SSS', match1to3, match3);
  3801 
  4845 
  3802     var token;
  4846     var token, getSetMillisecond;
  3803     for (token = 'SSSS'; token.length <= 9; token += 'S') {
  4847     for (token = 'SSSS'; token.length <= 9; token += 'S') {
  3804         addRegexToken(token, matchUnsigned);
  4848         addRegexToken(token, matchUnsigned);
  3805     }
  4849     }
  3806 
  4850 
  3807     function parseMs(input, array) {
  4851     function parseMs(input, array) {
  3809     }
  4853     }
  3810 
  4854 
  3811     for (token = 'S'; token.length <= 9; token += 'S') {
  4855     for (token = 'S'; token.length <= 9; token += 'S') {
  3812         addParseToken(token, parseMs);
  4856         addParseToken(token, parseMs);
  3813     }
  4857     }
       
  4858 
       
  4859     getSetMillisecond = makeGetSet('Milliseconds', false);
       
  4860 
       
  4861     // FORMATTING
       
  4862 
       
  4863     addFormatToken('z', 0, 0, 'zoneAbbr');
       
  4864     addFormatToken('zz', 0, 0, 'zoneName');
       
  4865 
  3814     // MOMENTS
  4866     // MOMENTS
  3815 
  4867 
  3816     var getSetMillisecond = makeGetSet('Milliseconds', false);
  4868     function getZoneAbbr() {
  3817 
       
  3818     // FORMATTING
       
  3819 
       
  3820     addFormatToken('z',  0, 0, 'zoneAbbr');
       
  3821     addFormatToken('zz', 0, 0, 'zoneName');
       
  3822 
       
  3823     // MOMENTS
       
  3824 
       
  3825     function getZoneAbbr () {
       
  3826         return this._isUTC ? 'UTC' : '';
  4869         return this._isUTC ? 'UTC' : '';
  3827     }
  4870     }
  3828 
  4871 
  3829     function getZoneName () {
  4872     function getZoneName() {
  3830         return this._isUTC ? 'Coordinated Universal Time' : '';
  4873         return this._isUTC ? 'Coordinated Universal Time' : '';
  3831     }
  4874     }
  3832 
  4875 
  3833     var proto = Moment.prototype;
  4876     var proto = Moment.prototype;
  3834 
  4877 
  3835     proto.add               = add;
  4878     proto.add = add;
  3836     proto.calendar          = calendar$1;
  4879     proto.calendar = calendar$1;
  3837     proto.clone             = clone;
  4880     proto.clone = clone;
  3838     proto.diff              = diff;
  4881     proto.diff = diff;
  3839     proto.endOf             = endOf;
  4882     proto.endOf = endOf;
  3840     proto.format            = format;
  4883     proto.format = format;
  3841     proto.from              = from;
  4884     proto.from = from;
  3842     proto.fromNow           = fromNow;
  4885     proto.fromNow = fromNow;
  3843     proto.to                = to;
  4886     proto.to = to;
  3844     proto.toNow             = toNow;
  4887     proto.toNow = toNow;
  3845     proto.get               = stringGet;
  4888     proto.get = stringGet;
  3846     proto.invalidAt         = invalidAt;
  4889     proto.invalidAt = invalidAt;
  3847     proto.isAfter           = isAfter;
  4890     proto.isAfter = isAfter;
  3848     proto.isBefore          = isBefore;
  4891     proto.isBefore = isBefore;
  3849     proto.isBetween         = isBetween;
  4892     proto.isBetween = isBetween;
  3850     proto.isSame            = isSame;
  4893     proto.isSame = isSame;
  3851     proto.isSameOrAfter     = isSameOrAfter;
  4894     proto.isSameOrAfter = isSameOrAfter;
  3852     proto.isSameOrBefore    = isSameOrBefore;
  4895     proto.isSameOrBefore = isSameOrBefore;
  3853     proto.isValid           = isValid$2;
  4896     proto.isValid = isValid$2;
  3854     proto.lang              = lang;
  4897     proto.lang = lang;
  3855     proto.locale            = locale;
  4898     proto.locale = locale;
  3856     proto.localeData        = localeData;
  4899     proto.localeData = localeData;
  3857     proto.max               = prototypeMax;
  4900     proto.max = prototypeMax;
  3858     proto.min               = prototypeMin;
  4901     proto.min = prototypeMin;
  3859     proto.parsingFlags      = parsingFlags;
  4902     proto.parsingFlags = parsingFlags;
  3860     proto.set               = stringSet;
  4903     proto.set = stringSet;
  3861     proto.startOf           = startOf;
  4904     proto.startOf = startOf;
  3862     proto.subtract          = subtract;
  4905     proto.subtract = subtract;
  3863     proto.toArray           = toArray;
  4906     proto.toArray = toArray;
  3864     proto.toObject          = toObject;
  4907     proto.toObject = toObject;
  3865     proto.toDate            = toDate;
  4908     proto.toDate = toDate;
  3866     proto.toISOString       = toISOString;
  4909     proto.toISOString = toISOString;
  3867     proto.inspect           = inspect;
  4910     proto.inspect = inspect;
  3868     proto.toJSON            = toJSON;
  4911     if (typeof Symbol !== 'undefined' && Symbol.for != null) {
  3869     proto.toString          = toString;
  4912         proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
  3870     proto.unix              = unix;
  4913             return 'Moment<' + this.format() + '>';
  3871     proto.valueOf           = valueOf;
  4914         };
  3872     proto.creationData      = creationData;
  4915     }
  3873     proto.year       = getSetYear;
  4916     proto.toJSON = toJSON;
       
  4917     proto.toString = toString;
       
  4918     proto.unix = unix;
       
  4919     proto.valueOf = valueOf;
       
  4920     proto.creationData = creationData;
       
  4921     proto.eraName = getEraName;
       
  4922     proto.eraNarrow = getEraNarrow;
       
  4923     proto.eraAbbr = getEraAbbr;
       
  4924     proto.eraYear = getEraYear;
       
  4925     proto.year = getSetYear;
  3874     proto.isLeapYear = getIsLeapYear;
  4926     proto.isLeapYear = getIsLeapYear;
  3875     proto.weekYear    = getSetWeekYear;
  4927     proto.weekYear = getSetWeekYear;
  3876     proto.isoWeekYear = getSetISOWeekYear;
  4928     proto.isoWeekYear = getSetISOWeekYear;
  3877     proto.quarter = proto.quarters = getSetQuarter;
  4929     proto.quarter = proto.quarters = getSetQuarter;
  3878     proto.month       = getSetMonth;
  4930     proto.month = getSetMonth;
  3879     proto.daysInMonth = getDaysInMonth;
  4931     proto.daysInMonth = getDaysInMonth;
  3880     proto.week           = proto.weeks        = getSetWeek;
  4932     proto.week = proto.weeks = getSetWeek;
  3881     proto.isoWeek        = proto.isoWeeks     = getSetISOWeek;
  4933     proto.isoWeek = proto.isoWeeks = getSetISOWeek;
  3882     proto.weeksInYear    = getWeeksInYear;
  4934     proto.weeksInYear = getWeeksInYear;
       
  4935     proto.weeksInWeekYear = getWeeksInWeekYear;
  3883     proto.isoWeeksInYear = getISOWeeksInYear;
  4936     proto.isoWeeksInYear = getISOWeeksInYear;
  3884     proto.date       = getSetDayOfMonth;
  4937     proto.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear;
  3885     proto.day        = proto.days             = getSetDayOfWeek;
  4938     proto.date = getSetDayOfMonth;
  3886     proto.weekday    = getSetLocaleDayOfWeek;
  4939     proto.day = proto.days = getSetDayOfWeek;
       
  4940     proto.weekday = getSetLocaleDayOfWeek;
  3887     proto.isoWeekday = getSetISODayOfWeek;
  4941     proto.isoWeekday = getSetISODayOfWeek;
  3888     proto.dayOfYear  = getSetDayOfYear;
  4942     proto.dayOfYear = getSetDayOfYear;
  3889     proto.hour = proto.hours = getSetHour;
  4943     proto.hour = proto.hours = getSetHour;
  3890     proto.minute = proto.minutes = getSetMinute;
  4944     proto.minute = proto.minutes = getSetMinute;
  3891     proto.second = proto.seconds = getSetSecond;
  4945     proto.second = proto.seconds = getSetSecond;
  3892     proto.millisecond = proto.milliseconds = getSetMillisecond;
  4946     proto.millisecond = proto.milliseconds = getSetMillisecond;
  3893     proto.utcOffset            = getSetOffset;
  4947     proto.utcOffset = getSetOffset;
  3894     proto.utc                  = setOffsetToUTC;
  4948     proto.utc = setOffsetToUTC;
  3895     proto.local                = setOffsetToLocal;
  4949     proto.local = setOffsetToLocal;
  3896     proto.parseZone            = setOffsetToParsedOffset;
  4950     proto.parseZone = setOffsetToParsedOffset;
  3897     proto.hasAlignedHourOffset = hasAlignedHourOffset;
  4951     proto.hasAlignedHourOffset = hasAlignedHourOffset;
  3898     proto.isDST                = isDaylightSavingTime;
  4952     proto.isDST = isDaylightSavingTime;
  3899     proto.isLocal              = isLocal;
  4953     proto.isLocal = isLocal;
  3900     proto.isUtcOffset          = isUtcOffset;
  4954     proto.isUtcOffset = isUtcOffset;
  3901     proto.isUtc                = isUtc;
  4955     proto.isUtc = isUtc;
  3902     proto.isUTC                = isUtc;
  4956     proto.isUTC = isUtc;
  3903     proto.zoneAbbr = getZoneAbbr;
  4957     proto.zoneAbbr = getZoneAbbr;
  3904     proto.zoneName = getZoneName;
  4958     proto.zoneName = getZoneName;
  3905     proto.dates  = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  4959     proto.dates = deprecate(
  3906     proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  4960         'dates accessor is deprecated. Use date instead.',
  3907     proto.years  = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  4961         getSetDayOfMonth
  3908     proto.zone   = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone);
  4962     );
  3909     proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted);
  4963     proto.months = deprecate(
  3910 
  4964         'months accessor is deprecated. Use month instead',
  3911     function createUnix (input) {
  4965         getSetMonth
       
  4966     );
       
  4967     proto.years = deprecate(
       
  4968         'years accessor is deprecated. Use year instead',
       
  4969         getSetYear
       
  4970     );
       
  4971     proto.zone = deprecate(
       
  4972         'moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',
       
  4973         getSetZone
       
  4974     );
       
  4975     proto.isDSTShifted = deprecate(
       
  4976         'isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',
       
  4977         isDaylightSavingTimeShifted
       
  4978     );
       
  4979 
       
  4980     function createUnix(input) {
  3912         return createLocal(input * 1000);
  4981         return createLocal(input * 1000);
  3913     }
  4982     }
  3914 
  4983 
  3915     function createInZone () {
  4984     function createInZone() {
  3916         return createLocal.apply(null, arguments).parseZone();
  4985         return createLocal.apply(null, arguments).parseZone();
  3917     }
  4986     }
  3918 
  4987 
  3919     function preParsePostFormat (string) {
  4988     function preParsePostFormat(string) {
  3920         return string;
  4989         return string;
  3921     }
  4990     }
  3922 
  4991 
  3923     var proto$1 = Locale.prototype;
  4992     var proto$1 = Locale.prototype;
  3924 
  4993 
  3925     proto$1.calendar        = calendar;
  4994     proto$1.calendar = calendar;
  3926     proto$1.longDateFormat  = longDateFormat;
  4995     proto$1.longDateFormat = longDateFormat;
  3927     proto$1.invalidDate     = invalidDate;
  4996     proto$1.invalidDate = invalidDate;
  3928     proto$1.ordinal         = ordinal;
  4997     proto$1.ordinal = ordinal;
  3929     proto$1.preparse        = preParsePostFormat;
  4998     proto$1.preparse = preParsePostFormat;
  3930     proto$1.postformat      = preParsePostFormat;
  4999     proto$1.postformat = preParsePostFormat;
  3931     proto$1.relativeTime    = relativeTime;
  5000     proto$1.relativeTime = relativeTime;
  3932     proto$1.pastFuture      = pastFuture;
  5001     proto$1.pastFuture = pastFuture;
  3933     proto$1.set             = set;
  5002     proto$1.set = set;
  3934 
  5003     proto$1.eras = localeEras;
  3935     proto$1.months            =        localeMonths;
  5004     proto$1.erasParse = localeErasParse;
  3936     proto$1.monthsShort       =        localeMonthsShort;
  5005     proto$1.erasConvertYear = localeErasConvertYear;
  3937     proto$1.monthsParse       =        localeMonthsParse;
  5006     proto$1.erasAbbrRegex = erasAbbrRegex;
  3938     proto$1.monthsRegex       = monthsRegex;
  5007     proto$1.erasNameRegex = erasNameRegex;
  3939     proto$1.monthsShortRegex  = monthsShortRegex;
  5008     proto$1.erasNarrowRegex = erasNarrowRegex;
       
  5009 
       
  5010     proto$1.months = localeMonths;
       
  5011     proto$1.monthsShort = localeMonthsShort;
       
  5012     proto$1.monthsParse = localeMonthsParse;
       
  5013     proto$1.monthsRegex = monthsRegex;
       
  5014     proto$1.monthsShortRegex = monthsShortRegex;
  3940     proto$1.week = localeWeek;
  5015     proto$1.week = localeWeek;
  3941     proto$1.firstDayOfYear = localeFirstDayOfYear;
  5016     proto$1.firstDayOfYear = localeFirstDayOfYear;
  3942     proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  5017     proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  3943 
  5018 
  3944     proto$1.weekdays       =        localeWeekdays;
  5019     proto$1.weekdays = localeWeekdays;
  3945     proto$1.weekdaysMin    =        localeWeekdaysMin;
  5020     proto$1.weekdaysMin = localeWeekdaysMin;
  3946     proto$1.weekdaysShort  =        localeWeekdaysShort;
  5021     proto$1.weekdaysShort = localeWeekdaysShort;
  3947     proto$1.weekdaysParse  =        localeWeekdaysParse;
  5022     proto$1.weekdaysParse = localeWeekdaysParse;
  3948 
  5023 
  3949     proto$1.weekdaysRegex       =        weekdaysRegex;
  5024     proto$1.weekdaysRegex = weekdaysRegex;
  3950     proto$1.weekdaysShortRegex  =        weekdaysShortRegex;
  5025     proto$1.weekdaysShortRegex = weekdaysShortRegex;
  3951     proto$1.weekdaysMinRegex    =        weekdaysMinRegex;
  5026     proto$1.weekdaysMinRegex = weekdaysMinRegex;
  3952 
  5027 
  3953     proto$1.isPM = localeIsPM;
  5028     proto$1.isPM = localeIsPM;
  3954     proto$1.meridiem = localeMeridiem;
  5029     proto$1.meridiem = localeMeridiem;
  3955 
  5030 
  3956     function get$1 (format, index, field, setter) {
  5031     function get$1(format, index, field, setter) {
  3957         var locale = getLocale();
  5032         var locale = getLocale(),
  3958         var utc = createUTC().set(setter, index);
  5033             utc = createUTC().set(setter, index);
  3959         return locale[field](utc, format);
  5034         return locale[field](utc, format);
  3960     }
  5035     }
  3961 
  5036 
  3962     function listMonthsImpl (format, index, field) {
  5037     function listMonthsImpl(format, index, field) {
  3963         if (isNumber(format)) {
  5038         if (isNumber(format)) {
  3964             index = format;
  5039             index = format;
  3965             format = undefined;
  5040             format = undefined;
  3966         }
  5041         }
  3967 
  5042 
  3969 
  5044 
  3970         if (index != null) {
  5045         if (index != null) {
  3971             return get$1(format, index, field, 'month');
  5046             return get$1(format, index, field, 'month');
  3972         }
  5047         }
  3973 
  5048 
  3974         var i;
  5049         var i,
  3975         var out = [];
  5050             out = [];
  3976         for (i = 0; i < 12; i++) {
  5051         for (i = 0; i < 12; i++) {
  3977             out[i] = get$1(format, i, field, 'month');
  5052             out[i] = get$1(format, i, field, 'month');
  3978         }
  5053         }
  3979         return out;
  5054         return out;
  3980     }
  5055     }
  3985     // (fmt)
  5060     // (fmt)
  3986     // (true)
  5061     // (true)
  3987     // (true, 5)
  5062     // (true, 5)
  3988     // (true, fmt, 5)
  5063     // (true, fmt, 5)
  3989     // (true, fmt)
  5064     // (true, fmt)
  3990     function listWeekdaysImpl (localeSorted, format, index, field) {
  5065     function listWeekdaysImpl(localeSorted, format, index, field) {
  3991         if (typeof localeSorted === 'boolean') {
  5066         if (typeof localeSorted === 'boolean') {
  3992             if (isNumber(format)) {
  5067             if (isNumber(format)) {
  3993                 index = format;
  5068                 index = format;
  3994                 format = undefined;
  5069                 format = undefined;
  3995             }
  5070             }
  4007 
  5082 
  4008             format = format || '';
  5083             format = format || '';
  4009         }
  5084         }
  4010 
  5085 
  4011         var locale = getLocale(),
  5086         var locale = getLocale(),
  4012             shift = localeSorted ? locale._week.dow : 0;
  5087             shift = localeSorted ? locale._week.dow : 0,
       
  5088             i,
       
  5089             out = [];
  4013 
  5090 
  4014         if (index != null) {
  5091         if (index != null) {
  4015             return get$1(format, (index + shift) % 7, field, 'day');
  5092             return get$1(format, (index + shift) % 7, field, 'day');
  4016         }
  5093         }
  4017 
  5094 
  4018         var i;
       
  4019         var out = [];
       
  4020         for (i = 0; i < 7; i++) {
  5095         for (i = 0; i < 7; i++) {
  4021             out[i] = get$1(format, (i + shift) % 7, field, 'day');
  5096             out[i] = get$1(format, (i + shift) % 7, field, 'day');
  4022         }
  5097         }
  4023         return out;
  5098         return out;
  4024     }
  5099     }
  4025 
  5100 
  4026     function listMonths (format, index) {
  5101     function listMonths(format, index) {
  4027         return listMonthsImpl(format, index, 'months');
  5102         return listMonthsImpl(format, index, 'months');
  4028     }
  5103     }
  4029 
  5104 
  4030     function listMonthsShort (format, index) {
  5105     function listMonthsShort(format, index) {
  4031         return listMonthsImpl(format, index, 'monthsShort');
  5106         return listMonthsImpl(format, index, 'monthsShort');
  4032     }
  5107     }
  4033 
  5108 
  4034     function listWeekdays (localeSorted, format, index) {
  5109     function listWeekdays(localeSorted, format, index) {
  4035         return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  5110         return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  4036     }
  5111     }
  4037 
  5112 
  4038     function listWeekdaysShort (localeSorted, format, index) {
  5113     function listWeekdaysShort(localeSorted, format, index) {
  4039         return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  5114         return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  4040     }
  5115     }
  4041 
  5116 
  4042     function listWeekdaysMin (localeSorted, format, index) {
  5117     function listWeekdaysMin(localeSorted, format, index) {
  4043         return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  5118         return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  4044     }
  5119     }
  4045 
  5120 
  4046     getSetGlobalLocale('en', {
  5121     getSetGlobalLocale('en', {
       
  5122         eras: [
       
  5123             {
       
  5124                 since: '0001-01-01',
       
  5125                 until: +Infinity,
       
  5126                 offset: 1,
       
  5127                 name: 'Anno Domini',
       
  5128                 narrow: 'AD',
       
  5129                 abbr: 'AD',
       
  5130             },
       
  5131             {
       
  5132                 since: '0000-12-31',
       
  5133                 until: -Infinity,
       
  5134                 offset: 1,
       
  5135                 name: 'Before Christ',
       
  5136                 narrow: 'BC',
       
  5137                 abbr: 'BC',
       
  5138             },
       
  5139         ],
  4047         dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  5140         dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  4048         ordinal : function (number) {
  5141         ordinal: function (number) {
  4049             var b = number % 10,
  5142             var b = number % 10,
  4050                 output = (toInt(number % 100 / 10) === 1) ? 'th' :
  5143                 output =
  4051                 (b === 1) ? 'st' :
  5144                     toInt((number % 100) / 10) === 1
  4052                 (b === 2) ? 'nd' :
  5145                         ? 'th'
  4053                 (b === 3) ? 'rd' : 'th';
  5146                         : b === 1
       
  5147                         ? 'st'
       
  5148                         : b === 2
       
  5149                         ? 'nd'
       
  5150                         : b === 3
       
  5151                         ? 'rd'
       
  5152                         : 'th';
  4054             return number + output;
  5153             return number + output;
  4055         }
  5154         },
  4056     });
  5155     });
  4057 
  5156 
  4058     // Side effect imports
  5157     // Side effect imports
  4059 
  5158 
  4060     hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale);
  5159     hooks.lang = deprecate(
  4061     hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale);
  5160         'moment.lang is deprecated. Use moment.locale instead.',
       
  5161         getSetGlobalLocale
       
  5162     );
       
  5163     hooks.langData = deprecate(
       
  5164         'moment.langData is deprecated. Use moment.localeData instead.',
       
  5165         getLocale
       
  5166     );
  4062 
  5167 
  4063     var mathAbs = Math.abs;
  5168     var mathAbs = Math.abs;
  4064 
  5169 
  4065     function abs () {
  5170     function abs() {
  4066         var data           = this._data;
  5171         var data = this._data;
  4067 
  5172 
  4068         this._milliseconds = mathAbs(this._milliseconds);
  5173         this._milliseconds = mathAbs(this._milliseconds);
  4069         this._days         = mathAbs(this._days);
  5174         this._days = mathAbs(this._days);
  4070         this._months       = mathAbs(this._months);
  5175         this._months = mathAbs(this._months);
  4071 
  5176 
  4072         data.milliseconds  = mathAbs(data.milliseconds);
  5177         data.milliseconds = mathAbs(data.milliseconds);
  4073         data.seconds       = mathAbs(data.seconds);
  5178         data.seconds = mathAbs(data.seconds);
  4074         data.minutes       = mathAbs(data.minutes);
  5179         data.minutes = mathAbs(data.minutes);
  4075         data.hours         = mathAbs(data.hours);
  5180         data.hours = mathAbs(data.hours);
  4076         data.months        = mathAbs(data.months);
  5181         data.months = mathAbs(data.months);
  4077         data.years         = mathAbs(data.years);
  5182         data.years = mathAbs(data.years);
  4078 
  5183 
  4079         return this;
  5184         return this;
  4080     }
  5185     }
  4081 
  5186 
  4082     function addSubtract$1 (duration, input, value, direction) {
  5187     function addSubtract$1(duration, input, value, direction) {
  4083         var other = createDuration(input, value);
  5188         var other = createDuration(input, value);
  4084 
  5189 
  4085         duration._milliseconds += direction * other._milliseconds;
  5190         duration._milliseconds += direction * other._milliseconds;
  4086         duration._days         += direction * other._days;
  5191         duration._days += direction * other._days;
  4087         duration._months       += direction * other._months;
  5192         duration._months += direction * other._months;
  4088 
  5193 
  4089         return duration._bubble();
  5194         return duration._bubble();
  4090     }
  5195     }
  4091 
  5196 
  4092     // supports only 2.0-style add(1, 's') or add(duration)
  5197     // supports only 2.0-style add(1, 's') or add(duration)
  4093     function add$1 (input, value) {
  5198     function add$1(input, value) {
  4094         return addSubtract$1(this, input, value, 1);
  5199         return addSubtract$1(this, input, value, 1);
  4095     }
  5200     }
  4096 
  5201 
  4097     // supports only 2.0-style subtract(1, 's') or subtract(duration)
  5202     // supports only 2.0-style subtract(1, 's') or subtract(duration)
  4098     function subtract$1 (input, value) {
  5203     function subtract$1(input, value) {
  4099         return addSubtract$1(this, input, value, -1);
  5204         return addSubtract$1(this, input, value, -1);
  4100     }
  5205     }
  4101 
  5206 
  4102     function absCeil (number) {
  5207     function absCeil(number) {
  4103         if (number < 0) {
  5208         if (number < 0) {
  4104             return Math.floor(number);
  5209             return Math.floor(number);
  4105         } else {
  5210         } else {
  4106             return Math.ceil(number);
  5211             return Math.ceil(number);
  4107         }
  5212         }
  4108     }
  5213     }
  4109 
  5214 
  4110     function bubble () {
  5215     function bubble() {
  4111         var milliseconds = this._milliseconds;
  5216         var milliseconds = this._milliseconds,
  4112         var days         = this._days;
  5217             days = this._days,
  4113         var months       = this._months;
  5218             months = this._months,
  4114         var data         = this._data;
  5219             data = this._data,
  4115         var seconds, minutes, hours, years, monthsFromDays;
  5220             seconds,
       
  5221             minutes,
       
  5222             hours,
       
  5223             years,
       
  5224             monthsFromDays;
  4116 
  5225 
  4117         // if we have a mix of positive and negative values, bubble down first
  5226         // if we have a mix of positive and negative values, bubble down first
  4118         // check: https://github.com/moment/moment/issues/2166
  5227         // check: https://github.com/moment/moment/issues/2166
  4119         if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  5228         if (
  4120                 (milliseconds <= 0 && days <= 0 && months <= 0))) {
  5229             !(
       
  5230                 (milliseconds >= 0 && days >= 0 && months >= 0) ||
       
  5231                 (milliseconds <= 0 && days <= 0 && months <= 0)
       
  5232             )
       
  5233         ) {
  4121             milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  5234             milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  4122             days = 0;
  5235             days = 0;
  4123             months = 0;
  5236             months = 0;
  4124         }
  5237         }
  4125 
  5238 
  4126         // The following code bubbles up values, see the tests for
  5239         // The following code bubbles up values, see the tests for
  4127         // examples of what that means.
  5240         // examples of what that means.
  4128         data.milliseconds = milliseconds % 1000;
  5241         data.milliseconds = milliseconds % 1000;
  4129 
  5242 
  4130         seconds           = absFloor(milliseconds / 1000);
  5243         seconds = absFloor(milliseconds / 1000);
  4131         data.seconds      = seconds % 60;
  5244         data.seconds = seconds % 60;
  4132 
  5245 
  4133         minutes           = absFloor(seconds / 60);
  5246         minutes = absFloor(seconds / 60);
  4134         data.minutes      = minutes % 60;
  5247         data.minutes = minutes % 60;
  4135 
  5248 
  4136         hours             = absFloor(minutes / 60);
  5249         hours = absFloor(minutes / 60);
  4137         data.hours        = hours % 24;
  5250         data.hours = hours % 24;
  4138 
  5251 
  4139         days += absFloor(hours / 24);
  5252         days += absFloor(hours / 24);
  4140 
  5253 
  4141         // convert days to months
  5254         // convert days to months
  4142         monthsFromDays = absFloor(daysToMonths(days));
  5255         monthsFromDays = absFloor(daysToMonths(days));
  4145 
  5258 
  4146         // 12 months -> 1 year
  5259         // 12 months -> 1 year
  4147         years = absFloor(months / 12);
  5260         years = absFloor(months / 12);
  4148         months %= 12;
  5261         months %= 12;
  4149 
  5262 
  4150         data.days   = days;
  5263         data.days = days;
  4151         data.months = months;
  5264         data.months = months;
  4152         data.years  = years;
  5265         data.years = years;
  4153 
  5266 
  4154         return this;
  5267         return this;
  4155     }
  5268     }
  4156 
  5269 
  4157     function daysToMonths (days) {
  5270     function daysToMonths(days) {
  4158         // 400 years have 146097 days (taking into account leap year rules)
  5271         // 400 years have 146097 days (taking into account leap year rules)
  4159         // 400 years have 12 months === 4800
  5272         // 400 years have 12 months === 4800
  4160         return days * 4800 / 146097;
  5273         return (days * 4800) / 146097;
  4161     }
  5274     }
  4162 
  5275 
  4163     function monthsToDays (months) {
  5276     function monthsToDays(months) {
  4164         // the reverse of daysToMonths
  5277         // the reverse of daysToMonths
  4165         return months * 146097 / 4800;
  5278         return (months * 146097) / 4800;
  4166     }
  5279     }
  4167 
  5280 
  4168     function as (units) {
  5281     function as(units) {
  4169         if (!this.isValid()) {
  5282         if (!this.isValid()) {
  4170             return NaN;
  5283             return NaN;
  4171         }
  5284         }
  4172         var days;
  5285         var days,
  4173         var months;
  5286             months,
  4174         var milliseconds = this._milliseconds;
  5287             milliseconds = this._milliseconds;
  4175 
  5288 
  4176         units = normalizeUnits(units);
  5289         units = normalizeUnits(units);
  4177 
  5290 
  4178         if (units === 'month' || units === 'year') {
  5291         if (units === 'month' || units === 'quarter' || units === 'year') {
  4179             days   = this._days   + milliseconds / 864e5;
  5292             days = this._days + milliseconds / 864e5;
  4180             months = this._months + daysToMonths(days);
  5293             months = this._months + daysToMonths(days);
  4181             return units === 'month' ? months : months / 12;
  5294             switch (units) {
       
  5295                 case 'month':
       
  5296                     return months;
       
  5297                 case 'quarter':
       
  5298                     return months / 3;
       
  5299                 case 'year':
       
  5300                     return months / 12;
       
  5301             }
  4182         } else {
  5302         } else {
  4183             // handle milliseconds separately because of floating point math errors (issue #1867)
  5303             // handle milliseconds separately because of floating point math errors (issue #1867)
  4184             days = this._days + Math.round(monthsToDays(this._months));
  5304             days = this._days + Math.round(monthsToDays(this._months));
  4185             switch (units) {
  5305             switch (units) {
  4186                 case 'week'   : return days / 7     + milliseconds / 6048e5;
  5306                 case 'week':
  4187                 case 'day'    : return days         + milliseconds / 864e5;
  5307                     return days / 7 + milliseconds / 6048e5;
  4188                 case 'hour'   : return days * 24    + milliseconds / 36e5;
  5308                 case 'day':
  4189                 case 'minute' : return days * 1440  + milliseconds / 6e4;
  5309                     return days + milliseconds / 864e5;
  4190                 case 'second' : return days * 86400 + milliseconds / 1000;
  5310                 case 'hour':
       
  5311                     return days * 24 + milliseconds / 36e5;
       
  5312                 case 'minute':
       
  5313                     return days * 1440 + milliseconds / 6e4;
       
  5314                 case 'second':
       
  5315                     return days * 86400 + milliseconds / 1000;
  4191                 // Math.floor prevents floating point math errors here
  5316                 // Math.floor prevents floating point math errors here
  4192                 case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  5317                 case 'millisecond':
  4193                 default: throw new Error('Unknown unit ' + units);
  5318                     return Math.floor(days * 864e5) + milliseconds;
       
  5319                 default:
       
  5320                     throw new Error('Unknown unit ' + units);
  4194             }
  5321             }
  4195         }
  5322         }
  4196     }
  5323     }
  4197 
  5324 
  4198     // TODO: Use this.as('ms')?
  5325     // TODO: Use this.as('ms')?
  4199     function valueOf$1 () {
  5326     function valueOf$1() {
  4200         if (!this.isValid()) {
  5327         if (!this.isValid()) {
  4201             return NaN;
  5328             return NaN;
  4202         }
  5329         }
  4203         return (
  5330         return (
  4204             this._milliseconds +
  5331             this._milliseconds +
  4206             (this._months % 12) * 2592e6 +
  5333             (this._months % 12) * 2592e6 +
  4207             toInt(this._months / 12) * 31536e6
  5334             toInt(this._months / 12) * 31536e6
  4208         );
  5335         );
  4209     }
  5336     }
  4210 
  5337 
  4211     function makeAs (alias) {
  5338     function makeAs(alias) {
  4212         return function () {
  5339         return function () {
  4213             return this.as(alias);
  5340             return this.as(alias);
  4214         };
  5341         };
  4215     }
  5342     }
  4216 
  5343 
  4217     var asMilliseconds = makeAs('ms');
  5344     var asMilliseconds = makeAs('ms'),
  4218     var asSeconds      = makeAs('s');
  5345         asSeconds = makeAs('s'),
  4219     var asMinutes      = makeAs('m');
  5346         asMinutes = makeAs('m'),
  4220     var asHours        = makeAs('h');
  5347         asHours = makeAs('h'),
  4221     var asDays         = makeAs('d');
  5348         asDays = makeAs('d'),
  4222     var asWeeks        = makeAs('w');
  5349         asWeeks = makeAs('w'),
  4223     var asMonths       = makeAs('M');
  5350         asMonths = makeAs('M'),
  4224     var asYears        = makeAs('y');
  5351         asQuarters = makeAs('Q'),
  4225 
  5352         asYears = makeAs('y');
  4226     function clone$1 () {
  5353 
       
  5354     function clone$1() {
  4227         return createDuration(this);
  5355         return createDuration(this);
  4228     }
  5356     }
  4229 
  5357 
  4230     function get$2 (units) {
  5358     function get$2(units) {
  4231         units = normalizeUnits(units);
  5359         units = normalizeUnits(units);
  4232         return this.isValid() ? this[units + 's']() : NaN;
  5360         return this.isValid() ? this[units + 's']() : NaN;
  4233     }
  5361     }
  4234 
  5362 
  4235     function makeGetter(name) {
  5363     function makeGetter(name) {
  4236         return function () {
  5364         return function () {
  4237             return this.isValid() ? this._data[name] : NaN;
  5365             return this.isValid() ? this._data[name] : NaN;
  4238         };
  5366         };
  4239     }
  5367     }
  4240 
  5368 
  4241     var milliseconds = makeGetter('milliseconds');
  5369     var milliseconds = makeGetter('milliseconds'),
  4242     var seconds      = makeGetter('seconds');
  5370         seconds = makeGetter('seconds'),
  4243     var minutes      = makeGetter('minutes');
  5371         minutes = makeGetter('minutes'),
  4244     var hours        = makeGetter('hours');
  5372         hours = makeGetter('hours'),
  4245     var days         = makeGetter('days');
  5373         days = makeGetter('days'),
  4246     var months       = makeGetter('months');
  5374         months = makeGetter('months'),
  4247     var years        = makeGetter('years');
  5375         years = makeGetter('years');
  4248 
  5376 
  4249     function weeks () {
  5377     function weeks() {
  4250         return absFloor(this.days() / 7);
  5378         return absFloor(this.days() / 7);
  4251     }
  5379     }
  4252 
  5380 
  4253     var round = Math.round;
  5381     var round = Math.round,
  4254     var thresholds = {
  5382         thresholds = {
  4255         ss: 44,         // a few seconds to seconds
  5383             ss: 44, // a few seconds to seconds
  4256         s : 45,         // seconds to minute
  5384             s: 45, // seconds to minute
  4257         m : 45,         // minutes to hour
  5385             m: 45, // minutes to hour
  4258         h : 22,         // hours to day
  5386             h: 22, // hours to day
  4259         d : 26,         // days to month
  5387             d: 26, // days to month/week
  4260         M : 11          // months to year
  5388             w: null, // weeks to month
  4261     };
  5389             M: 11, // months to year
       
  5390         };
  4262 
  5391 
  4263     // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  5392     // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  4264     function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  5393     function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  4265         return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  5394         return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  4266     }
  5395     }
  4267 
  5396 
  4268     function relativeTime$1 (posNegDuration, withoutSuffix, locale) {
  5397     function relativeTime$1(posNegDuration, withoutSuffix, thresholds, locale) {
  4269         var duration = createDuration(posNegDuration).abs();
  5398         var duration = createDuration(posNegDuration).abs(),
  4270         var seconds  = round(duration.as('s'));
  5399             seconds = round(duration.as('s')),
  4271         var minutes  = round(duration.as('m'));
  5400             minutes = round(duration.as('m')),
  4272         var hours    = round(duration.as('h'));
  5401             hours = round(duration.as('h')),
  4273         var days     = round(duration.as('d'));
  5402             days = round(duration.as('d')),
  4274         var months   = round(duration.as('M'));
  5403             months = round(duration.as('M')),
  4275         var years    = round(duration.as('y'));
  5404             weeks = round(duration.as('w')),
  4276 
  5405             years = round(duration.as('y')),
  4277         var a = seconds <= thresholds.ss && ['s', seconds]  ||
  5406             a =
  4278                 seconds < thresholds.s   && ['ss', seconds] ||
  5407                 (seconds <= thresholds.ss && ['s', seconds]) ||
  4279                 minutes <= 1             && ['m']           ||
  5408                 (seconds < thresholds.s && ['ss', seconds]) ||
  4280                 minutes < thresholds.m   && ['mm', minutes] ||
  5409                 (minutes <= 1 && ['m']) ||
  4281                 hours   <= 1             && ['h']           ||
  5410                 (minutes < thresholds.m && ['mm', minutes]) ||
  4282                 hours   < thresholds.h   && ['hh', hours]   ||
  5411                 (hours <= 1 && ['h']) ||
  4283                 days    <= 1             && ['d']           ||
  5412                 (hours < thresholds.h && ['hh', hours]) ||
  4284                 days    < thresholds.d   && ['dd', days]    ||
  5413                 (days <= 1 && ['d']) ||
  4285                 months  <= 1             && ['M']           ||
  5414                 (days < thresholds.d && ['dd', days]);
  4286                 months  < thresholds.M   && ['MM', months]  ||
  5415 
  4287                 years   <= 1             && ['y']           || ['yy', years];
  5416         if (thresholds.w != null) {
       
  5417             a =
       
  5418                 a ||
       
  5419                 (weeks <= 1 && ['w']) ||
       
  5420                 (weeks < thresholds.w && ['ww', weeks]);
       
  5421         }
       
  5422         a = a ||
       
  5423             (months <= 1 && ['M']) ||
       
  5424             (months < thresholds.M && ['MM', months]) ||
       
  5425             (years <= 1 && ['y']) || ['yy', years];
  4288 
  5426 
  4289         a[2] = withoutSuffix;
  5427         a[2] = withoutSuffix;
  4290         a[3] = +posNegDuration > 0;
  5428         a[3] = +posNegDuration > 0;
  4291         a[4] = locale;
  5429         a[4] = locale;
  4292         return substituteTimeAgo.apply(null, a);
  5430         return substituteTimeAgo.apply(null, a);
  4293     }
  5431     }
  4294 
  5432 
  4295     // This function allows you to set the rounding function for relative time strings
  5433     // This function allows you to set the rounding function for relative time strings
  4296     function getSetRelativeTimeRounding (roundingFunction) {
  5434     function getSetRelativeTimeRounding(roundingFunction) {
  4297         if (roundingFunction === undefined) {
  5435         if (roundingFunction === undefined) {
  4298             return round;
  5436             return round;
  4299         }
  5437         }
  4300         if (typeof(roundingFunction) === 'function') {
  5438         if (typeof roundingFunction === 'function') {
  4301             round = roundingFunction;
  5439             round = roundingFunction;
  4302             return true;
  5440             return true;
  4303         }
  5441         }
  4304         return false;
  5442         return false;
  4305     }
  5443     }
  4306 
  5444 
  4307     // This function allows you to set a threshold for relative time strings
  5445     // This function allows you to set a threshold for relative time strings
  4308     function getSetRelativeTimeThreshold (threshold, limit) {
  5446     function getSetRelativeTimeThreshold(threshold, limit) {
  4309         if (thresholds[threshold] === undefined) {
  5447         if (thresholds[threshold] === undefined) {
  4310             return false;
  5448             return false;
  4311         }
  5449         }
  4312         if (limit === undefined) {
  5450         if (limit === undefined) {
  4313             return thresholds[threshold];
  5451             return thresholds[threshold];
  4317             thresholds.ss = limit - 1;
  5455             thresholds.ss = limit - 1;
  4318         }
  5456         }
  4319         return true;
  5457         return true;
  4320     }
  5458     }
  4321 
  5459 
  4322     function humanize (withSuffix) {
  5460     function humanize(argWithSuffix, argThresholds) {
  4323         if (!this.isValid()) {
  5461         if (!this.isValid()) {
  4324             return this.localeData().invalidDate();
  5462             return this.localeData().invalidDate();
  4325         }
  5463         }
  4326 
  5464 
  4327         var locale = this.localeData();
  5465         var withSuffix = false,
  4328         var output = relativeTime$1(this, !withSuffix, locale);
  5466             th = thresholds,
       
  5467             locale,
       
  5468             output;
       
  5469 
       
  5470         if (typeof argWithSuffix === 'object') {
       
  5471             argThresholds = argWithSuffix;
       
  5472             argWithSuffix = false;
       
  5473         }
       
  5474         if (typeof argWithSuffix === 'boolean') {
       
  5475             withSuffix = argWithSuffix;
       
  5476         }
       
  5477         if (typeof argThresholds === 'object') {
       
  5478             th = Object.assign({}, thresholds, argThresholds);
       
  5479             if (argThresholds.s != null && argThresholds.ss == null) {
       
  5480                 th.ss = argThresholds.s - 1;
       
  5481             }
       
  5482         }
       
  5483 
       
  5484         locale = this.localeData();
       
  5485         output = relativeTime$1(this, !withSuffix, th, locale);
  4329 
  5486 
  4330         if (withSuffix) {
  5487         if (withSuffix) {
  4331             output = locale.pastFuture(+this, output);
  5488             output = locale.pastFuture(+this, output);
  4332         }
  5489         }
  4333 
  5490 
  4335     }
  5492     }
  4336 
  5493 
  4337     var abs$1 = Math.abs;
  5494     var abs$1 = Math.abs;
  4338 
  5495 
  4339     function sign(x) {
  5496     function sign(x) {
  4340         return ((x > 0) - (x < 0)) || +x;
  5497         return (x > 0) - (x < 0) || +x;
  4341     }
  5498     }
  4342 
  5499 
  4343     function toISOString$1() {
  5500     function toISOString$1() {
  4344         // for ISO strings we do not use the normal bubbling rules:
  5501         // for ISO strings we do not use the normal bubbling rules:
  4345         //  * milliseconds bubble up until they become hours
  5502         //  * milliseconds bubble up until they become hours
  4350         // and also not between days and months (28-31 days per month)
  5507         // and also not between days and months (28-31 days per month)
  4351         if (!this.isValid()) {
  5508         if (!this.isValid()) {
  4352             return this.localeData().invalidDate();
  5509             return this.localeData().invalidDate();
  4353         }
  5510         }
  4354 
  5511 
  4355         var seconds = abs$1(this._milliseconds) / 1000;
  5512         var seconds = abs$1(this._milliseconds) / 1000,
  4356         var days         = abs$1(this._days);
  5513             days = abs$1(this._days),
  4357         var months       = abs$1(this._months);
  5514             months = abs$1(this._months),
  4358         var minutes, hours, years;
  5515             minutes,
  4359 
  5516             hours,
  4360         // 3600 seconds -> 60 minutes -> 1 hour
  5517             years,
  4361         minutes           = absFloor(seconds / 60);
  5518             s,
  4362         hours             = absFloor(minutes / 60);
  5519             total = this.asSeconds(),
  4363         seconds %= 60;
  5520             totalSign,
  4364         minutes %= 60;
  5521             ymSign,
  4365 
  5522             daysSign,
  4366         // 12 months -> 1 year
  5523             hmsSign;
  4367         years  = absFloor(months / 12);
       
  4368         months %= 12;
       
  4369 
       
  4370 
       
  4371         // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
       
  4372         var Y = years;
       
  4373         var M = months;
       
  4374         var D = days;
       
  4375         var h = hours;
       
  4376         var m = minutes;
       
  4377         var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
       
  4378         var total = this.asSeconds();
       
  4379 
  5524 
  4380         if (!total) {
  5525         if (!total) {
  4381             // this is the same as C#'s (Noda) and python (isodate)...
  5526             // this is the same as C#'s (Noda) and python (isodate)...
  4382             // but not other JS (goog.date)
  5527             // but not other JS (goog.date)
  4383             return 'P0D';
  5528             return 'P0D';
  4384         }
  5529         }
  4385 
  5530 
  4386         var totalSign = total < 0 ? '-' : '';
  5531         // 3600 seconds -> 60 minutes -> 1 hour
  4387         var ymSign = sign(this._months) !== sign(total) ? '-' : '';
  5532         minutes = absFloor(seconds / 60);
  4388         var daysSign = sign(this._days) !== sign(total) ? '-' : '';
  5533         hours = absFloor(minutes / 60);
  4389         var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
  5534         seconds %= 60;
  4390 
  5535         minutes %= 60;
  4391         return totalSign + 'P' +
  5536 
  4392             (Y ? ymSign + Y + 'Y' : '') +
  5537         // 12 months -> 1 year
  4393             (M ? ymSign + M + 'M' : '') +
  5538         years = absFloor(months / 12);
  4394             (D ? daysSign + D + 'D' : '') +
  5539         months %= 12;
  4395             ((h || m || s) ? 'T' : '') +
  5540 
  4396             (h ? hmsSign + h + 'H' : '') +
  5541         // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  4397             (m ? hmsSign + m + 'M' : '') +
  5542         s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
  4398             (s ? hmsSign + s + 'S' : '');
  5543 
       
  5544         totalSign = total < 0 ? '-' : '';
       
  5545         ymSign = sign(this._months) !== sign(total) ? '-' : '';
       
  5546         daysSign = sign(this._days) !== sign(total) ? '-' : '';
       
  5547         hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
       
  5548 
       
  5549         return (
       
  5550             totalSign +
       
  5551             'P' +
       
  5552             (years ? ymSign + years + 'Y' : '') +
       
  5553             (months ? ymSign + months + 'M' : '') +
       
  5554             (days ? daysSign + days + 'D' : '') +
       
  5555             (hours || minutes || seconds ? 'T' : '') +
       
  5556             (hours ? hmsSign + hours + 'H' : '') +
       
  5557             (minutes ? hmsSign + minutes + 'M' : '') +
       
  5558             (seconds ? hmsSign + s + 'S' : '')
       
  5559         );
  4399     }
  5560     }
  4400 
  5561 
  4401     var proto$2 = Duration.prototype;
  5562     var proto$2 = Duration.prototype;
  4402 
  5563 
  4403     proto$2.isValid        = isValid$1;
  5564     proto$2.isValid = isValid$1;
  4404     proto$2.abs            = abs;
  5565     proto$2.abs = abs;
  4405     proto$2.add            = add$1;
  5566     proto$2.add = add$1;
  4406     proto$2.subtract       = subtract$1;
  5567     proto$2.subtract = subtract$1;
  4407     proto$2.as             = as;
  5568     proto$2.as = as;
  4408     proto$2.asMilliseconds = asMilliseconds;
  5569     proto$2.asMilliseconds = asMilliseconds;
  4409     proto$2.asSeconds      = asSeconds;
  5570     proto$2.asSeconds = asSeconds;
  4410     proto$2.asMinutes      = asMinutes;
  5571     proto$2.asMinutes = asMinutes;
  4411     proto$2.asHours        = asHours;
  5572     proto$2.asHours = asHours;
  4412     proto$2.asDays         = asDays;
  5573     proto$2.asDays = asDays;
  4413     proto$2.asWeeks        = asWeeks;
  5574     proto$2.asWeeks = asWeeks;
  4414     proto$2.asMonths       = asMonths;
  5575     proto$2.asMonths = asMonths;
  4415     proto$2.asYears        = asYears;
  5576     proto$2.asQuarters = asQuarters;
  4416     proto$2.valueOf        = valueOf$1;
  5577     proto$2.asYears = asYears;
  4417     proto$2._bubble        = bubble;
  5578     proto$2.valueOf = valueOf$1;
  4418     proto$2.clone          = clone$1;
  5579     proto$2._bubble = bubble;
  4419     proto$2.get            = get$2;
  5580     proto$2.clone = clone$1;
  4420     proto$2.milliseconds   = milliseconds;
  5581     proto$2.get = get$2;
  4421     proto$2.seconds        = seconds;
  5582     proto$2.milliseconds = milliseconds;
  4422     proto$2.minutes        = minutes;
  5583     proto$2.seconds = seconds;
  4423     proto$2.hours          = hours;
  5584     proto$2.minutes = minutes;
  4424     proto$2.days           = days;
  5585     proto$2.hours = hours;
  4425     proto$2.weeks          = weeks;
  5586     proto$2.days = days;
  4426     proto$2.months         = months;
  5587     proto$2.weeks = weeks;
  4427     proto$2.years          = years;
  5588     proto$2.months = months;
  4428     proto$2.humanize       = humanize;
  5589     proto$2.years = years;
  4429     proto$2.toISOString    = toISOString$1;
  5590     proto$2.humanize = humanize;
  4430     proto$2.toString       = toISOString$1;
  5591     proto$2.toISOString = toISOString$1;
  4431     proto$2.toJSON         = toISOString$1;
  5592     proto$2.toString = toISOString$1;
  4432     proto$2.locale         = locale;
  5593     proto$2.toJSON = toISOString$1;
  4433     proto$2.localeData     = localeData;
  5594     proto$2.locale = locale;
  4434 
  5595     proto$2.localeData = localeData;
  4435     proto$2.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString$1);
  5596 
       
  5597     proto$2.toIsoString = deprecate(
       
  5598         'toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',
       
  5599         toISOString$1
       
  5600     );
  4436     proto$2.lang = lang;
  5601     proto$2.lang = lang;
  4437 
       
  4438     // Side effect imports
       
  4439 
  5602 
  4440     // FORMATTING
  5603     // FORMATTING
  4441 
  5604 
  4442     addFormatToken('X', 0, 0, 'unix');
  5605     addFormatToken('X', 0, 0, 'unix');
  4443     addFormatToken('x', 0, 0, 'valueOf');
  5606     addFormatToken('x', 0, 0, 'valueOf');
  4445     // PARSING
  5608     // PARSING
  4446 
  5609 
  4447     addRegexToken('x', matchSigned);
  5610     addRegexToken('x', matchSigned);
  4448     addRegexToken('X', matchTimestamp);
  5611     addRegexToken('X', matchTimestamp);
  4449     addParseToken('X', function (input, array, config) {
  5612     addParseToken('X', function (input, array, config) {
  4450         config._d = new Date(parseFloat(input, 10) * 1000);
  5613         config._d = new Date(parseFloat(input) * 1000);
  4451     });
  5614     });
  4452     addParseToken('x', function (input, array, config) {
  5615     addParseToken('x', function (input, array, config) {
  4453         config._d = new Date(toInt(input));
  5616         config._d = new Date(toInt(input));
  4454     });
  5617     });
  4455 
  5618 
  4456     // Side effect imports
  5619     //! moment.js
  4457 
  5620 
  4458 
  5621     hooks.version = '2.27.0';
  4459     hooks.version = '2.22.2';
       
  4460 
  5622 
  4461     setHookCallback(createLocal);
  5623     setHookCallback(createLocal);
  4462 
  5624 
  4463     hooks.fn                    = proto;
  5625     hooks.fn = proto;
  4464     hooks.min                   = min;
  5626     hooks.min = min;
  4465     hooks.max                   = max;
  5627     hooks.max = max;
  4466     hooks.now                   = now;
  5628     hooks.now = now;
  4467     hooks.utc                   = createUTC;
  5629     hooks.utc = createUTC;
  4468     hooks.unix                  = createUnix;
  5630     hooks.unix = createUnix;
  4469     hooks.months                = listMonths;
  5631     hooks.months = listMonths;
  4470     hooks.isDate                = isDate;
  5632     hooks.isDate = isDate;
  4471     hooks.locale                = getSetGlobalLocale;
  5633     hooks.locale = getSetGlobalLocale;
  4472     hooks.invalid               = createInvalid;
  5634     hooks.invalid = createInvalid;
  4473     hooks.duration              = createDuration;
  5635     hooks.duration = createDuration;
  4474     hooks.isMoment              = isMoment;
  5636     hooks.isMoment = isMoment;
  4475     hooks.weekdays              = listWeekdays;
  5637     hooks.weekdays = listWeekdays;
  4476     hooks.parseZone             = createInZone;
  5638     hooks.parseZone = createInZone;
  4477     hooks.localeData            = getLocale;
  5639     hooks.localeData = getLocale;
  4478     hooks.isDuration            = isDuration;
  5640     hooks.isDuration = isDuration;
  4479     hooks.monthsShort           = listMonthsShort;
  5641     hooks.monthsShort = listMonthsShort;
  4480     hooks.weekdaysMin           = listWeekdaysMin;
  5642     hooks.weekdaysMin = listWeekdaysMin;
  4481     hooks.defineLocale          = defineLocale;
  5643     hooks.defineLocale = defineLocale;
  4482     hooks.updateLocale          = updateLocale;
  5644     hooks.updateLocale = updateLocale;
  4483     hooks.locales               = listLocales;
  5645     hooks.locales = listLocales;
  4484     hooks.weekdaysShort         = listWeekdaysShort;
  5646     hooks.weekdaysShort = listWeekdaysShort;
  4485     hooks.normalizeUnits        = normalizeUnits;
  5647     hooks.normalizeUnits = normalizeUnits;
  4486     hooks.relativeTimeRounding  = getSetRelativeTimeRounding;
  5648     hooks.relativeTimeRounding = getSetRelativeTimeRounding;
  4487     hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  5649     hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  4488     hooks.calendarFormat        = getCalendarFormat;
  5650     hooks.calendarFormat = getCalendarFormat;
  4489     hooks.prototype             = proto;
  5651     hooks.prototype = proto;
  4490 
  5652 
  4491     // currently HTML5 input type only supports 24-hour formats
  5653     // currently HTML5 input type only supports 24-hour formats
  4492     hooks.HTML5_FMT = {
  5654     hooks.HTML5_FMT = {
  4493         DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm',             // <input type="datetime-local" />
  5655         DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
  4494         DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss',  // <input type="datetime-local" step="1" />
  5656         DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
  4495         DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS',   // <input type="datetime-local" step="0.001" />
  5657         DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
  4496         DATE: 'YYYY-MM-DD',                             // <input type="date" />
  5658         DATE: 'YYYY-MM-DD', // <input type="date" />
  4497         TIME: 'HH:mm',                                  // <input type="time" />
  5659         TIME: 'HH:mm', // <input type="time" />
  4498         TIME_SECONDS: 'HH:mm:ss',                       // <input type="time" step="1" />
  5660         TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
  4499         TIME_MS: 'HH:mm:ss.SSS',                        // <input type="time" step="0.001" />
  5661         TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
  4500         WEEK: 'YYYY-[W]WW',                             // <input type="week" />
  5662         WEEK: 'GGGG-[W]WW', // <input type="week" />
  4501         MONTH: 'YYYY-MM'                                // <input type="month" />
  5663         MONTH: 'YYYY-MM', // <input type="month" />
  4502     };
  5664     };
  4503 
  5665 
  4504     return hooks;
  5666     return hooks;
  4505 
  5667 
  4506 })));
  5668 })));