3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
7 (function (undefined) {
9 /************************************
11 ************************************/
27 // internal storage for language config files
30 // moment internal properties
32 _isAMomentObject: null,
38 _offset : null, // optional. Combine with _isUTC
40 _lang : null // optional
44 hasModule = (typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'),
46 // ASP.NET json date format regex
47 aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
48 aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
50 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
51 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
52 isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
55 formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,
56 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
58 // parsing token regexes
59 parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
60 parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
61 parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
62 parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
63 parseTokenDigits = /\d+/, // nonzero number of digits
64 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.
65 parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
66 parseTokenT = /T/i, // T (ISO separator)
67 parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
69 //strict parsing regexes
70 parseTokenOneDigit = /\d/, // 0 - 9
71 parseTokenTwoDigits = /\d\d/, // 00 - 99
72 parseTokenThreeDigits = /\d{3}/, // 000 - 999
73 parseTokenFourDigits = /\d{4}/, // 0000 - 9999
74 parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
75 parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
78 // 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)
79 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)?)?$/,
81 isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
84 ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
85 ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
86 ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
87 ['GGGG-[W]WW', /\d{4}-W\d{2}/],
88 ['YYYY-DDD', /\d{4}-\d{3}/]
91 // iso time formats and regexes
93 ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d{1,3}/],
94 ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
95 ['HH:mm', /(T| )\d\d:\d\d/],
99 // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
100 parseTimezoneChunker = /([\+\-]|\d\d)/gi,
102 // getter and setter names
103 proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
104 unitMillisecondFactors = {
133 dayofyear : 'dayOfYear',
134 isoweekday : 'isoWeekday',
136 weekyear : 'weekYear',
137 isoweekyear : 'isoWeekYear'
140 // format function strings
141 formatFunctions = {},
143 // tokens to ordinalize and pad
144 ordinalizeTokens = 'DDD w W M D d'.split(' '),
145 paddedTokens = 'M D H h m s w W'.split(' '),
147 formatTokenFunctions = {
149 return this.month() + 1;
151 MMM : function (format) {
152 return this.lang().monthsShort(this, format);
154 MMMM : function (format) {
155 return this.lang().months(this, format);
161 return this.dayOfYear();
166 dd : function (format) {
167 return this.lang().weekdaysMin(this, format);
169 ddd : function (format) {
170 return this.lang().weekdaysShort(this, format);
172 dddd : function (format) {
173 return this.lang().weekdays(this, format);
179 return this.isoWeek();
182 return leftZeroFill(this.year() % 100, 2);
185 return leftZeroFill(this.year(), 4);
187 YYYYY : function () {
188 return leftZeroFill(this.year(), 5);
190 YYYYYY : function () {
191 var y = this.year(), sign = y >= 0 ? '+' : '-';
192 return sign + leftZeroFill(Math.abs(y), 6);
195 return leftZeroFill(this.weekYear() % 100, 2);
198 return leftZeroFill(this.weekYear(), 4);
200 ggggg : function () {
201 return leftZeroFill(this.weekYear(), 5);
204 return leftZeroFill(this.isoWeekYear() % 100, 2);
207 return leftZeroFill(this.isoWeekYear(), 4);
209 GGGGG : function () {
210 return leftZeroFill(this.isoWeekYear(), 5);
213 return this.weekday();
216 return this.isoWeekday();
219 return this.lang().meridiem(this.hours(), this.minutes(), true);
222 return this.lang().meridiem(this.hours(), this.minutes(), false);
228 return this.hours() % 12 || 12;
231 return this.minutes();
234 return this.seconds();
237 return toInt(this.milliseconds() / 100);
240 return leftZeroFill(toInt(this.milliseconds() / 10), 2);
243 return leftZeroFill(this.milliseconds(), 3);
246 return leftZeroFill(this.milliseconds(), 3);
249 var a = -this.zone(),
255 return b + leftZeroFill(toInt(a / 60), 2) + ":" + leftZeroFill(toInt(a) % 60, 2);
258 var a = -this.zone(),
264 return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
267 return this.zoneAbbr();
270 return this.zoneName();
276 return this.quarter();
280 lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
282 function defaultParsingFlags() {
283 // We need to deep clone this object, and es5 standard is not very
293 invalidFormat : false,
294 userInvalidated : false,
299 function padToken(func, count) {
300 return function (a) {
301 return leftZeroFill(func.call(this, a), count);
304 function ordinalizeToken(func, period) {
305 return function (a) {
306 return this.lang().ordinal(func.call(this, a), period);
310 while (ordinalizeTokens.length) {
311 i = ordinalizeTokens.pop();
312 formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
314 while (paddedTokens.length) {
315 i = paddedTokens.pop();
316 formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
318 formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
321 /************************************
323 ************************************/
325 function Language() {
329 // Moment prototype object
330 function Moment(config) {
331 checkOverflow(config);
332 extend(this, config);
335 // Duration Constructor
336 function Duration(duration) {
337 var normalizedInput = normalizeObjectUnits(duration),
338 years = normalizedInput.year || 0,
339 months = normalizedInput.month || 0,
340 weeks = normalizedInput.week || 0,
341 days = normalizedInput.day || 0,
342 hours = normalizedInput.hour || 0,
343 minutes = normalizedInput.minute || 0,
344 seconds = normalizedInput.second || 0,
345 milliseconds = normalizedInput.millisecond || 0;
347 // representation for dateAddRemove
348 this._milliseconds = +milliseconds +
349 seconds * 1e3 + // 1000
350 minutes * 6e4 + // 1000 * 60
351 hours * 36e5; // 1000 * 60 * 60
352 // Because of dateAddRemove treats 24 hours as different from a
353 // day when working around DST, we need to store them separately
356 // It is impossible translate months into days without knowing
357 // which months you are are talking about, so we have to store
359 this._months = +months +
367 /************************************
369 ************************************/
372 function extend(a, b) {
374 if (b.hasOwnProperty(i)) {
379 if (b.hasOwnProperty("toString")) {
380 a.toString = b.toString;
383 if (b.hasOwnProperty("valueOf")) {
384 a.valueOf = b.valueOf;
390 function cloneMoment(m) {
393 if (m.hasOwnProperty(i) && momentProperties.hasOwnProperty(i)) {
401 function absRound(number) {
403 return Math.ceil(number);
405 return Math.floor(number);
409 // left zero fill a number
410 // see http://jsperf.com/left-zero-filling for performance comparison
411 function leftZeroFill(number, targetLength, forceSign) {
412 var output = '' + Math.abs(number),
415 while (output.length < targetLength) {
416 output = '0' + output;
418 return (sign ? (forceSign ? '+' : '') : '-') + output;
421 // helper function for _.addTime and _.subtractTime
422 function addOrSubtractDurationFromMoment(mom, duration, isAdding, ignoreUpdateOffset) {
423 var milliseconds = duration._milliseconds,
424 days = duration._days,
425 months = duration._months,
430 mom._d.setTime(+mom._d + milliseconds * isAdding);
432 // store the minutes and hours so we can restore them
433 if (days || months) {
434 minutes = mom.minute();
438 mom.date(mom.date() + days * isAdding);
441 mom.month(mom.month() + months * isAdding);
443 if (milliseconds && !ignoreUpdateOffset) {
444 moment.updateOffset(mom);
446 // restore the minutes and hours after possibly changing dst
447 if (days || months) {
453 // check if is an array
454 function isArray(input) {
455 return Object.prototype.toString.call(input) === '[object Array]';
458 function isDate(input) {
459 return Object.prototype.toString.call(input) === '[object Date]' ||
460 input instanceof Date;
463 // compare two arrays, return the number of differences
464 function compareArrays(array1, array2, dontConvert) {
465 var len = Math.min(array1.length, array2.length),
466 lengthDiff = Math.abs(array1.length - array2.length),
469 for (i = 0; i < len; i++) {
470 if ((dontConvert && array1[i] !== array2[i]) ||
471 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
475 return diffs + lengthDiff;
478 function normalizeUnits(units) {
480 var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
481 units = unitAliases[units] || camelFunctions[lowered] || lowered;
486 function normalizeObjectUnits(inputObject) {
487 var normalizedInput = {},
491 for (prop in inputObject) {
492 if (inputObject.hasOwnProperty(prop)) {
493 normalizedProp = normalizeUnits(prop);
494 if (normalizedProp) {
495 normalizedInput[normalizedProp] = inputObject[prop];
500 return normalizedInput;
503 function makeList(field) {
506 if (field.indexOf('week') === 0) {
510 else if (field.indexOf('month') === 0) {
518 moment[field] = function (format, index) {
520 method = moment.fn._lang[field],
523 if (typeof format === 'number') {
528 getter = function (i) {
529 var m = moment().utc().set(setter, i);
530 return method.call(moment.fn._lang, m, format || '');
534 return getter(index);
537 for (i = 0; i < count; i++) {
538 results.push(getter(i));
545 function toInt(argumentForCoercion) {
546 var coercedNumber = +argumentForCoercion,
549 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
550 if (coercedNumber >= 0) {
551 value = Math.floor(coercedNumber);
553 value = Math.ceil(coercedNumber);
560 function daysInMonth(year, month) {
561 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
564 function daysInYear(year) {
565 return isLeapYear(year) ? 366 : 365;
568 function isLeapYear(year) {
569 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
572 function checkOverflow(m) {
574 if (m._a && m._pf.overflow === -2) {
576 m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
577 m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
578 m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
579 m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
580 m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
581 m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
584 if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
588 m._pf.overflow = overflow;
592 function isValid(m) {
593 if (m._isValid == null) {
594 m._isValid = !isNaN(m._d.getTime()) &&
595 m._pf.overflow < 0 &&
597 !m._pf.invalidMonth &&
599 !m._pf.invalidFormat &&
600 !m._pf.userInvalidated;
603 m._isValid = m._isValid &&
604 m._pf.charsLeftOver === 0 &&
605 m._pf.unusedTokens.length === 0;
611 function normalizeLanguage(key) {
612 return key ? key.toLowerCase().replace('_', '-') : key;
615 // Return a moment from input, that is local/utc/zone equivalent to model.
616 function makeAs(input, model) {
617 return model._isUTC ? moment(input).zone(model._offset || 0) :
618 moment(input).local();
621 /************************************
623 ************************************/
626 extend(Language.prototype, {
628 set : function (config) {
632 if (typeof prop === 'function') {
635 this['_' + i] = prop;
640 _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
641 months : function (m) {
642 return this._months[m.month()];
645 _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
646 monthsShort : function (m) {
647 return this._monthsShort[m.month()];
650 monthsParse : function (monthName) {
653 if (!this._monthsParse) {
654 this._monthsParse = [];
657 for (i = 0; i < 12; i++) {
658 // make the regex if we don't have it already
659 if (!this._monthsParse[i]) {
660 mom = moment.utc([2000, i]);
661 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
662 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
665 if (this._monthsParse[i].test(monthName)) {
671 _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
672 weekdays : function (m) {
673 return this._weekdays[m.day()];
676 _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
677 weekdaysShort : function (m) {
678 return this._weekdaysShort[m.day()];
681 _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
682 weekdaysMin : function (m) {
683 return this._weekdaysMin[m.day()];
686 weekdaysParse : function (weekdayName) {
689 if (!this._weekdaysParse) {
690 this._weekdaysParse = [];
693 for (i = 0; i < 7; i++) {
694 // make the regex if we don't have it already
695 if (!this._weekdaysParse[i]) {
696 mom = moment([2000, 1]).day(i);
697 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
698 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
701 if (this._weekdaysParse[i].test(weekdayName)) {
711 LLL : "MMMM D YYYY LT",
712 LLLL : "dddd, MMMM D YYYY LT"
714 longDateFormat : function (key) {
715 var output = this._longDateFormat[key];
716 if (!output && this._longDateFormat[key.toUpperCase()]) {
717 output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
720 this._longDateFormat[key] = output;
725 isPM : function (input) {
726 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
727 // Using charAt should be more compatible.
728 return ((input + '').toLowerCase().charAt(0) === 'p');
731 _meridiemParse : /[ap]\.?m?\.?/i,
732 meridiem : function (hours, minutes, isLower) {
734 return isLower ? 'pm' : 'PM';
736 return isLower ? 'am' : 'AM';
741 sameDay : '[Today at] LT',
742 nextDay : '[Tomorrow at] LT',
743 nextWeek : 'dddd [at] LT',
744 lastDay : '[Yesterday at] LT',
745 lastWeek : '[Last] dddd [at] LT',
748 calendar : function (key, mom) {
749 var output = this._calendar[key];
750 return typeof output === 'function' ? output.apply(mom) : output;
768 relativeTime : function (number, withoutSuffix, string, isFuture) {
769 var output = this._relativeTime[string];
770 return (typeof output === 'function') ?
771 output(number, withoutSuffix, string, isFuture) :
772 output.replace(/%d/i, number);
774 pastFuture : function (diff, output) {
775 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
776 return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
779 ordinal : function (number) {
780 return this._ordinal.replace("%d", number);
784 preparse : function (string) {
788 postformat : function (string) {
792 week : function (mom) {
793 return weekOfYear(mom, this._week.dow, this._week.doy).week;
797 dow : 0, // Sunday is the first day of the week.
798 doy : 6 // The week that contains Jan 1st is the first week of the year.
801 _invalidDate: 'Invalid date',
802 invalidDate: function () {
803 return this._invalidDate;
807 // Loads a language definition into the `languages` cache. The function
808 // takes a key and optionally values. If not in the browser and no values
809 // are provided, it will load the language file module. As a convenience,
810 // this function also returns the language values.
811 function loadLang(key, values) {
813 if (!languages[key]) {
814 languages[key] = new Language();
816 languages[key].set(values);
817 return languages[key];
820 // Remove a language from the `languages` cache. Mostly useful in tests.
821 function unloadLang(key) {
822 delete languages[key];
825 // Determines which language definition to use and returns it.
827 // With no parameters, it will return the global language. If you
828 // pass in a language key, such as 'en', it will return the
829 // definition for 'en', so long as 'en' has already been loaded using
831 function getLangDefinition(key) {
832 var i = 0, j, lang, next, split,
834 if (!languages[k] && hasModule) {
836 require('./lang/' + k);
843 return moment.fn._lang;
847 //short-circuit everything else
855 //pick the language from the array
856 //try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
857 //substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
858 while (i < key.length) {
859 split = normalizeLanguage(key[i]).split('-');
861 next = normalizeLanguage(key[i + 1]);
862 next = next ? next.split('-') : null;
864 lang = get(split.slice(0, j).join('-'));
868 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
869 //the next array item is better than a shallower substring of this one
876 return moment.fn._lang;
879 /************************************
881 ************************************/
884 function removeFormattingTokens(input) {
885 if (input.match(/\[[\s\S]/)) {
886 return input.replace(/^\[|\]$/g, "");
888 return input.replace(/\\/g, "");
891 function makeFormatFunction(format) {
892 var array = format.match(formattingTokens), i, length;
894 for (i = 0, length = array.length; i < length; i++) {
895 if (formatTokenFunctions[array[i]]) {
896 array[i] = formatTokenFunctions[array[i]];
898 array[i] = removeFormattingTokens(array[i]);
902 return function (mom) {
904 for (i = 0; i < length; i++) {
905 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
911 // format date using native date object
912 function formatMoment(m, format) {
915 return m.lang().invalidDate();
918 format = expandFormat(format, m.lang());
920 if (!formatFunctions[format]) {
921 formatFunctions[format] = makeFormatFunction(format);
924 return formatFunctions[format](m);
927 function expandFormat(format, lang) {
930 function replaceLongDateFormatTokens(input) {
931 return lang.longDateFormat(input) || input;
934 localFormattingTokens.lastIndex = 0;
935 while (i >= 0 && localFormattingTokens.test(format)) {
936 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
937 localFormattingTokens.lastIndex = 0;
945 /************************************
947 ************************************/
950 // get the regex to find the next token
951 function getParseRegexForToken(token, config) {
952 var a, strict = config._strict;
955 return parseTokenThreeDigits;
959 return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
963 return parseTokenSignedNumber;
968 return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
970 if (strict) { return parseTokenOneDigit; }
973 if (strict) { return parseTokenTwoDigits; }
976 if (strict) { return parseTokenThreeDigits; }
979 return parseTokenOneToThreeDigits;
985 return parseTokenWord;
988 return getLangDefinition(config._l)._meridiemParse;
990 return parseTokenTimestampMs;
993 return parseTokenTimezone;
997 return parseTokenDigits;
1009 return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
1021 return parseTokenOneOrTwoDigits;
1023 a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
1028 function timezoneMinutesFromString(string) {
1029 string = string || "";
1030 var possibleTzMatches = (string.match(parseTokenTimezone) || []),
1031 tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
1032 parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
1033 minutes = +(parts[1] * 60) + toInt(parts[2]);
1035 return parts[0] === '+' ? -minutes : minutes;
1038 // function to convert string input to date
1039 function addTimeToArrayFromToken(token, input, config) {
1040 var a, datePartArray = config._a;
1044 case 'M' : // fall through to MM
1046 if (input != null) {
1047 datePartArray[MONTH] = toInt(input) - 1;
1050 case 'MMM' : // fall through to MMMM
1052 a = getLangDefinition(config._l).monthsParse(input);
1053 // if we didn't find a month name, mark the date as invalid.
1055 datePartArray[MONTH] = a;
1057 config._pf.invalidMonth = input;
1061 case 'D' : // fall through to DD
1063 if (input != null) {
1064 datePartArray[DATE] = toInt(input);
1068 case 'DDD' : // fall through to DDDD
1070 if (input != null) {
1071 config._dayOfYear = toInt(input);
1077 datePartArray[YEAR] = toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
1082 datePartArray[YEAR] = toInt(input);
1085 case 'a' : // fall through to A
1087 config._isPm = getLangDefinition(config._l).isPM(input);
1090 case 'H' : // fall through to hh
1091 case 'HH' : // fall through to hh
1092 case 'h' : // fall through to hh
1094 datePartArray[HOUR] = toInt(input);
1097 case 'm' : // fall through to mm
1099 datePartArray[MINUTE] = toInt(input);
1102 case 's' : // fall through to ss
1104 datePartArray[SECOND] = toInt(input);
1111 datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
1113 // UNIX TIMESTAMP WITH MS
1115 config._d = new Date(parseFloat(input) * 1000);
1118 case 'Z' : // fall through to ZZ
1120 config._useUTC = true;
1121 config._tzm = timezoneMinutesFromString(input);
1133 token = token.substr(0, 1);
1140 token = token.substr(0, 2);
1142 config._w = config._w || {};
1143 config._w[token] = input;
1149 // convert an array to a date.
1150 // the array should mirror the parameters below
1151 // note: all values past the year are optional and will default to the lowest possible value.
1152 // [year, month, day , hour, minute, second, millisecond]
1153 function dateFromConfig(config) {
1154 var i, date, input = [], currentDate,
1155 yearToUse, fixYear, w, temp, lang, weekday, week;
1161 currentDate = currentDateArray(config);
1163 //compute day of the year from weeks and weekdays
1164 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
1165 fixYear = function (val) {
1166 var int_val = parseInt(val, 10);
1168 (val.length < 3 ? (int_val > 68 ? 1900 + int_val : 2000 + int_val) : int_val) :
1169 (config._a[YEAR] == null ? moment().weekYear() : config._a[YEAR]);
1173 if (w.GG != null || w.W != null || w.E != null) {
1174 temp = dayOfYearFromWeeks(fixYear(w.GG), w.W || 1, w.E, 4, 1);
1177 lang = getLangDefinition(config._l);
1178 weekday = w.d != null ? parseWeekday(w.d, lang) :
1179 (w.e != null ? parseInt(w.e, 10) + lang._week.dow : 0);
1181 week = parseInt(w.w, 10) || 1;
1183 //if we're parsing 'd', then the low day numbers may be next week
1184 if (w.d != null && weekday < lang._week.dow) {
1188 temp = dayOfYearFromWeeks(fixYear(w.gg), week, weekday, lang._week.doy, lang._week.dow);
1191 config._a[YEAR] = temp.year;
1192 config._dayOfYear = temp.dayOfYear;
1195 //if the day of the year is set, figure out what it is
1196 if (config._dayOfYear) {
1197 yearToUse = config._a[YEAR] == null ? currentDate[YEAR] : config._a[YEAR];
1199 if (config._dayOfYear > daysInYear(yearToUse)) {
1200 config._pf._overflowDayOfYear = true;
1203 date = makeUTCDate(yearToUse, 0, config._dayOfYear);
1204 config._a[MONTH] = date.getUTCMonth();
1205 config._a[DATE] = date.getUTCDate();
1208 // Default to current date.
1209 // * if no year, month, day of month are given, default to today
1210 // * if day of month is given, default month and year
1211 // * if month is given, default only year
1212 // * if year is given, don't default anything
1213 for (i = 0; i < 3 && config._a[i] == null; ++i) {
1214 config._a[i] = input[i] = currentDate[i];
1217 // Zero out whatever was not defaulted, including time
1218 for (; i < 7; i++) {
1219 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
1222 // add the offsets to the time to be parsed so that we can have a clean array for checking isValid
1223 input[HOUR] += toInt((config._tzm || 0) / 60);
1224 input[MINUTE] += toInt((config._tzm || 0) % 60);
1226 config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
1229 function dateFromObject(config) {
1230 var normalizedInput;
1236 normalizedInput = normalizeObjectUnits(config._i);
1238 normalizedInput.year,
1239 normalizedInput.month,
1240 normalizedInput.day,
1241 normalizedInput.hour,
1242 normalizedInput.minute,
1243 normalizedInput.second,
1244 normalizedInput.millisecond
1247 dateFromConfig(config);
1250 function currentDateArray(config) {
1251 var now = new Date();
1252 if (config._useUTC) {
1254 now.getUTCFullYear(),
1259 return [now.getFullYear(), now.getMonth(), now.getDate()];
1263 // date from string and format string
1264 function makeDateFromStringAndFormat(config) {
1267 config._pf.empty = true;
1269 // This array is used to make a Date, either with `new Date` or `Date.UTC`
1270 var lang = getLangDefinition(config._l),
1271 string = '' + config._i,
1272 i, parsedInput, tokens, token, skipped,
1273 stringLength = string.length,
1274 totalParsedInputLength = 0;
1276 tokens = expandFormat(config._f, lang).match(formattingTokens) || [];
1278 for (i = 0; i < tokens.length; i++) {
1280 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
1282 skipped = string.substr(0, string.indexOf(parsedInput));
1283 if (skipped.length > 0) {
1284 config._pf.unusedInput.push(skipped);
1286 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
1287 totalParsedInputLength += parsedInput.length;
1289 // don't parse if it's not a known token
1290 if (formatTokenFunctions[token]) {
1292 config._pf.empty = false;
1295 config._pf.unusedTokens.push(token);
1297 addTimeToArrayFromToken(token, parsedInput, config);
1299 else if (config._strict && !parsedInput) {
1300 config._pf.unusedTokens.push(token);
1304 // add remaining unparsed input length to the string
1305 config._pf.charsLeftOver = stringLength - totalParsedInputLength;
1306 if (string.length > 0) {
1307 config._pf.unusedInput.push(string);
1311 if (config._isPm && config._a[HOUR] < 12) {
1312 config._a[HOUR] += 12;
1314 // if is 12 am, change hours to 0
1315 if (config._isPm === false && config._a[HOUR] === 12) {
1316 config._a[HOUR] = 0;
1319 dateFromConfig(config);
1320 checkOverflow(config);
1323 function unescapeFormat(s) {
1324 return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
1325 return p1 || p2 || p3 || p4;
1329 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
1330 function regexpEscape(s) {
1331 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
1334 // date from string and array of format strings
1335 function makeDateFromStringAndArray(config) {
1343 if (config._f.length === 0) {
1344 config._pf.invalidFormat = true;
1345 config._d = new Date(NaN);
1349 for (i = 0; i < config._f.length; i++) {
1351 tempConfig = extend({}, config);
1352 tempConfig._pf = defaultParsingFlags();
1353 tempConfig._f = config._f[i];
1354 makeDateFromStringAndFormat(tempConfig);
1356 if (!isValid(tempConfig)) {
1360 // if there is any input that was not parsed add a penalty for that format
1361 currentScore += tempConfig._pf.charsLeftOver;
1364 currentScore += tempConfig._pf.unusedTokens.length * 10;
1366 tempConfig._pf.score = currentScore;
1368 if (scoreToBeat == null || currentScore < scoreToBeat) {
1369 scoreToBeat = currentScore;
1370 bestMoment = tempConfig;
1374 extend(config, bestMoment || tempConfig);
1377 // date from iso format
1378 function makeDateFromString(config) {
1381 match = isoRegex.exec(string);
1384 config._pf.iso = true;
1385 for (i = 0, l = isoDates.length; i < l; i++) {
1386 if (isoDates[i][1].exec(string)) {
1387 // match[5] should be "T" or undefined
1388 config._f = isoDates[i][0] + (match[6] || " ");
1392 for (i = 0, l = isoTimes.length; i < l; i++) {
1393 if (isoTimes[i][1].exec(string)) {
1394 config._f += isoTimes[i][0];
1398 if (string.match(parseTokenTimezone)) {
1401 makeDateFromStringAndFormat(config);
1404 config._d = new Date(string);
1408 function makeDateFromInput(config) {
1409 var input = config._i,
1410 matched = aspNetJsonRegex.exec(input);
1412 if (input === undefined) {
1413 config._d = new Date();
1414 } else if (matched) {
1415 config._d = new Date(+matched[1]);
1416 } else if (typeof input === 'string') {
1417 makeDateFromString(config);
1418 } else if (isArray(input)) {
1419 config._a = input.slice(0);
1420 dateFromConfig(config);
1421 } else if (isDate(input)) {
1422 config._d = new Date(+input);
1423 } else if (typeof(input) === 'object') {
1424 dateFromObject(config);
1426 config._d = new Date(input);
1430 function makeDate(y, m, d, h, M, s, ms) {
1431 //can't just apply() to create a date:
1432 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
1433 var date = new Date(y, m, d, h, M, s, ms);
1435 //the date constructor doesn't accept years < 1970
1437 date.setFullYear(y);
1442 function makeUTCDate(y) {
1443 var date = new Date(Date.UTC.apply(null, arguments));
1445 date.setUTCFullYear(y);
1450 function parseWeekday(input, language) {
1451 if (typeof input === 'string') {
1452 if (!isNaN(input)) {
1453 input = parseInt(input, 10);
1456 input = language.weekdaysParse(input);
1457 if (typeof input !== 'number') {
1465 /************************************
1467 ************************************/
1470 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
1471 function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) {
1472 return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
1475 function relativeTime(milliseconds, withoutSuffix, lang) {
1476 var seconds = round(Math.abs(milliseconds) / 1000),
1477 minutes = round(seconds / 60),
1478 hours = round(minutes / 60),
1479 days = round(hours / 24),
1480 years = round(days / 365),
1481 args = seconds < 45 && ['s', seconds] ||
1482 minutes === 1 && ['m'] ||
1483 minutes < 45 && ['mm', minutes] ||
1484 hours === 1 && ['h'] ||
1485 hours < 22 && ['hh', hours] ||
1486 days === 1 && ['d'] ||
1487 days <= 25 && ['dd', days] ||
1488 days <= 45 && ['M'] ||
1489 days < 345 && ['MM', round(days / 30)] ||
1490 years === 1 && ['y'] || ['yy', years];
1491 args[2] = withoutSuffix;
1492 args[3] = milliseconds > 0;
1494 return substituteTimeAgo.apply({}, args);
1498 /************************************
1500 ************************************/
1503 // firstDayOfWeek 0 = sun, 6 = sat
1504 // the day of the week that starts the week
1505 // (usually sunday or monday)
1506 // firstDayOfWeekOfYear 0 = sun, 6 = sat
1507 // the first week is the week that contains the first
1508 // of this day of the week
1509 // (eg. ISO weeks use thursday (4))
1510 function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
1511 var end = firstDayOfWeekOfYear - firstDayOfWeek,
1512 daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
1516 if (daysToDayOfWeek > end) {
1517 daysToDayOfWeek -= 7;
1520 if (daysToDayOfWeek < end - 7) {
1521 daysToDayOfWeek += 7;
1524 adjustedMoment = moment(mom).add('d', daysToDayOfWeek);
1526 week: Math.ceil(adjustedMoment.dayOfYear() / 7),
1527 year: adjustedMoment.year()
1531 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
1532 function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
1533 var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
1535 weekday = weekday != null ? weekday : firstDayOfWeek;
1536 daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
1537 dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
1540 year: dayOfYear > 0 ? year : year - 1,
1541 dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
1545 /************************************
1547 ************************************/
1549 function makeMoment(config) {
1550 var input = config._i,
1553 if (input === null) {
1554 return moment.invalid({nullInput: true});
1557 if (typeof input === 'string') {
1558 config._i = input = getLangDefinition().preparse(input);
1561 if (moment.isMoment(input)) {
1562 config = cloneMoment(input);
1564 config._d = new Date(+input._d);
1565 } else if (format) {
1566 if (isArray(format)) {
1567 makeDateFromStringAndArray(config);
1569 makeDateFromStringAndFormat(config);
1572 makeDateFromInput(config);
1575 return new Moment(config);
1578 moment = function (input, format, lang, strict) {
1581 if (typeof(lang) === "boolean") {
1585 // object construction must be done this way.
1586 // https://github.com/moment/moment/issues/1423
1588 c._isAMomentObject = true;
1594 c._pf = defaultParsingFlags();
1596 return makeMoment(c);
1599 // creating with utc
1600 moment.utc = function (input, format, lang, strict) {
1603 if (typeof(lang) === "boolean") {
1607 // object construction must be done this way.
1608 // https://github.com/moment/moment/issues/1423
1610 c._isAMomentObject = true;
1617 c._pf = defaultParsingFlags();
1619 return makeMoment(c).utc();
1622 // creating with unix timestamp (in seconds)
1623 moment.unix = function (input) {
1624 return moment(input * 1000);
1628 moment.duration = function (input, key) {
1629 var duration = input,
1630 // matching against regexp is expensive, do it on demand
1636 if (moment.isDuration(input)) {
1638 ms: input._milliseconds,
1642 } else if (typeof input === 'number') {
1645 duration[key] = input;
1647 duration.milliseconds = input;
1649 } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
1650 sign = (match[1] === "-") ? -1 : 1;
1653 d: toInt(match[DATE]) * sign,
1654 h: toInt(match[HOUR]) * sign,
1655 m: toInt(match[MINUTE]) * sign,
1656 s: toInt(match[SECOND]) * sign,
1657 ms: toInt(match[MILLISECOND]) * sign
1659 } else if (!!(match = isoDurationRegex.exec(input))) {
1660 sign = (match[1] === "-") ? -1 : 1;
1661 parseIso = function (inp) {
1662 // We'd normally use ~~inp for this, but unfortunately it also
1663 // converts floats to ints.
1664 // inp may be undefined, so careful calling replace on it.
1665 var res = inp && parseFloat(inp.replace(',', '.'));
1666 // apply sign while we're at it
1667 return (isNaN(res) ? 0 : res) * sign;
1670 y: parseIso(match[2]),
1671 M: parseIso(match[3]),
1672 d: parseIso(match[4]),
1673 h: parseIso(match[5]),
1674 m: parseIso(match[6]),
1675 s: parseIso(match[7]),
1676 w: parseIso(match[8])
1680 ret = new Duration(duration);
1682 if (moment.isDuration(input) && input.hasOwnProperty('_lang')) {
1683 ret._lang = input._lang;
1690 moment.version = VERSION;
1693 moment.defaultFormat = isoFormat;
1695 // This function will be called whenever a moment is mutated.
1696 // It is intended to keep the offset in sync with the timezone.
1697 moment.updateOffset = function () {};
1699 // This function will load languages and then set the global language. If
1700 // no arguments are passed in, it will simply return the current global
1702 moment.lang = function (key, values) {
1705 return moment.fn._lang._abbr;
1708 loadLang(normalizeLanguage(key), values);
1709 } else if (values === null) {
1712 } else if (!languages[key]) {
1713 getLangDefinition(key);
1715 r = moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key);
1719 // returns language data
1720 moment.langData = function (key) {
1721 if (key && key._lang && key._lang._abbr) {
1722 key = key._lang._abbr;
1724 return getLangDefinition(key);
1727 // compare moment object
1728 moment.isMoment = function (obj) {
1729 return obj instanceof Moment ||
1730 (obj != null && obj.hasOwnProperty('_isAMomentObject'));
1733 // for typechecking Duration objects
1734 moment.isDuration = function (obj) {
1735 return obj instanceof Duration;
1738 for (i = lists.length - 1; i >= 0; --i) {
1742 moment.normalizeUnits = function (units) {
1743 return normalizeUnits(units);
1746 moment.invalid = function (flags) {
1747 var m = moment.utc(NaN);
1748 if (flags != null) {
1749 extend(m._pf, flags);
1752 m._pf.userInvalidated = true;
1758 moment.parseZone = function (input) {
1759 return moment(input).parseZone();
1762 /************************************
1764 ************************************/
1767 extend(moment.fn = Moment.prototype, {
1769 clone : function () {
1770 return moment(this);
1773 valueOf : function () {
1774 return +this._d + ((this._offset || 0) * 60000);
1777 unix : function () {
1778 return Math.floor(+this / 1000);
1781 toString : function () {
1782 return this.clone().lang('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
1785 toDate : function () {
1786 return this._offset ? new Date(+this) : this._d;
1789 toISOString : function () {
1790 var m = moment(this).utc();
1791 if (0 < m.year() && m.year() <= 9999) {
1792 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
1794 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
1798 toArray : function () {
1811 isValid : function () {
1812 return isValid(this);
1815 isDSTShifted : function () {
1818 return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
1824 parsingFlags : function () {
1825 return extend({}, this._pf);
1828 invalidAt: function () {
1829 return this._pf.overflow;
1833 return this.zone(0);
1836 local : function () {
1838 this._isUTC = false;
1842 format : function (inputString) {
1843 var output = formatMoment(this, inputString || moment.defaultFormat);
1844 return this.lang().postformat(output);
1847 add : function (input, val) {
1849 // switch args to support add('s', 1) and add(1, 's')
1850 if (typeof input === 'string') {
1851 dur = moment.duration(+val, input);
1853 dur = moment.duration(input, val);
1855 addOrSubtractDurationFromMoment(this, dur, 1);
1859 subtract : function (input, val) {
1861 // switch args to support subtract('s', 1) and subtract(1, 's')
1862 if (typeof input === 'string') {
1863 dur = moment.duration(+val, input);
1865 dur = moment.duration(input, val);
1867 addOrSubtractDurationFromMoment(this, dur, -1);
1871 diff : function (input, units, asFloat) {
1872 var that = makeAs(input, this),
1873 zoneDiff = (this.zone() - that.zone()) * 6e4,
1876 units = normalizeUnits(units);
1878 if (units === 'year' || units === 'month') {
1879 // average number of days in the months in the given dates
1880 diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
1881 // difference in months
1882 output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
1883 // adjust by taking difference in days, average number of days
1884 // and dst in the given months.
1885 output += ((this - moment(this).startOf('month')) -
1886 (that - moment(that).startOf('month'))) / diff;
1887 // same as above but with zones, to negate all dst
1888 output -= ((this.zone() - moment(this).startOf('month').zone()) -
1889 (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff;
1890 if (units === 'year') {
1891 output = output / 12;
1894 diff = (this - that);
1895 output = units === 'second' ? diff / 1e3 : // 1000
1896 units === 'minute' ? diff / 6e4 : // 1000 * 60
1897 units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
1898 units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
1899 units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
1902 return asFloat ? output : absRound(output);
1905 from : function (time, withoutSuffix) {
1906 return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix);
1909 fromNow : function (withoutSuffix) {
1910 return this.from(moment(), withoutSuffix);
1913 calendar : function () {
1914 // We want to compare the start of today, vs this.
1915 // Getting start-of-today depends on whether we're zone'd or not.
1916 var sod = makeAs(moment(), this).startOf('day'),
1917 diff = this.diff(sod, 'days', true),
1918 format = diff < -6 ? 'sameElse' :
1919 diff < -1 ? 'lastWeek' :
1920 diff < 0 ? 'lastDay' :
1921 diff < 1 ? 'sameDay' :
1922 diff < 2 ? 'nextDay' :
1923 diff < 7 ? 'nextWeek' : 'sameElse';
1924 return this.format(this.lang().calendar(format, this));
1927 isLeapYear : function () {
1928 return isLeapYear(this.year());
1931 isDST : function () {
1932 return (this.zone() < this.clone().month(0).zone() ||
1933 this.zone() < this.clone().month(5).zone());
1936 day : function (input) {
1937 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
1938 if (input != null) {
1939 input = parseWeekday(input, this.lang());
1940 return this.add({ d : input - day });
1946 month : function (input) {
1947 var utc = this._isUTC ? 'UTC' : '',
1950 if (input != null) {
1951 if (typeof input === 'string') {
1952 input = this.lang().monthsParse(input);
1953 if (typeof input !== 'number') {
1958 dayOfMonth = this.date();
1960 this._d['set' + utc + 'Month'](input);
1961 this.date(Math.min(dayOfMonth, this.daysInMonth()));
1963 moment.updateOffset(this);
1966 return this._d['get' + utc + 'Month']();
1970 startOf: function (units) {
1971 units = normalizeUnits(units);
1972 // the following switch intentionally omits break keywords
1973 // to utilize falling through the cases.
1993 this.milliseconds(0);
1997 // weeks are a special case
1998 if (units === 'week') {
2000 } else if (units === 'isoWeek') {
2007 endOf: function (units) {
2008 units = normalizeUnits(units);
2009 return this.startOf(units).add((units === 'isoWeek' ? 'week' : units), 1).subtract('ms', 1);
2012 isAfter: function (input, units) {
2013 units = typeof units !== 'undefined' ? units : 'millisecond';
2014 return +this.clone().startOf(units) > +moment(input).startOf(units);
2017 isBefore: function (input, units) {
2018 units = typeof units !== 'undefined' ? units : 'millisecond';
2019 return +this.clone().startOf(units) < +moment(input).startOf(units);
2022 isSame: function (input, units) {
2023 units = units || 'ms';
2024 return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
2027 min: function (other) {
2028 other = moment.apply(null, arguments);
2029 return other < this ? this : other;
2032 max: function (other) {
2033 other = moment.apply(null, arguments);
2034 return other > this ? this : other;
2037 zone : function (input) {
2038 var offset = this._offset || 0;
2039 if (input != null) {
2040 if (typeof input === "string") {
2041 input = timezoneMinutesFromString(input);
2043 if (Math.abs(input) < 16) {
2046 this._offset = input;
2048 if (offset !== input) {
2049 addOrSubtractDurationFromMoment(this, moment.duration(offset - input, 'm'), 1, true);
2052 return this._isUTC ? offset : this._d.getTimezoneOffset();
2057 zoneAbbr : function () {
2058 return this._isUTC ? "UTC" : "";
2061 zoneName : function () {
2062 return this._isUTC ? "Coordinated Universal Time" : "";
2065 parseZone : function () {
2067 this.zone(this._tzm);
2068 } else if (typeof this._i === 'string') {
2074 hasAlignedHourOffset : function (input) {
2079 input = moment(input).zone();
2082 return (this.zone() - input) % 60 === 0;
2085 daysInMonth : function () {
2086 return daysInMonth(this.year(), this.month());
2089 dayOfYear : function (input) {
2090 var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
2091 return input == null ? dayOfYear : this.add("d", (input - dayOfYear));
2094 quarter : function () {
2095 return Math.ceil((this.month() + 1.0) / 3.0);
2098 weekYear : function (input) {
2099 var year = weekOfYear(this, this.lang()._week.dow, this.lang()._week.doy).year;
2100 return input == null ? year : this.add("y", (input - year));
2103 isoWeekYear : function (input) {
2104 var year = weekOfYear(this, 1, 4).year;
2105 return input == null ? year : this.add("y", (input - year));
2108 week : function (input) {
2109 var week = this.lang().week(this);
2110 return input == null ? week : this.add("d", (input - week) * 7);
2113 isoWeek : function (input) {
2114 var week = weekOfYear(this, 1, 4).week;
2115 return input == null ? week : this.add("d", (input - week) * 7);
2118 weekday : function (input) {
2119 var weekday = (this.day() + 7 - this.lang()._week.dow) % 7;
2120 return input == null ? weekday : this.add("d", input - weekday);
2123 isoWeekday : function (input) {
2124 // behaves the same as moment#day except
2125 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
2126 // as a setter, sunday should belong to the previous week.
2127 return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
2130 get : function (units) {
2131 units = normalizeUnits(units);
2132 return this[units]();
2135 set : function (units, value) {
2136 units = normalizeUnits(units);
2137 if (typeof this[units] === 'function') {
2143 // If passed a language key, it will set the language for this
2144 // instance. Otherwise, it will return the language configuration
2145 // variables for this instance.
2146 lang : function (key) {
2147 if (key === undefined) {
2150 this._lang = getLangDefinition(key);
2156 // helper for adding shortcuts
2157 function makeGetterAndSetter(name, key) {
2158 moment.fn[name] = moment.fn[name + 's'] = function (input) {
2159 var utc = this._isUTC ? 'UTC' : '';
2160 if (input != null) {
2161 this._d['set' + utc + key](input);
2162 moment.updateOffset(this);
2165 return this._d['get' + utc + key]();
2170 // loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
2171 for (i = 0; i < proxyGettersAndSetters.length; i ++) {
2172 makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase().replace(/s$/, ''), proxyGettersAndSetters[i]);
2175 // add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
2176 makeGetterAndSetter('year', 'FullYear');
2178 // add plural methods
2179 moment.fn.days = moment.fn.day;
2180 moment.fn.months = moment.fn.month;
2181 moment.fn.weeks = moment.fn.week;
2182 moment.fn.isoWeeks = moment.fn.isoWeek;
2184 // add aliased format methods
2185 moment.fn.toJSON = moment.fn.toISOString;
2187 /************************************
2189 ************************************/
2192 extend(moment.duration.fn = Duration.prototype, {
2194 _bubble : function () {
2195 var milliseconds = this._milliseconds,
2197 months = this._months,
2199 seconds, minutes, hours, years;
2201 // The following code bubbles up values, see the tests for
2202 // examples of what that means.
2203 data.milliseconds = milliseconds % 1000;
2205 seconds = absRound(milliseconds / 1000);
2206 data.seconds = seconds % 60;
2208 minutes = absRound(seconds / 60);
2209 data.minutes = minutes % 60;
2211 hours = absRound(minutes / 60);
2212 data.hours = hours % 24;
2214 days += absRound(hours / 24);
2215 data.days = days % 30;
2217 months += absRound(days / 30);
2218 data.months = months % 12;
2220 years = absRound(months / 12);
2224 weeks : function () {
2225 return absRound(this.days() / 7);
2228 valueOf : function () {
2229 return this._milliseconds +
2230 this._days * 864e5 +
2231 (this._months % 12) * 2592e6 +
2232 toInt(this._months / 12) * 31536e6;
2235 humanize : function (withSuffix) {
2236 var difference = +this,
2237 output = relativeTime(difference, !withSuffix, this.lang());
2240 output = this.lang().pastFuture(difference, output);
2243 return this.lang().postformat(output);
2246 add : function (input, val) {
2247 // supports only 2.0-style add(1, 's') or add(moment)
2248 var dur = moment.duration(input, val);
2250 this._milliseconds += dur._milliseconds;
2251 this._days += dur._days;
2252 this._months += dur._months;
2259 subtract : function (input, val) {
2260 var dur = moment.duration(input, val);
2262 this._milliseconds -= dur._milliseconds;
2263 this._days -= dur._days;
2264 this._months -= dur._months;
2271 get : function (units) {
2272 units = normalizeUnits(units);
2273 return this[units.toLowerCase() + 's']();
2276 as : function (units) {
2277 units = normalizeUnits(units);
2278 return this['as' + units.charAt(0).toUpperCase() + units.slice(1) + 's']();
2281 lang : moment.fn.lang,
2283 toIsoString : function () {
2284 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
2285 var years = Math.abs(this.years()),
2286 months = Math.abs(this.months()),
2287 days = Math.abs(this.days()),
2288 hours = Math.abs(this.hours()),
2289 minutes = Math.abs(this.minutes()),
2290 seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
2292 if (!this.asSeconds()) {
2293 // this is the same as C#'s (Noda) and python (isodate)...
2294 // but not other JS (goog.date)
2298 return (this.asSeconds() < 0 ? '-' : '') +
2300 (years ? years + 'Y' : '') +
2301 (months ? months + 'M' : '') +
2302 (days ? days + 'D' : '') +
2303 ((hours || minutes || seconds) ? 'T' : '') +
2304 (hours ? hours + 'H' : '') +
2305 (minutes ? minutes + 'M' : '') +
2306 (seconds ? seconds + 'S' : '');
2310 function makeDurationGetter(name) {
2311 moment.duration.fn[name] = function () {
2312 return this._data[name];
2316 function makeDurationAsGetter(name, factor) {
2317 moment.duration.fn['as' + name] = function () {
2318 return +this / factor;
2322 for (i in unitMillisecondFactors) {
2323 if (unitMillisecondFactors.hasOwnProperty(i)) {
2324 makeDurationAsGetter(i, unitMillisecondFactors[i]);
2325 makeDurationGetter(i.toLowerCase());
2329 makeDurationAsGetter('Weeks', 6048e5);
2330 moment.duration.fn.asMonths = function () {
2331 return (+this - this.years() * 31536e6) / 2592e6 + this.years() * 12;
2335 /************************************
2337 ************************************/
2340 // Set default language, other languages will inherit from English.
2342 ordinal : function (number) {
2343 var b = number % 10,
2344 output = (toInt(number % 100 / 10) === 1) ? 'th' :
2347 (b === 3) ? 'rd' : 'th';
2348 return number + output;
2352 /* EMBED_LANGUAGES */
2354 /************************************
2356 ************************************/
2358 function makeGlobal(deprecate) {
2359 var warned = false, local_moment = moment;
2360 /*global ender:false */
2361 if (typeof ender !== 'undefined') {
2364 // here, `this` means `window` in the browser, or `global` on the server
2365 // add `moment` as a global object via a string identifier,
2366 // for Closure Compiler "advanced" mode
2368 global.moment = function () {
2369 if (!warned && console && console.warn) {
2372 "Accessing Moment through the global scope is " +
2373 "deprecated, and will be removed in an upcoming " +
2376 return local_moment.apply(null, arguments);
2378 extend(global.moment, local_moment);
2380 global['moment'] = moment;
2384 // CommonJS module is defined
2386 module.exports = moment;
2388 } else if (typeof define === "function" && define.amd) {
2389 define("moment", function (require, exports, module) {
2390 if (module.config && module.config() && module.config().noGlobal !== true) {
2391 // If user provided noGlobal, he is aware of global
2392 makeGlobal(module.config().noGlobal === undefined);