3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
7 (function (undefined) {
8 /************************************
10 ************************************/
14 // the global-scope this is NOT the global object in Node.js
15 globalScope = (typeof global !== 'undefined' && (typeof window === 'undefined' || window === global.window)) ? global : this,
18 hasOwnProperty = Object.prototype.hasOwnProperty,
29 // internal storage for locale config files
32 // extra moment internal properties (plugins register props here)
33 momentProperties = [],
36 hasModule = (typeof module !== 'undefined' && module && module.exports),
38 // ASP.NET json date format regex
39 aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
40 aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
42 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
43 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
44 isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
47 formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|x|X|zz?|ZZ?|.)/g,
48 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
50 // parsing token regexes
51 parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
52 parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
53 parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
54 parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
55 parseTokenDigits = /\d+/, // nonzero number of digits
56 parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic.
57 parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
58 parseTokenT = /T/i, // T (ISO separator)
59 parseTokenOffsetMs = /[\+\-]?\d+/, // 1234567890123
60 parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
62 //strict parsing regexes
63 parseTokenOneDigit = /\d/, // 0 - 9
64 parseTokenTwoDigits = /\d\d/, // 00 - 99
65 parseTokenThreeDigits = /\d{3}/, // 000 - 999
66 parseTokenFourDigits = /\d{4}/, // 0000 - 9999
67 parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
68 parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
71 // 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)
72 isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
74 isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
77 ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
78 ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
79 ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
80 ['GGGG-[W]WW', /\d{4}-W\d{2}/],
81 ['YYYY-DDD', /\d{4}-\d{3}/]
84 // iso time formats and regexes
86 ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
87 ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
88 ['HH:mm', /(T| )\d\d:\d\d/],
92 // timezone chunker '+10:00' > ['10', '00'] or '-1530' > ['-', '15', '30']
93 parseTimezoneChunker = /([\+\-]|\d\d)/gi,
95 // getter and setter names
96 proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
97 unitMillisecondFactors = {
127 dayofyear : 'dayOfYear',
128 isoweekday : 'isoWeekday',
130 weekyear : 'weekYear',
131 isoweekyear : 'isoWeekYear'
134 // format function strings
135 formatFunctions = {},
137 // default relative time thresholds
138 relativeTimeThresholds = {
139 s: 45, // seconds to minute
140 m: 45, // minutes to hour
141 h: 22, // hours to day
142 d: 26, // days to month
143 M: 11 // months to year
146 // tokens to ordinalize and pad
147 ordinalizeTokens = 'DDD w W M D d'.split(' '),
148 paddedTokens = 'M D H h m s w W'.split(' '),
150 formatTokenFunctions = {
152 return this.month() + 1;
154 MMM : function (format) {
155 return this.localeData().monthsShort(this, format);
157 MMMM : function (format) {
158 return this.localeData().months(this, format);
164 return this.dayOfYear();
169 dd : function (format) {
170 return this.localeData().weekdaysMin(this, format);
172 ddd : function (format) {
173 return this.localeData().weekdaysShort(this, format);
175 dddd : function (format) {
176 return this.localeData().weekdays(this, format);
182 return this.isoWeek();
185 return leftZeroFill(this.year() % 100, 2);
188 return leftZeroFill(this.year(), 4);
190 YYYYY : function () {
191 return leftZeroFill(this.year(), 5);
193 YYYYYY : function () {
194 var y = this.year(), sign = y >= 0 ? '+' : '-';
195 return sign + leftZeroFill(Math.abs(y), 6);
198 return leftZeroFill(this.weekYear() % 100, 2);
201 return leftZeroFill(this.weekYear(), 4);
203 ggggg : function () {
204 return leftZeroFill(this.weekYear(), 5);
207 return leftZeroFill(this.isoWeekYear() % 100, 2);
210 return leftZeroFill(this.isoWeekYear(), 4);
212 GGGGG : function () {
213 return leftZeroFill(this.isoWeekYear(), 5);
216 return this.weekday();
219 return this.isoWeekday();
222 return this.localeData().meridiem(this.hours(), this.minutes(), true);
225 return this.localeData().meridiem(this.hours(), this.minutes(), false);
231 return this.hours() % 12 || 12;
234 return this.minutes();
237 return this.seconds();
240 return toInt(this.milliseconds() / 100);
243 return leftZeroFill(toInt(this.milliseconds() / 10), 2);
246 return leftZeroFill(this.milliseconds(), 3);
249 return leftZeroFill(this.milliseconds(), 3);
252 var a = this.utcOffset(),
258 return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);
261 var a = this.utcOffset(),
267 return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
270 return this.zoneAbbr();
273 return this.zoneName();
276 return this.valueOf();
282 return this.quarter();
288 lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'],
290 updateInProgress = false;
292 // Pick the first defined of two or three arguments. dfl comes from
294 function dfl(a, b, c) {
295 switch (arguments.length) {
296 case 2: return a != null ? a : b;
297 case 3: return a != null ? a : b != null ? b : c;
298 default: throw new Error('Implement me');
302 function hasOwnProp(a, b) {
303 return hasOwnProperty.call(a, b);
306 function defaultParsingFlags() {
307 // We need to deep clone this object, and es5 standard is not very
317 invalidFormat : false,
318 userInvalidated : false,
323 function printMsg(msg) {
324 if (moment.suppressDeprecationWarnings === false &&
325 typeof console !== 'undefined' && console.warn) {
326 console.warn('Deprecation warning: ' + msg);
330 function deprecate(msg, fn) {
331 var firstTime = true;
332 return extend(function () {
337 return fn.apply(this, arguments);
341 function deprecateSimple(name, msg) {
342 if (!deprecations[name]) {
344 deprecations[name] = true;
348 function padToken(func, count) {
349 return function (a) {
350 return leftZeroFill(func.call(this, a), count);
353 function ordinalizeToken(func, period) {
354 return function (a) {
355 return this.localeData().ordinal(func.call(this, a), period);
359 function monthDiff(a, b) {
360 // difference in months
361 var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
362 // b is in (anchor - 1 month, anchor + 1 month)
363 anchor = a.clone().add(wholeMonthDiff, 'months'),
366 if (b - anchor < 0) {
367 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
368 // linear across the month
369 adjust = (b - anchor) / (anchor - anchor2);
371 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
372 // linear across the month
373 adjust = (b - anchor) / (anchor2 - anchor);
376 return -(wholeMonthDiff + adjust);
379 while (ordinalizeTokens.length) {
380 i = ordinalizeTokens.pop();
381 formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
383 while (paddedTokens.length) {
384 i = paddedTokens.pop();
385 formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
387 formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
390 function meridiemFixWrap(locale, hour, meridiem) {
393 if (meridiem == null) {
397 if (locale.meridiemHour != null) {
398 return locale.meridiemHour(hour, meridiem);
399 } else if (locale.isPM != null) {
401 isPm = locale.isPM(meridiem);
402 if (isPm && hour < 12) {
405 if (!isPm && hour === 12) {
410 // thie is not supposed to happen
415 /************************************
417 ************************************/
422 // Moment prototype object
423 function Moment(config, skipOverflow) {
424 if (skipOverflow !== false) {
425 checkOverflow(config);
427 copyConfig(this, config);
428 this._d = new Date(+config._d);
429 // Prevent infinite loop in case updateOffset creates new moment
431 if (updateInProgress === false) {
432 updateInProgress = true;
433 moment.updateOffset(this);
434 updateInProgress = false;
438 // Duration Constructor
439 function Duration(duration) {
440 var normalizedInput = normalizeObjectUnits(duration),
441 years = normalizedInput.year || 0,
442 quarters = normalizedInput.quarter || 0,
443 months = normalizedInput.month || 0,
444 weeks = normalizedInput.week || 0,
445 days = normalizedInput.day || 0,
446 hours = normalizedInput.hour || 0,
447 minutes = normalizedInput.minute || 0,
448 seconds = normalizedInput.second || 0,
449 milliseconds = normalizedInput.millisecond || 0;
451 // representation for dateAddRemove
452 this._milliseconds = +milliseconds +
453 seconds * 1e3 + // 1000
454 minutes * 6e4 + // 1000 * 60
455 hours * 36e5; // 1000 * 60 * 60
456 // Because of dateAddRemove treats 24 hours as different from a
457 // day when working around DST, we need to store them separately
460 // It is impossible translate months into days without knowing
461 // which months you are are talking about, so we have to store
463 this._months = +months +
469 this._locale = moment.localeData();
474 /************************************
476 ************************************/
479 function extend(a, b) {
481 if (hasOwnProp(b, i)) {
486 if (hasOwnProp(b, 'toString')) {
487 a.toString = b.toString;
490 if (hasOwnProp(b, 'valueOf')) {
491 a.valueOf = b.valueOf;
497 function copyConfig(to, from) {
500 if (typeof from._isAMomentObject !== 'undefined') {
501 to._isAMomentObject = from._isAMomentObject;
503 if (typeof from._i !== 'undefined') {
506 if (typeof from._f !== 'undefined') {
509 if (typeof from._l !== 'undefined') {
512 if (typeof from._strict !== 'undefined') {
513 to._strict = from._strict;
515 if (typeof from._tzm !== 'undefined') {
518 if (typeof from._isUTC !== 'undefined') {
519 to._isUTC = from._isUTC;
521 if (typeof from._offset !== 'undefined') {
522 to._offset = from._offset;
524 if (typeof from._pf !== 'undefined') {
527 if (typeof from._locale !== 'undefined') {
528 to._locale = from._locale;
531 if (momentProperties.length > 0) {
532 for (i in momentProperties) {
533 prop = momentProperties[i];
535 if (typeof val !== 'undefined') {
544 function absRound(number) {
546 return Math.ceil(number);
548 return Math.floor(number);
552 // left zero fill a number
553 // see http://jsperf.com/left-zero-filling for performance comparison
554 function leftZeroFill(number, targetLength, forceSign) {
555 var output = '' + Math.abs(number),
558 while (output.length < targetLength) {
559 output = '0' + output;
561 return (sign ? (forceSign ? '+' : '') : '-') + output;
564 function positiveMomentsDifference(base, other) {
565 var res = {milliseconds: 0, months: 0};
567 res.months = other.month() - base.month() +
568 (other.year() - base.year()) * 12;
569 if (base.clone().add(res.months, 'M').isAfter(other)) {
573 res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
578 function momentsDifference(base, other) {
580 other = makeAs(other, base);
581 if (base.isBefore(other)) {
582 res = positiveMomentsDifference(base, other);
584 res = positiveMomentsDifference(other, base);
585 res.milliseconds = -res.milliseconds;
586 res.months = -res.months;
592 // TODO: remove 'name' arg after deprecation is removed
593 function createAdder(direction, name) {
594 return function (val, period) {
596 //invert the arguments, but complain about it
597 if (period !== null && !isNaN(+period)) {
598 deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
599 tmp = val; val = period; period = tmp;
602 val = typeof val === 'string' ? +val : val;
603 dur = moment.duration(val, period);
604 addOrSubtractDurationFromMoment(this, dur, direction);
609 function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {
610 var milliseconds = duration._milliseconds,
611 days = duration._days,
612 months = duration._months;
613 updateOffset = updateOffset == null ? true : updateOffset;
616 mom._d.setTime(+mom._d + milliseconds * isAdding);
619 rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);
622 rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);
625 moment.updateOffset(mom, days || months);
629 // check if is an array
630 function isArray(input) {
631 return Object.prototype.toString.call(input) === '[object Array]';
634 function isDate(input) {
635 return Object.prototype.toString.call(input) === '[object Date]' ||
636 input instanceof Date;
639 // compare two arrays, return the number of differences
640 function compareArrays(array1, array2, dontConvert) {
641 var len = Math.min(array1.length, array2.length),
642 lengthDiff = Math.abs(array1.length - array2.length),
645 for (i = 0; i < len; i++) {
646 if ((dontConvert && array1[i] !== array2[i]) ||
647 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
651 return diffs + lengthDiff;
654 function normalizeUnits(units) {
656 var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
657 units = unitAliases[units] || camelFunctions[lowered] || lowered;
662 function normalizeObjectUnits(inputObject) {
663 var normalizedInput = {},
667 for (prop in inputObject) {
668 if (hasOwnProp(inputObject, prop)) {
669 normalizedProp = normalizeUnits(prop);
670 if (normalizedProp) {
671 normalizedInput[normalizedProp] = inputObject[prop];
676 return normalizedInput;
679 function makeList(field) {
682 if (field.indexOf('week') === 0) {
686 else if (field.indexOf('month') === 0) {
694 moment[field] = function (format, index) {
696 method = moment._locale[field],
699 if (typeof format === 'number') {
704 getter = function (i) {
705 var m = moment().utc().set(setter, i);
706 return method.call(moment._locale, m, format || '');
710 return getter(index);
713 for (i = 0; i < count; i++) {
714 results.push(getter(i));
721 function toInt(argumentForCoercion) {
722 var coercedNumber = +argumentForCoercion,
725 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
726 if (coercedNumber >= 0) {
727 value = Math.floor(coercedNumber);
729 value = Math.ceil(coercedNumber);
736 function daysInMonth(year, month) {
737 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
740 function weeksInYear(year, dow, doy) {
741 return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;
744 function daysInYear(year) {
745 return isLeapYear(year) ? 366 : 365;
748 function isLeapYear(year) {
749 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
752 function checkOverflow(m) {
754 if (m._a && m._pf.overflow === -2) {
756 m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
757 m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
758 m._a[HOUR] < 0 || m._a[HOUR] > 24 ||
759 (m._a[HOUR] === 24 && (m._a[MINUTE] !== 0 ||
760 m._a[SECOND] !== 0 ||
761 m._a[MILLISECOND] !== 0)) ? HOUR :
762 m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
763 m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
764 m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
767 if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
771 m._pf.overflow = overflow;
775 function isValid(m) {
776 if (m._isValid == null) {
777 m._isValid = !isNaN(m._d.getTime()) &&
778 m._pf.overflow < 0 &&
780 !m._pf.invalidMonth &&
782 !m._pf.invalidFormat &&
783 !m._pf.userInvalidated;
786 m._isValid = m._isValid &&
787 m._pf.charsLeftOver === 0 &&
788 m._pf.unusedTokens.length === 0 &&
789 m._pf.bigHour === undefined;
795 function normalizeLocale(key) {
796 return key ? key.toLowerCase().replace('_', '-') : key;
799 // pick the locale from the array
800 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
801 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
802 function chooseLocale(names) {
803 var i = 0, j, next, locale, split;
805 while (i < names.length) {
806 split = normalizeLocale(names[i]).split('-');
808 next = normalizeLocale(names[i + 1]);
809 next = next ? next.split('-') : null;
811 locale = loadLocale(split.slice(0, j).join('-'));
815 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
816 //the next array item is better than a shallower substring of this one
826 function loadLocale(name) {
827 var oldLocale = null;
828 if (!locales[name] && hasModule) {
830 oldLocale = moment.locale();
831 require('./locale/' + name);
832 // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales
833 moment.locale(oldLocale);
836 return locales[name];
839 // Return a moment from input, that is local/utc/utcOffset equivalent to
841 function makeAs(input, model) {
845 diff = (moment.isMoment(input) || isDate(input) ?
846 +input : +moment(input)) - (+res);
847 // Use low-level api, because this fn is low-level api.
848 res._d.setTime(+res._d + diff);
849 moment.updateOffset(res, false);
852 return moment(input).local();
856 /************************************
858 ************************************/
861 extend(Locale.prototype, {
863 set : function (config) {
867 if (typeof prop === 'function') {
870 this['_' + i] = prop;
873 // Lenient ordinal parsing accepts just a number in addition to
874 // number + (possibly) stuff coming from _ordinalParseLenient.
875 this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + /\d{1,2}/.source);
878 _months : 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
879 months : function (m) {
880 return this._months[m.month()];
883 _monthsShort : 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
884 monthsShort : function (m) {
885 return this._monthsShort[m.month()];
888 monthsParse : function (monthName, format, strict) {
891 if (!this._monthsParse) {
892 this._monthsParse = [];
893 this._longMonthsParse = [];
894 this._shortMonthsParse = [];
897 for (i = 0; i < 12; i++) {
898 // make the regex if we don't have it already
899 mom = moment.utc([2000, i]);
900 if (strict && !this._longMonthsParse[i]) {
901 this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
902 this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
904 if (!strict && !this._monthsParse[i]) {
905 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
906 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
909 if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
911 } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
913 } else if (!strict && this._monthsParse[i].test(monthName)) {
919 _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
920 weekdays : function (m) {
921 return this._weekdays[m.day()];
924 _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
925 weekdaysShort : function (m) {
926 return this._weekdaysShort[m.day()];
929 _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
930 weekdaysMin : function (m) {
931 return this._weekdaysMin[m.day()];
934 weekdaysParse : function (weekdayName) {
937 if (!this._weekdaysParse) {
938 this._weekdaysParse = [];
941 for (i = 0; i < 7; i++) {
942 // make the regex if we don't have it already
943 if (!this._weekdaysParse[i]) {
944 mom = moment([2000, 1]).day(i);
945 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
946 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
949 if (this._weekdaysParse[i].test(weekdayName)) {
960 LLL : 'MMMM D, YYYY LT',
961 LLLL : 'dddd, MMMM D, YYYY LT'
963 longDateFormat : function (key) {
964 var output = this._longDateFormat[key];
965 if (!output && this._longDateFormat[key.toUpperCase()]) {
966 output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
969 this._longDateFormat[key] = output;
974 isPM : function (input) {
975 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
976 // Using charAt should be more compatible.
977 return ((input + '').toLowerCase().charAt(0) === 'p');
980 _meridiemParse : /[ap]\.?m?\.?/i,
981 meridiem : function (hours, minutes, isLower) {
983 return isLower ? 'pm' : 'PM';
985 return isLower ? 'am' : 'AM';
991 sameDay : '[Today at] LT',
992 nextDay : '[Tomorrow at] LT',
993 nextWeek : 'dddd [at] LT',
994 lastDay : '[Yesterday at] LT',
995 lastWeek : '[Last] dddd [at] LT',
998 calendar : function (key, mom, now) {
999 var output = this._calendar[key];
1000 return typeof output === 'function' ? output.apply(mom, [now]) : output;
1006 s : 'a few seconds',
1019 relativeTime : function (number, withoutSuffix, string, isFuture) {
1020 var output = this._relativeTime[string];
1021 return (typeof output === 'function') ?
1022 output(number, withoutSuffix, string, isFuture) :
1023 output.replace(/%d/i, number);
1026 pastFuture : function (diff, output) {
1027 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
1028 return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
1031 ordinal : function (number) {
1032 return this._ordinal.replace('%d', number);
1035 _ordinalParse : /\d{1,2}/,
1037 preparse : function (string) {
1041 postformat : function (string) {
1045 week : function (mom) {
1046 return weekOfYear(mom, this._week.dow, this._week.doy).week;
1050 dow : 0, // Sunday is the first day of the week.
1051 doy : 6 // The week that contains Jan 1st is the first week of the year.
1054 firstDayOfWeek : function () {
1055 return this._week.dow;
1058 firstDayOfYear : function () {
1059 return this._week.doy;
1062 _invalidDate: 'Invalid date',
1063 invalidDate: function () {
1064 return this._invalidDate;
1068 /************************************
1070 ************************************/
1073 function removeFormattingTokens(input) {
1074 if (input.match(/\[[\s\S]/)) {
1075 return input.replace(/^\[|\]$/g, '');
1077 return input.replace(/\\/g, '');
1080 function makeFormatFunction(format) {
1081 var array = format.match(formattingTokens), i, length;
1083 for (i = 0, length = array.length; i < length; i++) {
1084 if (formatTokenFunctions[array[i]]) {
1085 array[i] = formatTokenFunctions[array[i]];
1087 array[i] = removeFormattingTokens(array[i]);
1091 return function (mom) {
1093 for (i = 0; i < length; i++) {
1094 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
1100 // format date using native date object
1101 function formatMoment(m, format) {
1103 return m.localeData().invalidDate();
1106 format = expandFormat(format, m.localeData());
1108 if (!formatFunctions[format]) {
1109 formatFunctions[format] = makeFormatFunction(format);
1112 return formatFunctions[format](m);
1115 function expandFormat(format, locale) {
1118 function replaceLongDateFormatTokens(input) {
1119 return locale.longDateFormat(input) || input;
1122 localFormattingTokens.lastIndex = 0;
1123 while (i >= 0 && localFormattingTokens.test(format)) {
1124 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
1125 localFormattingTokens.lastIndex = 0;
1133 /************************************
1135 ************************************/
1138 // get the regex to find the next token
1139 function getParseRegexForToken(token, config) {
1140 var a, strict = config._strict;
1143 return parseTokenOneDigit;
1145 return parseTokenThreeDigits;
1149 return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
1153 return parseTokenSignedNumber;
1158 return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
1161 return parseTokenOneDigit;
1166 return parseTokenTwoDigits;
1171 return parseTokenThreeDigits;
1175 return parseTokenOneToThreeDigits;
1181 return parseTokenWord;
1184 return config._locale._meridiemParse;
1186 return parseTokenOffsetMs;
1188 return parseTokenTimestampMs;
1191 return parseTokenTimezone;
1195 return parseTokenDigits;
1207 return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
1219 return parseTokenOneOrTwoDigits;
1221 return strict ? config._locale._ordinalParse : config._locale._ordinalParseLenient;
1223 a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), 'i'));
1228 function utcOffsetFromString(string) {
1229 string = string || '';
1230 var possibleTzMatches = (string.match(parseTokenTimezone) || []),
1231 tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
1232 parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
1233 minutes = +(parts[1] * 60) + toInt(parts[2]);
1235 return parts[0] === '+' ? minutes : -minutes;
1238 // function to convert string input to date
1239 function addTimeToArrayFromToken(token, input, config) {
1240 var a, datePartArray = config._a;
1245 if (input != null) {
1246 datePartArray[MONTH] = (toInt(input) - 1) * 3;
1250 case 'M' : // fall through to MM
1252 if (input != null) {
1253 datePartArray[MONTH] = toInt(input) - 1;
1256 case 'MMM' : // fall through to MMMM
1258 a = config._locale.monthsParse(input, token, config._strict);
1259 // if we didn't find a month name, mark the date as invalid.
1261 datePartArray[MONTH] = a;
1263 config._pf.invalidMonth = input;
1267 case 'D' : // fall through to DD
1269 if (input != null) {
1270 datePartArray[DATE] = toInt(input);
1274 if (input != null) {
1275 datePartArray[DATE] = toInt(parseInt(
1276 input.match(/\d{1,2}/)[0], 10));
1280 case 'DDD' : // fall through to DDDD
1282 if (input != null) {
1283 config._dayOfYear = toInt(input);
1289 datePartArray[YEAR] = moment.parseTwoDigitYear(input);
1294 datePartArray[YEAR] = toInt(input);
1297 case 'a' : // fall through to A
1299 config._meridiem = input;
1300 // config._isPm = config._locale.isPM(input);
1303 case 'h' : // fall through to hh
1305 config._pf.bigHour = true;
1307 case 'H' : // fall through to HH
1309 datePartArray[HOUR] = toInt(input);
1312 case 'm' : // fall through to mm
1314 datePartArray[MINUTE] = toInt(input);
1317 case 's' : // fall through to ss
1319 datePartArray[SECOND] = toInt(input);
1326 datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
1328 // UNIX OFFSET (MILLISECONDS)
1330 config._d = new Date(toInt(input));
1332 // UNIX TIMESTAMP WITH MS
1334 config._d = new Date(parseFloat(input) * 1000);
1337 case 'Z' : // fall through to ZZ
1339 config._useUTC = true;
1340 config._tzm = utcOffsetFromString(input);
1346 a = config._locale.weekdaysParse(input);
1347 // if we didn't get a weekday name, mark the date as invalid
1349 config._w = config._w || {};
1352 config._pf.invalidWeekday = input;
1355 // WEEK, WEEK DAY - numeric
1363 token = token.substr(0, 1);
1368 token = token.substr(0, 2);
1370 config._w = config._w || {};
1371 config._w[token] = toInt(input);
1376 config._w = config._w || {};
1377 config._w[token] = moment.parseTwoDigitYear(input);
1381 function dayOfYearFromWeekInfo(config) {
1382 var w, weekYear, week, weekday, dow, doy, temp;
1385 if (w.GG != null || w.W != null || w.E != null) {
1389 // TODO: We need to take the current isoWeekYear, but that depends on
1390 // how we interpret now (local, utc, fixed offset). So create
1391 // a now version of current config (take local/utc/offset flags, and
1393 weekYear = dfl(w.GG, config._a[YEAR], weekOfYear(moment(), 1, 4).year);
1395 weekday = dfl(w.E, 1);
1397 dow = config._locale._week.dow;
1398 doy = config._locale._week.doy;
1400 weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);
1404 // weekday -- low day numbers are considered next week
1406 if (weekday < dow) {
1409 } else if (w.e != null) {
1410 // local weekday -- counting starts from begining of week
1411 weekday = w.e + dow;
1413 // default to begining of week
1417 temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
1419 config._a[YEAR] = temp.year;
1420 config._dayOfYear = temp.dayOfYear;
1423 // convert an array to a date.
1424 // the array should mirror the parameters below
1425 // note: all values past the year are optional and will default to the lowest possible value.
1426 // [year, month, day , hour, minute, second, millisecond]
1427 function dateFromConfig(config) {
1428 var i, date, input = [], currentDate, yearToUse;
1434 currentDate = currentDateArray(config);
1436 //compute day of the year from weeks and weekdays
1437 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
1438 dayOfYearFromWeekInfo(config);
1441 //if the day of the year is set, figure out what it is
1442 if (config._dayOfYear) {
1443 yearToUse = dfl(config._a[YEAR], currentDate[YEAR]);
1445 if (config._dayOfYear > daysInYear(yearToUse)) {
1446 config._pf._overflowDayOfYear = true;
1449 date = makeUTCDate(yearToUse, 0, config._dayOfYear);
1450 config._a[MONTH] = date.getUTCMonth();
1451 config._a[DATE] = date.getUTCDate();
1454 // Default to current date.
1455 // * if no year, month, day of month are given, default to today
1456 // * if day of month is given, default month and year
1457 // * if month is given, default only year
1458 // * if year is given, don't default anything
1459 for (i = 0; i < 3 && config._a[i] == null; ++i) {
1460 config._a[i] = input[i] = currentDate[i];
1463 // Zero out whatever was not defaulted, including time
1464 for (; i < 7; i++) {
1465 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
1468 // Check for 24:00:00.000
1469 if (config._a[HOUR] === 24 &&
1470 config._a[MINUTE] === 0 &&
1471 config._a[SECOND] === 0 &&
1472 config._a[MILLISECOND] === 0) {
1473 config._nextDay = true;
1474 config._a[HOUR] = 0;
1477 config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
1478 // Apply timezone offset from input. The actual utcOffset can be changed
1480 if (config._tzm != null) {
1481 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
1484 if (config._nextDay) {
1485 config._a[HOUR] = 24;
1489 function dateFromObject(config) {
1490 var normalizedInput;
1496 normalizedInput = normalizeObjectUnits(config._i);
1498 normalizedInput.year,
1499 normalizedInput.month,
1500 normalizedInput.day || normalizedInput.date,
1501 normalizedInput.hour,
1502 normalizedInput.minute,
1503 normalizedInput.second,
1504 normalizedInput.millisecond
1507 dateFromConfig(config);
1510 function currentDateArray(config) {
1511 var now = new Date();
1512 if (config._useUTC) {
1514 now.getUTCFullYear(),
1519 return [now.getFullYear(), now.getMonth(), now.getDate()];
1523 // date from string and format string
1524 function makeDateFromStringAndFormat(config) {
1525 if (config._f === moment.ISO_8601) {
1531 config._pf.empty = true;
1533 // This array is used to make a Date, either with `new Date` or `Date.UTC`
1534 var string = '' + config._i,
1535 i, parsedInput, tokens, token, skipped,
1536 stringLength = string.length,
1537 totalParsedInputLength = 0;
1539 tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
1541 for (i = 0; i < tokens.length; i++) {
1543 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
1545 skipped = string.substr(0, string.indexOf(parsedInput));
1546 if (skipped.length > 0) {
1547 config._pf.unusedInput.push(skipped);
1549 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
1550 totalParsedInputLength += parsedInput.length;
1552 // don't parse if it's not a known token
1553 if (formatTokenFunctions[token]) {
1555 config._pf.empty = false;
1558 config._pf.unusedTokens.push(token);
1560 addTimeToArrayFromToken(token, parsedInput, config);
1562 else if (config._strict && !parsedInput) {
1563 config._pf.unusedTokens.push(token);
1567 // add remaining unparsed input length to the string
1568 config._pf.charsLeftOver = stringLength - totalParsedInputLength;
1569 if (string.length > 0) {
1570 config._pf.unusedInput.push(string);
1573 // clear _12h flag if hour is <= 12
1574 if (config._pf.bigHour === true && config._a[HOUR] <= 12) {
1575 config._pf.bigHour = undefined;
1578 config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR],
1580 dateFromConfig(config);
1581 checkOverflow(config);
1584 function unescapeFormat(s) {
1585 return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
1586 return p1 || p2 || p3 || p4;
1590 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
1591 function regexpEscape(s) {
1592 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
1595 // date from string and array of format strings
1596 function makeDateFromStringAndArray(config) {
1604 if (config._f.length === 0) {
1605 config._pf.invalidFormat = true;
1606 config._d = new Date(NaN);
1610 for (i = 0; i < config._f.length; i++) {
1612 tempConfig = copyConfig({}, config);
1613 if (config._useUTC != null) {
1614 tempConfig._useUTC = config._useUTC;
1616 tempConfig._pf = defaultParsingFlags();
1617 tempConfig._f = config._f[i];
1618 makeDateFromStringAndFormat(tempConfig);
1620 if (!isValid(tempConfig)) {
1624 // if there is any input that was not parsed add a penalty for that format
1625 currentScore += tempConfig._pf.charsLeftOver;
1628 currentScore += tempConfig._pf.unusedTokens.length * 10;
1630 tempConfig._pf.score = currentScore;
1632 if (scoreToBeat == null || currentScore < scoreToBeat) {
1633 scoreToBeat = currentScore;
1634 bestMoment = tempConfig;
1638 extend(config, bestMoment || tempConfig);
1641 // date from iso format
1642 function parseISO(config) {
1645 match = isoRegex.exec(string);
1648 config._pf.iso = true;
1649 for (i = 0, l = isoDates.length; i < l; i++) {
1650 if (isoDates[i][1].exec(string)) {
1651 // match[5] should be 'T' or undefined
1652 config._f = isoDates[i][0] + (match[6] || ' ');
1656 for (i = 0, l = isoTimes.length; i < l; i++) {
1657 if (isoTimes[i][1].exec(string)) {
1658 config._f += isoTimes[i][0];
1662 if (string.match(parseTokenTimezone)) {
1665 makeDateFromStringAndFormat(config);
1667 config._isValid = false;
1671 // date from iso format or fallback
1672 function makeDateFromString(config) {
1674 if (config._isValid === false) {
1675 delete config._isValid;
1676 moment.createFromInputFallback(config);
1680 function map(arr, fn) {
1682 for (i = 0; i < arr.length; ++i) {
1683 res.push(fn(arr[i], i));
1688 function makeDateFromInput(config) {
1689 var input = config._i, matched;
1690 if (input === undefined) {
1691 config._d = new Date();
1692 } else if (isDate(input)) {
1693 config._d = new Date(+input);
1694 } else if ((matched = aspNetJsonRegex.exec(input)) !== null) {
1695 config._d = new Date(+matched[1]);
1696 } else if (typeof input === 'string') {
1697 makeDateFromString(config);
1698 } else if (isArray(input)) {
1699 config._a = map(input.slice(0), function (obj) {
1700 return parseInt(obj, 10);
1702 dateFromConfig(config);
1703 } else if (typeof(input) === 'object') {
1704 dateFromObject(config);
1705 } else if (typeof(input) === 'number') {
1706 // from milliseconds
1707 config._d = new Date(input);
1709 moment.createFromInputFallback(config);
1713 function makeDate(y, m, d, h, M, s, ms) {
1714 //can't just apply() to create a date:
1715 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
1716 var date = new Date(y, m, d, h, M, s, ms);
1718 //the date constructor doesn't accept years < 1970
1720 date.setFullYear(y);
1725 function makeUTCDate(y) {
1726 var date = new Date(Date.UTC.apply(null, arguments));
1728 date.setUTCFullYear(y);
1733 function parseWeekday(input, locale) {
1734 if (typeof input === 'string') {
1735 if (!isNaN(input)) {
1736 input = parseInt(input, 10);
1739 input = locale.weekdaysParse(input);
1740 if (typeof input !== 'number') {
1748 /************************************
1750 ************************************/
1753 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
1754 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
1755 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
1758 function relativeTime(posNegDuration, withoutSuffix, locale) {
1759 var duration = moment.duration(posNegDuration).abs(),
1760 seconds = round(duration.as('s')),
1761 minutes = round(duration.as('m')),
1762 hours = round(duration.as('h')),
1763 days = round(duration.as('d')),
1764 months = round(duration.as('M')),
1765 years = round(duration.as('y')),
1767 args = seconds < relativeTimeThresholds.s && ['s', seconds] ||
1768 minutes === 1 && ['m'] ||
1769 minutes < relativeTimeThresholds.m && ['mm', minutes] ||
1770 hours === 1 && ['h'] ||
1771 hours < relativeTimeThresholds.h && ['hh', hours] ||
1772 days === 1 && ['d'] ||
1773 days < relativeTimeThresholds.d && ['dd', days] ||
1774 months === 1 && ['M'] ||
1775 months < relativeTimeThresholds.M && ['MM', months] ||
1776 years === 1 && ['y'] || ['yy', years];
1778 args[2] = withoutSuffix;
1779 args[3] = +posNegDuration > 0;
1781 return substituteTimeAgo.apply({}, args);
1785 /************************************
1787 ************************************/
1790 // firstDayOfWeek 0 = sun, 6 = sat
1791 // the day of the week that starts the week
1792 // (usually sunday or monday)
1793 // firstDayOfWeekOfYear 0 = sun, 6 = sat
1794 // the first week is the week that contains the first
1795 // of this day of the week
1796 // (eg. ISO weeks use thursday (4))
1797 function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
1798 var end = firstDayOfWeekOfYear - firstDayOfWeek,
1799 daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
1803 if (daysToDayOfWeek > end) {
1804 daysToDayOfWeek -= 7;
1807 if (daysToDayOfWeek < end - 7) {
1808 daysToDayOfWeek += 7;
1811 adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');
1813 week: Math.ceil(adjustedMoment.dayOfYear() / 7),
1814 year: adjustedMoment.year()
1818 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1819 function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
1820 var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
1822 d = d === 0 ? 7 : d;
1823 weekday = weekday != null ? weekday : firstDayOfWeek;
1824 daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
1825 dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
1828 year: dayOfYear > 0 ? year : year - 1,
1829 dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
1833 /************************************
1835 ************************************/
1837 function makeMoment(config) {
1838 var input = config._i,
1842 config._locale = config._locale || moment.localeData(config._l);
1844 if (input === null || (format === undefined && input === '')) {
1845 return moment.invalid({nullInput: true});
1848 if (typeof input === 'string') {
1849 config._i = input = config._locale.preparse(input);
1852 if (moment.isMoment(input)) {
1853 return new Moment(input, true);
1854 } else if (format) {
1855 if (isArray(format)) {
1856 makeDateFromStringAndArray(config);
1858 makeDateFromStringAndFormat(config);
1861 makeDateFromInput(config);
1864 res = new Moment(config);
1866 // Adding is smart enough around DST
1868 res._nextDay = undefined;
1874 moment = function (input, format, locale, strict) {
1877 if (typeof(locale) === 'boolean') {
1881 // object construction must be done this way.
1882 // https://github.com/moment/moment/issues/1423
1884 c._isAMomentObject = true;
1890 c._pf = defaultParsingFlags();
1892 return makeMoment(c);
1895 moment.suppressDeprecationWarnings = false;
1897 moment.createFromInputFallback = deprecate(
1898 'moment construction falls back to js Date. This is ' +
1899 'discouraged and will be removed in upcoming major ' +
1900 'release. Please refer to ' +
1901 'https://github.com/moment/moment/issues/1407 for more info.',
1903 config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
1907 // Pick a moment m from moments so that m[fn](other) is true for all
1908 // other. This relies on the function fn to be transitive.
1910 // moments should either be an array of moment objects or an array, whose
1911 // first element is an array of moment objects.
1912 function pickBy(fn, moments) {
1914 if (moments.length === 1 && isArray(moments[0])) {
1915 moments = moments[0];
1917 if (!moments.length) {
1921 for (i = 1; i < moments.length; ++i) {
1922 if (moments[i][fn](res)) {
1929 moment.min = function () {
1930 var args = [].slice.call(arguments, 0);
1932 return pickBy('isBefore', args);
1935 moment.max = function () {
1936 var args = [].slice.call(arguments, 0);
1938 return pickBy('isAfter', args);
1941 // creating with utc
1942 moment.utc = function (input, format, locale, strict) {
1945 if (typeof(locale) === 'boolean') {
1949 // object construction must be done this way.
1950 // https://github.com/moment/moment/issues/1423
1952 c._isAMomentObject = true;
1959 c._pf = defaultParsingFlags();
1961 return makeMoment(c).utc();
1964 // creating with unix timestamp (in seconds)
1965 moment.unix = function (input) {
1966 return moment(input * 1000);
1970 moment.duration = function (input, key) {
1971 var duration = input,
1972 // matching against regexp is expensive, do it on demand
1979 if (moment.isDuration(input)) {
1981 ms: input._milliseconds,
1985 } else if (typeof input === 'number') {
1988 duration[key] = input;
1990 duration.milliseconds = input;
1992 } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
1993 sign = (match[1] === '-') ? -1 : 1;
1996 d: toInt(match[DATE]) * sign,
1997 h: toInt(match[HOUR]) * sign,
1998 m: toInt(match[MINUTE]) * sign,
1999 s: toInt(match[SECOND]) * sign,
2000 ms: toInt(match[MILLISECOND]) * sign
2002 } else if (!!(match = isoDurationRegex.exec(input))) {
2003 sign = (match[1] === '-') ? -1 : 1;
2004 parseIso = function (inp) {
2005 // We'd normally use ~~inp for this, but unfortunately it also
2006 // converts floats to ints.
2007 // inp may be undefined, so careful calling replace on it.
2008 var res = inp && parseFloat(inp.replace(',', '.'));
2009 // apply sign while we're at it
2010 return (isNaN(res) ? 0 : res) * sign;
2013 y: parseIso(match[2]),
2014 M: parseIso(match[3]),
2015 d: parseIso(match[4]),
2016 h: parseIso(match[5]),
2017 m: parseIso(match[6]),
2018 s: parseIso(match[7]),
2019 w: parseIso(match[8])
2021 } else if (duration == null) {// checks for null or undefined
2023 } else if (typeof duration === 'object' &&
2024 ('from' in duration || 'to' in duration)) {
2025 diffRes = momentsDifference(moment(duration.from), moment(duration.to));
2028 duration.ms = diffRes.milliseconds;
2029 duration.M = diffRes.months;
2032 ret = new Duration(duration);
2034 if (moment.isDuration(input) && hasOwnProp(input, '_locale')) {
2035 ret._locale = input._locale;
2042 moment.version = VERSION;
2045 moment.defaultFormat = isoFormat;
2047 // constant that refers to the ISO standard
2048 moment.ISO_8601 = function () {};
2050 // Plugins that add properties should also add the key here (null value),
2051 // so we can properly clone ourselves.
2052 moment.momentProperties = momentProperties;
2054 // This function will be called whenever a moment is mutated.
2055 // It is intended to keep the offset in sync with the timezone.
2056 moment.updateOffset = function () {};
2058 // This function allows you to set a threshold for relative time strings
2059 moment.relativeTimeThreshold = function (threshold, limit) {
2060 if (relativeTimeThresholds[threshold] === undefined) {
2063 if (limit === undefined) {
2064 return relativeTimeThresholds[threshold];
2066 relativeTimeThresholds[threshold] = limit;
2070 moment.lang = deprecate(
2071 'moment.lang is deprecated. Use moment.locale instead.',
2072 function (key, value) {
2073 return moment.locale(key, value);
2077 // This function will load locale and then set the global locale. If
2078 // no arguments are passed in, it will simply return the current global
2080 moment.locale = function (key, values) {
2083 if (typeof(values) !== 'undefined') {
2084 data = moment.defineLocale(key, values);
2087 data = moment.localeData(key);
2091 moment.duration._locale = moment._locale = data;
2095 return moment._locale._abbr;
2098 moment.defineLocale = function (name, values) {
2099 if (values !== null) {
2101 if (!locales[name]) {
2102 locales[name] = new Locale();
2104 locales[name].set(values);
2106 // backwards compat for now: also set the locale
2107 moment.locale(name);
2109 return locales[name];
2111 // useful for testing
2112 delete locales[name];
2117 moment.langData = deprecate(
2118 'moment.langData is deprecated. Use moment.localeData instead.',
2120 return moment.localeData(key);
2124 // returns locale data
2125 moment.localeData = function (key) {
2128 if (key && key._locale && key._locale._abbr) {
2129 key = key._locale._abbr;
2133 return moment._locale;
2136 if (!isArray(key)) {
2137 //short-circuit everything else
2138 locale = loadLocale(key);
2145 return chooseLocale(key);
2148 // compare moment object
2149 moment.isMoment = function (obj) {
2150 return obj instanceof Moment ||
2151 (obj != null && hasOwnProp(obj, '_isAMomentObject'));
2154 // for typechecking Duration objects
2155 moment.isDuration = function (obj) {
2156 return obj instanceof Duration;
2159 for (i = lists.length - 1; i >= 0; --i) {
2163 moment.normalizeUnits = function (units) {
2164 return normalizeUnits(units);
2167 moment.invalid = function (flags) {
2168 var m = moment.utc(NaN);
2169 if (flags != null) {
2170 extend(m._pf, flags);
2173 m._pf.userInvalidated = true;
2179 moment.parseZone = function () {
2180 return moment.apply(null, arguments).parseZone();
2183 moment.parseTwoDigitYear = function (input) {
2184 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
2187 moment.isDate = isDate;
2189 /************************************
2191 ************************************/
2194 extend(moment.fn = Moment.prototype, {
2196 clone : function () {
2197 return moment(this);
2200 valueOf : function () {
2201 return +this._d - ((this._offset || 0) * 60000);
2204 unix : function () {
2205 return Math.floor(+this / 1000);
2208 toString : function () {
2209 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
2212 toDate : function () {
2213 return this._offset ? new Date(+this) : this._d;
2216 toISOString : function () {
2217 var m = moment(this).utc();
2218 if (0 < m.year() && m.year() <= 9999) {
2219 if ('function' === typeof Date.prototype.toISOString) {
2220 // native implementation is ~50x faster, use it when we can
2221 return this.toDate().toISOString();
2223 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2226 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2230 toArray : function () {
2243 isValid : function () {
2244 return isValid(this);
2247 isDSTShifted : function () {
2249 return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
2255 parsingFlags : function () {
2256 return extend({}, this._pf);
2259 invalidAt: function () {
2260 return this._pf.overflow;
2263 utc : function (keepLocalTime) {
2264 return this.utcOffset(0, keepLocalTime);
2267 local : function (keepLocalTime) {
2269 this.utcOffset(0, keepLocalTime);
2270 this._isUTC = false;
2272 if (keepLocalTime) {
2273 this.subtract(this._dateUtcOffset(), 'm');
2279 format : function (inputString) {
2280 var output = formatMoment(this, inputString || moment.defaultFormat);
2281 return this.localeData().postformat(output);
2284 add : createAdder(1, 'add'),
2286 subtract : createAdder(-1, 'subtract'),
2288 diff : function (input, units, asFloat) {
2289 var that = makeAs(input, this),
2290 zoneDiff = (that.utcOffset() - this.utcOffset()) * 6e4,
2291 anchor, diff, output, daysAdjust;
2293 units = normalizeUnits(units);
2295 if (units === 'year' || units === 'month' || units === 'quarter') {
2296 output = monthDiff(this, that);
2297 if (units === 'quarter') {
2298 output = output / 3;
2299 } else if (units === 'year') {
2300 output = output / 12;
2304 output = units === 'second' ? diff / 1e3 : // 1000
2305 units === 'minute' ? diff / 6e4 : // 1000 * 60
2306 units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
2307 units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
2308 units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
2311 return asFloat ? output : absRound(output);
2314 from : function (time, withoutSuffix) {
2315 return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
2318 fromNow : function (withoutSuffix) {
2319 return this.from(moment(), withoutSuffix);
2322 calendar : function (time) {
2323 // We want to compare the start of today, vs this.
2324 // Getting start-of-today depends on whether we're locat/utc/offset
2326 var now = time || moment(),
2327 sod = makeAs(now, this).startOf('day'),
2328 diff = this.diff(sod, 'days', true),
2329 format = diff < -6 ? 'sameElse' :
2330 diff < -1 ? 'lastWeek' :
2331 diff < 0 ? 'lastDay' :
2332 diff < 1 ? 'sameDay' :
2333 diff < 2 ? 'nextDay' :
2334 diff < 7 ? 'nextWeek' : 'sameElse';
2335 return this.format(this.localeData().calendar(format, this, moment(now)));
2338 isLeapYear : function () {
2339 return isLeapYear(this.year());
2342 isDST : function () {
2343 return (this.utcOffset() > this.clone().month(0).utcOffset() ||
2344 this.utcOffset() > this.clone().month(5).utcOffset());
2347 day : function (input) {
2348 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
2349 if (input != null) {
2350 input = parseWeekday(input, this.localeData());
2351 return this.add(input - day, 'd');
2357 month : makeAccessor('Month', true),
2359 startOf : function (units) {
2360 units = normalizeUnits(units);
2361 // the following switch intentionally omits break keywords
2362 // to utilize falling through the cases.
2383 this.milliseconds(0);
2387 // weeks are a special case
2388 if (units === 'week') {
2390 } else if (units === 'isoWeek') {
2394 // quarters are also special
2395 if (units === 'quarter') {
2396 this.month(Math.floor(this.month() / 3) * 3);
2402 endOf: function (units) {
2403 units = normalizeUnits(units);
2404 if (units === undefined || units === 'millisecond') {
2407 return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
2410 isAfter: function (input, units) {
2412 units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
2413 if (units === 'millisecond') {
2414 input = moment.isMoment(input) ? input : moment(input);
2415 return +this > +input;
2417 inputMs = moment.isMoment(input) ? +input : +moment(input);
2418 return inputMs < +this.clone().startOf(units);
2422 isBefore: function (input, units) {
2424 units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
2425 if (units === 'millisecond') {
2426 input = moment.isMoment(input) ? input : moment(input);
2427 return +this < +input;
2429 inputMs = moment.isMoment(input) ? +input : +moment(input);
2430 return +this.clone().endOf(units) < inputMs;
2434 isBetween: function (from, to, units) {
2435 return this.isAfter(from, units) && this.isBefore(to, units);
2438 isSame: function (input, units) {
2440 units = normalizeUnits(units || 'millisecond');
2441 if (units === 'millisecond') {
2442 input = moment.isMoment(input) ? input : moment(input);
2443 return +this === +input;
2445 inputMs = +moment(input);
2446 return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units));
2451 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
2453 other = moment.apply(null, arguments);
2454 return other < this ? this : other;
2459 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
2461 other = moment.apply(null, arguments);
2462 return other > this ? this : other;
2467 'moment().zone is deprecated, use moment().utcOffset instead. ' +
2468 'https://github.com/moment/moment/issues/1779',
2469 function (input, keepLocalTime) {
2470 if (input != null) {
2471 if (typeof input !== 'string') {
2475 this.utcOffset(input, keepLocalTime);
2479 return -this.utcOffset();
2484 // keepLocalTime = true means only change the timezone, without
2485 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
2486 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
2487 // +0200, so we adjust the time as needed, to be valid.
2489 // Keeping the time actually adds/subtracts (one hour)
2490 // from the actual represented time. That is why we call updateOffset
2491 // a second time. In case it wants us to change the offset again
2492 // _changeInProgress == true case, then we have to adjust, because
2493 // there is no such time in the given timezone.
2494 utcOffset : function (input, keepLocalTime) {
2495 var offset = this._offset || 0,
2497 if (input != null) {
2498 if (typeof input === 'string') {
2499 input = utcOffsetFromString(input);
2501 if (Math.abs(input) < 16) {
2504 if (!this._isUTC && keepLocalTime) {
2505 localAdjust = this._dateUtcOffset();
2507 this._offset = input;
2509 if (localAdjust != null) {
2510 this.add(localAdjust, 'm');
2512 if (offset !== input) {
2513 if (!keepLocalTime || this._changeInProgress) {
2514 addOrSubtractDurationFromMoment(this,
2515 moment.duration(input - offset, 'm'), 1, false);
2516 } else if (!this._changeInProgress) {
2517 this._changeInProgress = true;
2518 moment.updateOffset(this, true);
2519 this._changeInProgress = null;
2525 return this._isUTC ? offset : this._dateUtcOffset();
2529 isLocal : function () {
2530 return !this._isUTC;
2533 isUtcOffset : function () {
2537 isUtc : function () {
2538 return this._isUTC && this._offset === 0;
2541 zoneAbbr : function () {
2542 return this._isUTC ? 'UTC' : '';
2545 zoneName : function () {
2546 return this._isUTC ? 'Coordinated Universal Time' : '';
2549 parseZone : function () {
2551 this.utcOffset(this._tzm);
2552 } else if (typeof this._i === 'string') {
2553 this.utcOffset(utcOffsetFromString(this._i));
2558 hasAlignedHourOffset : function (input) {
2563 input = moment(input).utcOffset();
2566 return (this.utcOffset() - input) % 60 === 0;
2569 daysInMonth : function () {
2570 return daysInMonth(this.year(), this.month());
2573 dayOfYear : function (input) {
2574 var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
2575 return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
2578 quarter : function (input) {
2579 return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
2582 weekYear : function (input) {
2583 var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;
2584 return input == null ? year : this.add((input - year), 'y');
2587 isoWeekYear : function (input) {
2588 var year = weekOfYear(this, 1, 4).year;
2589 return input == null ? year : this.add((input - year), 'y');
2592 week : function (input) {
2593 var week = this.localeData().week(this);
2594 return input == null ? week : this.add((input - week) * 7, 'd');
2597 isoWeek : function (input) {
2598 var week = weekOfYear(this, 1, 4).week;
2599 return input == null ? week : this.add((input - week) * 7, 'd');
2602 weekday : function (input) {
2603 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
2604 return input == null ? weekday : this.add(input - weekday, 'd');
2607 isoWeekday : function (input) {
2608 // behaves the same as moment#day except
2609 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
2610 // as a setter, sunday should belong to the previous week.
2611 return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
2614 isoWeeksInYear : function () {
2615 return weeksInYear(this.year(), 1, 4);
2618 weeksInYear : function () {
2619 var weekInfo = this.localeData()._week;
2620 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
2623 get : function (units) {
2624 units = normalizeUnits(units);
2625 return this[units]();
2628 set : function (units, value) {
2630 if (typeof units === 'object') {
2631 for (unit in units) {
2632 this.set(unit, units[unit]);
2636 units = normalizeUnits(units);
2637 if (typeof this[units] === 'function') {
2644 // If passed a locale key, it will set the locale for this
2645 // instance. Otherwise, it will return the locale configuration
2646 // variables for this instance.
2647 locale : function (key) {
2650 if (key === undefined) {
2651 return this._locale._abbr;
2653 newLocaleData = moment.localeData(key);
2654 if (newLocaleData != null) {
2655 this._locale = newLocaleData;
2662 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
2664 if (key === undefined) {
2665 return this.localeData();
2667 return this.locale(key);
2672 localeData : function () {
2673 return this._locale;
2676 _dateUtcOffset : function () {
2677 // On Firefox.24 Date#getTimezoneOffset returns a floating point.
2678 // https://github.com/moment/moment/pull/1871
2679 return -Math.round(this._d.getTimezoneOffset() / 15) * 15;
2684 function rawMonthSetter(mom, value) {
2687 // TODO: Move this out of here!
2688 if (typeof value === 'string') {
2689 value = mom.localeData().monthsParse(value);
2690 // TODO: Another silent failure?
2691 if (typeof value !== 'number') {
2696 dayOfMonth = Math.min(mom.date(),
2697 daysInMonth(mom.year(), value));
2698 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
2702 function rawGetter(mom, unit) {
2703 return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
2706 function rawSetter(mom, unit, value) {
2707 if (unit === 'Month') {
2708 return rawMonthSetter(mom, value);
2710 return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
2714 function makeAccessor(unit, keepTime) {
2715 return function (value) {
2716 if (value != null) {
2717 rawSetter(this, unit, value);
2718 moment.updateOffset(this, keepTime);
2721 return rawGetter(this, unit);
2726 moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);
2727 moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);
2728 moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);
2729 // Setting the hour should keep the time, because the user explicitly
2730 // specified which hour he wants. So trying to maintain the same hour (in
2731 // a new timezone) makes sense. Adding/subtracting hours does not follow
2733 moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);
2734 // moment.fn.month is defined separately
2735 moment.fn.date = makeAccessor('Date', true);
2736 moment.fn.dates = deprecate('dates accessor is deprecated. Use date instead.', makeAccessor('Date', true));
2737 moment.fn.year = makeAccessor('FullYear', true);
2738 moment.fn.years = deprecate('years accessor is deprecated. Use year instead.', makeAccessor('FullYear', true));
2740 // add plural methods
2741 moment.fn.days = moment.fn.day;
2742 moment.fn.months = moment.fn.month;
2743 moment.fn.weeks = moment.fn.week;
2744 moment.fn.isoWeeks = moment.fn.isoWeek;
2745 moment.fn.quarters = moment.fn.quarter;
2747 // add aliased format methods
2748 moment.fn.toJSON = moment.fn.toISOString;
2750 // alias isUtc for dev-friendliness
2751 moment.fn.isUTC = moment.fn.isUtc;
2753 /************************************
2755 ************************************/
2758 function daysToYears (days) {
2759 // 400 years have 146097 days (taking into account leap year rules)
2760 return days * 400 / 146097;
2763 function yearsToDays (years) {
2764 // years * 365 + absRound(years / 4) -
2765 // absRound(years / 100) + absRound(years / 400);
2766 return years * 146097 / 400;
2769 extend(moment.duration.fn = Duration.prototype, {
2771 _bubble : function () {
2772 var milliseconds = this._milliseconds,
2774 months = this._months,
2776 seconds, minutes, hours, years = 0;
2778 // The following code bubbles up values, see the tests for
2779 // examples of what that means.
2780 data.milliseconds = milliseconds % 1000;
2782 seconds = absRound(milliseconds / 1000);
2783 data.seconds = seconds % 60;
2785 minutes = absRound(seconds / 60);
2786 data.minutes = minutes % 60;
2788 hours = absRound(minutes / 60);
2789 data.hours = hours % 24;
2791 days += absRound(hours / 24);
2793 // Accurately convert days to years, assume start from year 0.
2794 years = absRound(daysToYears(days));
2795 days -= absRound(yearsToDays(years));
2797 // 30 days to a month
2798 // TODO (iskren): Use anchor date (like 1st Jan) to compute this.
2799 months += absRound(days / 30);
2802 // 12 months -> 1 year
2803 years += absRound(months / 12);
2807 data.months = months;
2812 this._milliseconds = Math.abs(this._milliseconds);
2813 this._days = Math.abs(this._days);
2814 this._months = Math.abs(this._months);
2816 this._data.milliseconds = Math.abs(this._data.milliseconds);
2817 this._data.seconds = Math.abs(this._data.seconds);
2818 this._data.minutes = Math.abs(this._data.minutes);
2819 this._data.hours = Math.abs(this._data.hours);
2820 this._data.months = Math.abs(this._data.months);
2821 this._data.years = Math.abs(this._data.years);
2826 weeks : function () {
2827 return absRound(this.days() / 7);
2830 valueOf : function () {
2831 return this._milliseconds +
2832 this._days * 864e5 +
2833 (this._months % 12) * 2592e6 +
2834 toInt(this._months / 12) * 31536e6;
2837 humanize : function (withSuffix) {
2838 var output = relativeTime(this, !withSuffix, this.localeData());
2841 output = this.localeData().pastFuture(+this, output);
2844 return this.localeData().postformat(output);
2847 add : function (input, val) {
2848 // supports only 2.0-style add(1, 's') or add(moment)
2849 var dur = moment.duration(input, val);
2851 this._milliseconds += dur._milliseconds;
2852 this._days += dur._days;
2853 this._months += dur._months;
2860 subtract : function (input, val) {
2861 var dur = moment.duration(input, val);
2863 this._milliseconds -= dur._milliseconds;
2864 this._days -= dur._days;
2865 this._months -= dur._months;
2872 get : function (units) {
2873 units = normalizeUnits(units);
2874 return this[units.toLowerCase() + 's']();
2877 as : function (units) {
2879 units = normalizeUnits(units);
2881 if (units === 'month' || units === 'year') {
2882 days = this._days + this._milliseconds / 864e5;
2883 months = this._months + daysToYears(days) * 12;
2884 return units === 'month' ? months : months / 12;
2886 // handle milliseconds separately because of floating point math errors (issue #1867)
2887 days = this._days + Math.round(yearsToDays(this._months / 12));
2889 case 'week': return days / 7 + this._milliseconds / 6048e5;
2890 case 'day': return days + this._milliseconds / 864e5;
2891 case 'hour': return days * 24 + this._milliseconds / 36e5;
2892 case 'minute': return days * 24 * 60 + this._milliseconds / 6e4;
2893 case 'second': return days * 24 * 60 * 60 + this._milliseconds / 1000;
2894 // Math.floor prevents floating point math errors here
2895 case 'millisecond': return Math.floor(days * 24 * 60 * 60 * 1000) + this._milliseconds;
2896 default: throw new Error('Unknown unit ' + units);
2901 lang : moment.fn.lang,
2902 locale : moment.fn.locale,
2904 toIsoString : deprecate(
2905 'toIsoString() is deprecated. Please use toISOString() instead ' +
2906 '(notice the capitals)',
2908 return this.toISOString();
2912 toISOString : function () {
2913 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
2914 var years = Math.abs(this.years()),
2915 months = Math.abs(this.months()),
2916 days = Math.abs(this.days()),
2917 hours = Math.abs(this.hours()),
2918 minutes = Math.abs(this.minutes()),
2919 seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
2921 if (!this.asSeconds()) {
2922 // this is the same as C#'s (Noda) and python (isodate)...
2923 // but not other JS (goog.date)
2927 return (this.asSeconds() < 0 ? '-' : '') +
2929 (years ? years + 'Y' : '') +
2930 (months ? months + 'M' : '') +
2931 (days ? days + 'D' : '') +
2932 ((hours || minutes || seconds) ? 'T' : '') +
2933 (hours ? hours + 'H' : '') +
2934 (minutes ? minutes + 'M' : '') +
2935 (seconds ? seconds + 'S' : '');
2938 localeData : function () {
2939 return this._locale;
2942 toJSON : function () {
2943 return this.toISOString();
2947 moment.duration.fn.toString = moment.duration.fn.toISOString;
2949 function makeDurationGetter(name) {
2950 moment.duration.fn[name] = function () {
2951 return this._data[name];
2955 for (i in unitMillisecondFactors) {
2956 if (hasOwnProp(unitMillisecondFactors, i)) {
2957 makeDurationGetter(i.toLowerCase());
2961 moment.duration.fn.asMilliseconds = function () {
2962 return this.as('ms');
2964 moment.duration.fn.asSeconds = function () {
2965 return this.as('s');
2967 moment.duration.fn.asMinutes = function () {
2968 return this.as('m');
2970 moment.duration.fn.asHours = function () {
2971 return this.as('h');
2973 moment.duration.fn.asDays = function () {
2974 return this.as('d');
2976 moment.duration.fn.asWeeks = function () {
2977 return this.as('weeks');
2979 moment.duration.fn.asMonths = function () {
2980 return this.as('M');
2982 moment.duration.fn.asYears = function () {
2983 return this.as('y');
2986 /************************************
2988 ************************************/
2991 // Set default locale, other locale will inherit from English.
2992 moment.locale('en', {
2993 ordinalParse: /\d{1,2}(th|st|nd|rd)/,
2994 ordinal : function (number) {
2995 var b = number % 10,
2996 output = (toInt(number % 100 / 10) === 1) ? 'th' :
2999 (b === 3) ? 'rd' : 'th';
3000 return number + output;
3006 /************************************
3008 ************************************/
3010 function makeGlobal(shouldDeprecate) {
3011 /*global ender:false */
3012 if (typeof ender !== 'undefined') {
3015 oldGlobalMoment = globalScope.moment;
3016 if (shouldDeprecate) {
3017 globalScope.moment = deprecate(
3018 'Accessing Moment through the global scope is ' +
3019 'deprecated, and will be removed in an upcoming ' +
3023 globalScope.moment = moment;
3027 // CommonJS module is defined
3029 module.exports = moment;
3030 } else if (typeof define === 'function' && define.amd) {
3031 define(function (require, exports, module) {
3032 if (module.config && module.config() && module.config().noGlobal === true) {
3033 // release the global variable
3034 globalScope.moment = oldGlobalMoment;