3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
\r
7 (function (undefined) {
\r
8 /************************************
\r
10 ************************************/
\r
14 // the global-scope this is NOT the global object in Node.js
\r
15 globalScope = typeof global !== 'undefined' ? global : this,
\r
28 // internal storage for locale config files
\r
31 // extra moment internal properties (plugins register props here)
\r
32 momentProperties = [],
\r
35 hasModule = (typeof module !== 'undefined' && module.exports),
\r
37 // ASP.NET json date format regex
\r
38 aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
\r
39 aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
\r
41 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
\r
42 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
\r
43 isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
\r
46 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|zz?|ZZ?|.)/g,
\r
47 localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
\r
49 // parsing token regexes
\r
50 parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
\r
51 parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
\r
52 parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
\r
53 parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
\r
54 parseTokenDigits = /\d+/, // nonzero number of digits
\r
55 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.
\r
56 parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
\r
57 parseTokenT = /T/i, // T (ISO separator)
\r
58 parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
\r
59 parseTokenOrdinal = /\d{1,2}/,
\r
61 //strict parsing regexes
\r
62 parseTokenOneDigit = /\d/, // 0 - 9
\r
63 parseTokenTwoDigits = /\d\d/, // 00 - 99
\r
64 parseTokenThreeDigits = /\d{3}/, // 000 - 999
\r
65 parseTokenFourDigits = /\d{4}/, // 0000 - 9999
\r
66 parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
\r
67 parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
\r
70 // 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)
\r
71 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)?)?$/,
\r
73 isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
\r
76 ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
\r
77 ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
\r
78 ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
\r
79 ['GGGG-[W]WW', /\d{4}-W\d{2}/],
\r
80 ['YYYY-DDD', /\d{4}-\d{3}/]
\r
83 // iso time formats and regexes
\r
85 ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
\r
86 ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
\r
87 ['HH:mm', /(T| )\d\d:\d\d/],
\r
91 // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
\r
92 parseTimezoneChunker = /([\+\-]|\d\d)/gi,
\r
94 // getter and setter names
\r
95 proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
\r
96 unitMillisecondFactors = {
\r
107 ms : 'millisecond',
\r
126 dayofyear : 'dayOfYear',
\r
127 isoweekday : 'isoWeekday',
\r
128 isoweek : 'isoWeek',
\r
129 weekyear : 'weekYear',
\r
130 isoweekyear : 'isoWeekYear'
\r
133 // format function strings
\r
134 formatFunctions = {},
\r
136 // default relative time thresholds
\r
137 relativeTimeThresholds = {
\r
138 s: 45, // seconds to minute
\r
139 m: 45, // minutes to hour
\r
140 h: 22, // hours to day
\r
141 d: 26, // days to month
\r
142 M: 11 // months to year
\r
145 // tokens to ordinalize and pad
\r
146 ordinalizeTokens = 'DDD w W M D d'.split(' '),
\r
147 paddedTokens = 'M D H h m s w W'.split(' '),
\r
149 formatTokenFunctions = {
\r
151 return this.month() + 1;
\r
153 MMM : function (format) {
\r
154 return this.localeData().monthsShort(this, format);
\r
156 MMMM : function (format) {
\r
157 return this.localeData().months(this, format);
\r
160 return this.date();
\r
162 DDD : function () {
\r
163 return this.dayOfYear();
\r
168 dd : function (format) {
\r
169 return this.localeData().weekdaysMin(this, format);
\r
171 ddd : function (format) {
\r
172 return this.localeData().weekdaysShort(this, format);
\r
174 dddd : function (format) {
\r
175 return this.localeData().weekdays(this, format);
\r
178 return this.week();
\r
181 return this.isoWeek();
\r
184 return leftZeroFill(this.year() % 100, 2);
\r
186 YYYY : function () {
\r
187 return leftZeroFill(this.year(), 4);
\r
189 YYYYY : function () {
\r
190 return leftZeroFill(this.year(), 5);
\r
192 YYYYYY : function () {
\r
193 var y = this.year(), sign = y >= 0 ? '+' : '-';
\r
194 return sign + leftZeroFill(Math.abs(y), 6);
\r
197 return leftZeroFill(this.weekYear() % 100, 2);
\r
199 gggg : function () {
\r
200 return leftZeroFill(this.weekYear(), 4);
\r
202 ggggg : function () {
\r
203 return leftZeroFill(this.weekYear(), 5);
\r
206 return leftZeroFill(this.isoWeekYear() % 100, 2);
\r
208 GGGG : function () {
\r
209 return leftZeroFill(this.isoWeekYear(), 4);
\r
211 GGGGG : function () {
\r
212 return leftZeroFill(this.isoWeekYear(), 5);
\r
215 return this.weekday();
\r
218 return this.isoWeekday();
\r
221 return this.localeData().meridiem(this.hours(), this.minutes(), true);
\r
224 return this.localeData().meridiem(this.hours(), this.minutes(), false);
\r
227 return this.hours();
\r
230 return this.hours() % 12 || 12;
\r
233 return this.minutes();
\r
236 return this.seconds();
\r
239 return toInt(this.milliseconds() / 100);
\r
242 return leftZeroFill(toInt(this.milliseconds() / 10), 2);
\r
244 SSS : function () {
\r
245 return leftZeroFill(this.milliseconds(), 3);
\r
247 SSSS : function () {
\r
248 return leftZeroFill(this.milliseconds(), 3);
\r
251 var a = -this.zone(),
\r
257 return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);
\r
260 var a = -this.zone(),
\r
266 return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
\r
269 return this.zoneAbbr();
\r
272 return this.zoneName();
\r
275 return this.unix();
\r
278 return this.quarter();
\r
284 lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
\r
286 // Pick the first defined of two or three arguments. dfl comes from
\r
288 function dfl(a, b, c) {
\r
289 switch (arguments.length) {
\r
290 case 2: return a != null ? a : b;
\r
291 case 3: return a != null ? a : b != null ? b : c;
\r
292 default: throw new Error('Implement me');
\r
296 function defaultParsingFlags() {
\r
297 // We need to deep clone this object, and es5 standard is not very
\r
306 invalidMonth : null,
\r
307 invalidFormat : false,
\r
308 userInvalidated : false,
\r
313 function printMsg(msg) {
\r
314 if (moment.suppressDeprecationWarnings === false &&
\r
315 typeof console !== 'undefined' && console.warn) {
\r
316 console.warn("Deprecation warning: " + msg);
\r
320 function deprecate(msg, fn) {
\r
321 var firstTime = true;
\r
322 return extend(function () {
\r
327 return fn.apply(this, arguments);
\r
331 function deprecateSimple(name, msg) {
\r
332 if (!deprecations[name]) {
\r
334 deprecations[name] = true;
\r
338 function padToken(func, count) {
\r
339 return function (a) {
\r
340 return leftZeroFill(func.call(this, a), count);
\r
343 function ordinalizeToken(func, period) {
\r
344 return function (a) {
\r
345 return this.localeData().ordinal(func.call(this, a), period);
\r
349 while (ordinalizeTokens.length) {
\r
350 i = ordinalizeTokens.pop();
\r
351 formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
\r
353 while (paddedTokens.length) {
\r
354 i = paddedTokens.pop();
\r
355 formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
\r
357 formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
\r
360 /************************************
\r
362 ************************************/
\r
364 function Locale() {
\r
367 // Moment prototype object
\r
368 function Moment(config, skipOverflow) {
\r
369 if (skipOverflow !== false) {
\r
370 checkOverflow(config);
\r
372 copyConfig(this, config);
\r
373 this._d = new Date(+config._d);
\r
376 // Duration Constructor
\r
377 function Duration(duration) {
\r
378 var normalizedInput = normalizeObjectUnits(duration),
\r
379 years = normalizedInput.year || 0,
\r
380 quarters = normalizedInput.quarter || 0,
\r
381 months = normalizedInput.month || 0,
\r
382 weeks = normalizedInput.week || 0,
\r
383 days = normalizedInput.day || 0,
\r
384 hours = normalizedInput.hour || 0,
\r
385 minutes = normalizedInput.minute || 0,
\r
386 seconds = normalizedInput.second || 0,
\r
387 milliseconds = normalizedInput.millisecond || 0;
\r
389 // representation for dateAddRemove
\r
390 this._milliseconds = +milliseconds +
\r
391 seconds * 1e3 + // 1000
\r
392 minutes * 6e4 + // 1000 * 60
\r
393 hours * 36e5; // 1000 * 60 * 60
\r
394 // Because of dateAddRemove treats 24 hours as different from a
\r
395 // day when working around DST, we need to store them separately
\r
396 this._days = +days +
\r
398 // It is impossible translate months into days without knowing
\r
399 // which months you are are talking about, so we have to store
\r
401 this._months = +months +
\r
407 this._locale = moment.localeData();
\r
412 /************************************
\r
414 ************************************/
\r
417 function extend(a, b) {
\r
419 if (b.hasOwnProperty(i)) {
\r
424 if (b.hasOwnProperty('toString')) {
\r
425 a.toString = b.toString;
\r
428 if (b.hasOwnProperty('valueOf')) {
\r
429 a.valueOf = b.valueOf;
\r
435 function copyConfig(to, from) {
\r
438 if (typeof from._isAMomentObject !== 'undefined') {
\r
439 to._isAMomentObject = from._isAMomentObject;
\r
441 if (typeof from._i !== 'undefined') {
\r
444 if (typeof from._f !== 'undefined') {
\r
447 if (typeof from._l !== 'undefined') {
\r
450 if (typeof from._strict !== 'undefined') {
\r
451 to._strict = from._strict;
\r
453 if (typeof from._tzm !== 'undefined') {
\r
454 to._tzm = from._tzm;
\r
456 if (typeof from._isUTC !== 'undefined') {
\r
457 to._isUTC = from._isUTC;
\r
459 if (typeof from._offset !== 'undefined') {
\r
460 to._offset = from._offset;
\r
462 if (typeof from._pf !== 'undefined') {
\r
465 if (typeof from._locale !== 'undefined') {
\r
466 to._locale = from._locale;
\r
469 if (momentProperties.length > 0) {
\r
470 for (i in momentProperties) {
\r
471 prop = momentProperties[i];
\r
473 if (typeof val !== 'undefined') {
\r
482 function absRound(number) {
\r
484 return Math.ceil(number);
\r
486 return Math.floor(number);
\r
490 // left zero fill a number
\r
491 // see http://jsperf.com/left-zero-filling for performance comparison
\r
492 function leftZeroFill(number, targetLength, forceSign) {
\r
493 var output = '' + Math.abs(number),
\r
494 sign = number >= 0;
\r
496 while (output.length < targetLength) {
\r
497 output = '0' + output;
\r
499 return (sign ? (forceSign ? '+' : '') : '-') + output;
\r
502 function positiveMomentsDifference(base, other) {
\r
503 var res = {milliseconds: 0, months: 0};
\r
505 res.months = other.month() - base.month() +
\r
506 (other.year() - base.year()) * 12;
\r
507 if (base.clone().add(res.months, 'M').isAfter(other)) {
\r
511 res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
\r
516 function momentsDifference(base, other) {
\r
518 other = makeAs(other, base);
\r
519 if (base.isBefore(other)) {
\r
520 res = positiveMomentsDifference(base, other);
\r
522 res = positiveMomentsDifference(other, base);
\r
523 res.milliseconds = -res.milliseconds;
\r
524 res.months = -res.months;
\r
530 // TODO: remove 'name' arg after deprecation is removed
\r
531 function createAdder(direction, name) {
\r
532 return function (val, period) {
\r
534 //invert the arguments, but complain about it
\r
535 if (period !== null && !isNaN(+period)) {
\r
536 deprecateSimple(name, "moment()." + name + "(period, number) is deprecated. Please use moment()." + name + "(number, period).");
\r
537 tmp = val; val = period; period = tmp;
\r
540 val = typeof val === 'string' ? +val : val;
\r
541 dur = moment.duration(val, period);
\r
542 addOrSubtractDurationFromMoment(this, dur, direction);
\r
547 function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {
\r
548 var milliseconds = duration._milliseconds,
\r
549 days = duration._days,
\r
550 months = duration._months;
\r
551 updateOffset = updateOffset == null ? true : updateOffset;
\r
553 if (milliseconds) {
\r
554 mom._d.setTime(+mom._d + milliseconds * isAdding);
\r
557 rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);
\r
560 rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);
\r
562 if (updateOffset) {
\r
563 moment.updateOffset(mom, days || months);
\r
567 // check if is an array
\r
568 function isArray(input) {
\r
569 return Object.prototype.toString.call(input) === '[object Array]';
\r
572 function isDate(input) {
\r
573 return Object.prototype.toString.call(input) === '[object Date]' ||
\r
574 input instanceof Date;
\r
577 // compare two arrays, return the number of differences
\r
578 function compareArrays(array1, array2, dontConvert) {
\r
579 var len = Math.min(array1.length, array2.length),
\r
580 lengthDiff = Math.abs(array1.length - array2.length),
\r
583 for (i = 0; i < len; i++) {
\r
584 if ((dontConvert && array1[i] !== array2[i]) ||
\r
585 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
\r
589 return diffs + lengthDiff;
\r
592 function normalizeUnits(units) {
\r
594 var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
\r
595 units = unitAliases[units] || camelFunctions[lowered] || lowered;
\r
600 function normalizeObjectUnits(inputObject) {
\r
601 var normalizedInput = {},
\r
605 for (prop in inputObject) {
\r
606 if (inputObject.hasOwnProperty(prop)) {
\r
607 normalizedProp = normalizeUnits(prop);
\r
608 if (normalizedProp) {
\r
609 normalizedInput[normalizedProp] = inputObject[prop];
\r
614 return normalizedInput;
\r
617 function makeList(field) {
\r
620 if (field.indexOf('week') === 0) {
\r
624 else if (field.indexOf('month') === 0) {
\r
632 moment[field] = function (format, index) {
\r
634 method = moment._locale[field],
\r
637 if (typeof format === 'number') {
\r
639 format = undefined;
\r
642 getter = function (i) {
\r
643 var m = moment().utc().set(setter, i);
\r
644 return method.call(moment._locale, m, format || '');
\r
647 if (index != null) {
\r
648 return getter(index);
\r
651 for (i = 0; i < count; i++) {
\r
652 results.push(getter(i));
\r
659 function toInt(argumentForCoercion) {
\r
660 var coercedNumber = +argumentForCoercion,
\r
663 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
\r
664 if (coercedNumber >= 0) {
\r
665 value = Math.floor(coercedNumber);
\r
667 value = Math.ceil(coercedNumber);
\r
674 function daysInMonth(year, month) {
\r
675 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
\r
678 function weeksInYear(year, dow, doy) {
\r
679 return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;
\r
682 function daysInYear(year) {
\r
683 return isLeapYear(year) ? 366 : 365;
\r
686 function isLeapYear(year) {
\r
687 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
\r
690 function checkOverflow(m) {
\r
692 if (m._a && m._pf.overflow === -2) {
\r
694 m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
\r
695 m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
\r
696 m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
\r
697 m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
\r
698 m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
\r
699 m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
\r
702 if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
\r
706 m._pf.overflow = overflow;
\r
710 function isValid(m) {
\r
711 if (m._isValid == null) {
\r
712 m._isValid = !isNaN(m._d.getTime()) &&
\r
713 m._pf.overflow < 0 &&
\r
715 !m._pf.invalidMonth &&
\r
716 !m._pf.nullInput &&
\r
717 !m._pf.invalidFormat &&
\r
718 !m._pf.userInvalidated;
\r
721 m._isValid = m._isValid &&
\r
722 m._pf.charsLeftOver === 0 &&
\r
723 m._pf.unusedTokens.length === 0;
\r
729 function normalizeLocale(key) {
\r
730 return key ? key.toLowerCase().replace('_', '-') : key;
\r
733 // pick the locale from the array
\r
734 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
\r
735 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
\r
736 function chooseLocale(names) {
\r
737 var i = 0, j, next, locale, split;
\r
739 while (i < names.length) {
\r
740 split = normalizeLocale(names[i]).split('-');
\r
742 next = normalizeLocale(names[i + 1]);
\r
743 next = next ? next.split('-') : null;
\r
745 locale = loadLocale(split.slice(0, j).join('-'));
\r
749 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
\r
750 //the next array item is better than a shallower substring of this one
\r
760 function loadLocale(name) {
\r
761 var oldLocale = null;
\r
762 if (!locales[name] && hasModule) {
\r
764 oldLocale = moment.locale();
\r
765 require('./locale/' + name);
\r
766 // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales
\r
767 moment.locale(oldLocale);
\r
770 return locales[name];
\r
773 // Return a moment from input, that is local/utc/zone equivalent to model.
\r
774 function makeAs(input, model) {
\r
775 return model._isUTC ? moment(input).zone(model._offset || 0) :
\r
776 moment(input).local();
\r
779 /************************************
\r
781 ************************************/
\r
784 extend(Locale.prototype, {
\r
786 set : function (config) {
\r
788 for (i in config) {
\r
790 if (typeof prop === 'function') {
\r
793 this['_' + i] = prop;
\r
798 _months : '1_2_3_4_May_June_July_August_September_October_November_December'.split('_'),
\r
799 months : function (m) {
\r
800 return this._months[m.month()];
\r
803 _monthsShort : '1_2_3_4_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
\r
804 monthsShort : function (m) {
\r
805 return this._monthsShort[m.month()];
\r
808 monthsParse : function (monthName) {
\r
811 if (!this._monthsParse) {
\r
812 this._monthsParse = [];
\r
815 for (i = 0; i < 12; i++) {
\r
816 // make the regex if we don't have it already
\r
817 if (!this._monthsParse[i]) {
\r
818 mom = moment.utc([2000, i]);
\r
819 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
\r
820 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
\r
823 if (this._monthsParse[i].test(monthName)) {
\r
829 _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
\r
830 weekdays : function (m) {
\r
831 return this._weekdays[m.day()];
\r
834 _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
\r
835 weekdaysShort : function (m) {
\r
836 return this._weekdaysShort[m.day()];
\r
839 _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
\r
840 weekdaysMin : function (m) {
\r
841 return this._weekdaysMin[m.day()];
\r
844 weekdaysParse : function (weekdayName) {
\r
847 if (!this._weekdaysParse) {
\r
848 this._weekdaysParse = [];
\r
851 for (i = 0; i < 7; i++) {
\r
852 // make the regex if we don't have it already
\r
853 if (!this._weekdaysParse[i]) {
\r
854 mom = moment([2000, 1]).day(i);
\r
855 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
\r
856 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
\r
859 if (this._weekdaysParse[i].test(weekdayName)) {
\r
865 _longDateFormat : {
\r
868 LL : 'MMMM D, YYYY',
\r
869 LLL : 'MMMM D, YYYY LT',
\r
870 LLLL : 'dddd, MMMM D, YYYY LT'
\r
872 longDateFormat : function (key) {
\r
873 var output = this._longDateFormat[key];
\r
874 if (!output && this._longDateFormat[key.toUpperCase()]) {
\r
875 output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
\r
876 return val.slice(1);
\r
878 this._longDateFormat[key] = output;
\r
883 isPM : function (input) {
\r
884 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
\r
885 // Using charAt should be more compatible.
\r
886 return ((input + '').toLowerCase().charAt(0) === 'p');
\r
889 _meridiemParse : /[ap]\.?m?\.?/i,
\r
890 meridiem : function (hours, minutes, isLower) {
\r
892 return isLower ? 'pm' : 'PM';
\r
894 return isLower ? 'am' : 'AM';
\r
899 sameDay : '[Today at] LT',
\r
900 nextDay : '[Tomorrow at] LT',
\r
901 nextWeek : 'dddd [at] LT',
\r
902 lastDay : '[Yesterday at] LT',
\r
903 lastWeek : '[Last] dddd [at] LT',
\r
906 calendar : function (key, mom) {
\r
907 var output = this._calendar[key];
\r
908 return typeof output === 'function' ? output.apply(mom) : output;
\r
914 s : 'a few seconds',
\r
927 relativeTime : function (number, withoutSuffix, string, isFuture) {
\r
928 var output = this._relativeTime[string];
\r
929 return (typeof output === 'function') ?
\r
930 output(number, withoutSuffix, string, isFuture) :
\r
931 output.replace(/%d/i, number);
\r
934 pastFuture : function (diff, output) {
\r
935 var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
\r
936 return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
\r
939 ordinal : function (number) {
\r
940 return this._ordinal.replace('%d', number);
\r
944 preparse : function (string) {
\r
948 postformat : function (string) {
\r
952 week : function (mom) {
\r
953 return weekOfYear(mom, this._week.dow, this._week.doy).week;
\r
957 dow : 0, // Sunday is the first day of the week.
\r
958 doy : 6 // The week that contains Jan 1st is the first week of the year.
\r
961 _invalidDate: 'Invalid date',
\r
962 invalidDate: function () {
\r
963 return this._invalidDate;
\r
967 /************************************
\r
969 ************************************/
\r
972 function removeFormattingTokens(input) {
\r
973 if (input.match(/\[[\s\S]/)) {
\r
974 return input.replace(/^\[|\]$/g, '');
\r
976 return input.replace(/\\/g, '');
\r
979 function makeFormatFunction(format) {
\r
980 var array = format.match(formattingTokens), i, length;
\r
982 for (i = 0, length = array.length; i < length; i++) {
\r
983 if (formatTokenFunctions[array[i]]) {
\r
984 array[i] = formatTokenFunctions[array[i]];
\r
986 array[i] = removeFormattingTokens(array[i]);
\r
990 return function (mom) {
\r
992 for (i = 0; i < length; i++) {
\r
993 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
\r
999 // format date using native date object
\r
1000 function formatMoment(m, format) {
\r
1001 if (!m.isValid()) {
\r
1002 return m.localeData().invalidDate();
\r
1005 format = expandFormat(format, m.localeData());
\r
1007 if (!formatFunctions[format]) {
\r
1008 formatFunctions[format] = makeFormatFunction(format);
\r
1011 return formatFunctions[format](m);
\r
1014 function expandFormat(format, locale) {
\r
1017 function replaceLongDateFormatTokens(input) {
\r
1018 return locale.longDateFormat(input) || input;
\r
1021 localFormattingTokens.lastIndex = 0;
\r
1022 while (i >= 0 && localFormattingTokens.test(format)) {
\r
1023 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
\r
1024 localFormattingTokens.lastIndex = 0;
\r
1032 /************************************
\r
1034 ************************************/
\r
1037 // get the regex to find the next token
\r
1038 function getParseRegexForToken(token, config) {
\r
1039 var a, strict = config._strict;
\r
1042 return parseTokenOneDigit;
\r
1044 return parseTokenThreeDigits;
\r
1048 return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
\r
1052 return parseTokenSignedNumber;
\r
1057 return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
\r
1060 return parseTokenOneDigit;
\r
1062 /* falls through */
\r
1065 return parseTokenTwoDigits;
\r
1067 /* falls through */
\r
1070 return parseTokenThreeDigits;
\r
1072 /* falls through */
\r
1074 return parseTokenOneToThreeDigits;
\r
1080 return parseTokenWord;
\r
1083 return config._locale._meridiemParse;
\r
1085 return parseTokenTimestampMs;
\r
1088 return parseTokenTimezone;
\r
1090 return parseTokenT;
\r
1092 return parseTokenDigits;
\r
1104 return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
\r
1116 return parseTokenOneOrTwoDigits;
\r
1118 return parseTokenOrdinal;
\r
1120 a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), 'i'));
\r
1125 function timezoneMinutesFromString(string) {
\r
1126 string = string || '';
\r
1127 var possibleTzMatches = (string.match(parseTokenTimezone) || []),
\r
1128 tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
\r
1129 parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
\r
1130 minutes = +(parts[1] * 60) + toInt(parts[2]);
\r
1132 return parts[0] === '+' ? -minutes : minutes;
\r
1135 // function to convert string input to date
\r
1136 function addTimeToArrayFromToken(token, input, config) {
\r
1137 var a, datePartArray = config._a;
\r
1142 if (input != null) {
\r
1143 datePartArray[MONTH] = (toInt(input) - 1) * 3;
\r
1147 case 'M' : // fall through to MM
\r
1149 if (input != null) {
\r
1150 datePartArray[MONTH] = toInt(input) - 1;
\r
1153 case 'MMM' : // fall through to MMMM
\r
1155 a = config._locale.monthsParse(input);
\r
1156 // if we didn't find a month name, mark the date as invalid.
\r
1158 datePartArray[MONTH] = a;
\r
1160 config._pf.invalidMonth = input;
\r
1164 case 'D' : // fall through to DD
\r
1166 if (input != null) {
\r
1167 datePartArray[DATE] = toInt(input);
\r
1171 if (input != null) {
\r
1172 datePartArray[DATE] = toInt(parseInt(input, 10));
\r
1176 case 'DDD' : // fall through to DDDD
\r
1178 if (input != null) {
\r
1179 config._dayOfYear = toInt(input);
\r
1185 datePartArray[YEAR] = moment.parseTwoDigitYear(input);
\r
1190 datePartArray[YEAR] = toInt(input);
\r
1193 case 'a' : // fall through to A
\r
1195 config._isPm = config._locale.isPM(input);
\r
1198 case 'H' : // fall through to hh
\r
1199 case 'HH' : // fall through to hh
\r
1200 case 'h' : // fall through to hh
\r
1202 datePartArray[HOUR] = toInt(input);
\r
1205 case 'm' : // fall through to mm
\r
1207 datePartArray[MINUTE] = toInt(input);
\r
1210 case 's' : // fall through to ss
\r
1212 datePartArray[SECOND] = toInt(input);
\r
1219 datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
\r
1221 // UNIX TIMESTAMP WITH MS
\r
1223 config._d = new Date(parseFloat(input) * 1000);
\r
1226 case 'Z' : // fall through to ZZ
\r
1228 config._useUTC = true;
\r
1229 config._tzm = timezoneMinutesFromString(input);
\r
1231 // WEEKDAY - human
\r
1235 a = config._locale.weekdaysParse(input);
\r
1236 // if we didn't get a weekday name, mark the date as invalid
\r
1238 config._w = config._w || {};
\r
1239 config._w['d'] = a;
\r
1241 config._pf.invalidWeekday = input;
\r
1244 // WEEK, WEEK DAY - numeric
\r
1252 token = token.substr(0, 1);
\r
1253 /* falls through */
\r
1257 token = token.substr(0, 2);
\r
1259 config._w = config._w || {};
\r
1260 config._w[token] = toInt(input);
\r
1265 config._w = config._w || {};
\r
1266 config._w[token] = moment.parseTwoDigitYear(input);
\r
1270 function dayOfYearFromWeekInfo(config) {
\r
1271 var w, weekYear, week, weekday, dow, doy, temp;
\r
1274 if (w.GG != null || w.W != null || w.E != null) {
\r
1278 // TODO: We need to take the current isoWeekYear, but that depends on
\r
1279 // how we interpret now (local, utc, fixed offset). So create
\r
1280 // a now version of current config (take local/utc/offset flags, and
\r
1282 weekYear = dfl(w.GG, config._a[YEAR], weekOfYear(moment(), 1, 4).year);
\r
1283 week = dfl(w.W, 1);
\r
1284 weekday = dfl(w.E, 1);
\r
1286 dow = config._locale._week.dow;
\r
1287 doy = config._locale._week.doy;
\r
1289 weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);
\r
1290 week = dfl(w.w, 1);
\r
1292 if (w.d != null) {
\r
1293 // weekday -- low day numbers are considered next week
\r
1295 if (weekday < dow) {
\r
1298 } else if (w.e != null) {
\r
1299 // local weekday -- counting starts from begining of week
\r
1300 weekday = w.e + dow;
\r
1302 // default to begining of week
\r
1306 temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
\r
1308 config._a[YEAR] = temp.year;
\r
1309 config._dayOfYear = temp.dayOfYear;
\r
1312 // convert an array to a date.
\r
1313 // the array should mirror the parameters below
\r
1314 // note: all values past the year are optional and will default to the lowest possible value.
\r
1315 // [year, month, day , hour, minute, second, millisecond]
\r
1316 function dateFromConfig(config) {
\r
1317 var i, date, input = [], currentDate, yearToUse;
\r
1323 currentDate = currentDateArray(config);
\r
1325 //compute day of the year from weeks and weekdays
\r
1326 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
\r
1327 dayOfYearFromWeekInfo(config);
\r
1330 //if the day of the year is set, figure out what it is
\r
1331 if (config._dayOfYear) {
\r
1332 yearToUse = dfl(config._a[YEAR], currentDate[YEAR]);
\r
1334 if (config._dayOfYear > daysInYear(yearToUse)) {
\r
1335 config._pf._overflowDayOfYear = true;
\r
1338 date = makeUTCDate(yearToUse, 0, config._dayOfYear);
\r
1339 config._a[MONTH] = date.getUTCMonth();
\r
1340 config._a[DATE] = date.getUTCDate();
\r
1343 // Default to current date.
\r
1344 // * if no year, month, day of month are given, default to today
\r
1345 // * if day of month is given, default month and year
\r
1346 // * if month is given, default only year
\r
1347 // * if year is given, don't default anything
\r
1348 for (i = 0; i < 3 && config._a[i] == null; ++i) {
\r
1349 config._a[i] = input[i] = currentDate[i];
\r
1352 // Zero out whatever was not defaulted, including time
\r
1353 for (; i < 7; i++) {
\r
1354 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
\r
1357 config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
\r
1358 // Apply timezone offset from input. The actual zone can be changed
\r
1359 // with parseZone.
\r
1360 if (config._tzm != null) {
\r
1361 config._d.setUTCMinutes(config._d.getUTCMinutes() + config._tzm);
\r
1365 function dateFromObject(config) {
\r
1366 var normalizedInput;
\r
1372 normalizedInput = normalizeObjectUnits(config._i);
\r
1374 normalizedInput.year,
\r
1375 normalizedInput.month,
\r
1376 normalizedInput.day,
\r
1377 normalizedInput.hour,
\r
1378 normalizedInput.minute,
\r
1379 normalizedInput.second,
\r
1380 normalizedInput.millisecond
\r
1383 dateFromConfig(config);
\r
1386 function currentDateArray(config) {
\r
1387 var now = new Date();
\r
1388 if (config._useUTC) {
\r
1390 now.getUTCFullYear(),
\r
1391 now.getUTCMonth(),
\r
1395 return [now.getFullYear(), now.getMonth(), now.getDate()];
\r
1399 // date from string and format string
\r
1400 function makeDateFromStringAndFormat(config) {
\r
1401 if (config._f === moment.ISO_8601) {
\r
1407 config._pf.empty = true;
\r
1409 // This array is used to make a Date, either with `new Date` or `Date.UTC`
\r
1410 var string = '' + config._i,
\r
1411 i, parsedInput, tokens, token, skipped,
\r
1412 stringLength = string.length,
\r
1413 totalParsedInputLength = 0;
\r
1415 tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
\r
1417 for (i = 0; i < tokens.length; i++) {
\r
1418 token = tokens[i];
\r
1419 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
\r
1420 if (parsedInput) {
\r
1421 skipped = string.substr(0, string.indexOf(parsedInput));
\r
1422 if (skipped.length > 0) {
\r
1423 config._pf.unusedInput.push(skipped);
\r
1425 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
\r
1426 totalParsedInputLength += parsedInput.length;
\r
1428 // don't parse if it's not a known token
\r
1429 if (formatTokenFunctions[token]) {
\r
1430 if (parsedInput) {
\r
1431 config._pf.empty = false;
\r
1434 config._pf.unusedTokens.push(token);
\r
1436 addTimeToArrayFromToken(token, parsedInput, config);
\r
1438 else if (config._strict && !parsedInput) {
\r
1439 config._pf.unusedTokens.push(token);
\r
1443 // add remaining unparsed input length to the string
\r
1444 config._pf.charsLeftOver = stringLength - totalParsedInputLength;
\r
1445 if (string.length > 0) {
\r
1446 config._pf.unusedInput.push(string);
\r
1450 if (config._isPm && config._a[HOUR] < 12) {
\r
1451 config._a[HOUR] += 12;
\r
1453 // if is 12 am, change hours to 0
\r
1454 if (config._isPm === false && config._a[HOUR] === 12) {
\r
1455 config._a[HOUR] = 0;
\r
1458 dateFromConfig(config);
\r
1459 checkOverflow(config);
\r
1462 function unescapeFormat(s) {
\r
1463 return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
\r
1464 return p1 || p2 || p3 || p4;
\r
1468 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
\r
1469 function regexpEscape(s) {
\r
1470 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
\r
1473 // date from string and array of format strings
\r
1474 function makeDateFromStringAndArray(config) {
\r
1482 if (config._f.length === 0) {
\r
1483 config._pf.invalidFormat = true;
\r
1484 config._d = new Date(NaN);
\r
1488 for (i = 0; i < config._f.length; i++) {
\r
1490 tempConfig = copyConfig({}, config);
\r
1491 tempConfig._pf = defaultParsingFlags();
\r
1492 tempConfig._f = config._f[i];
\r
1493 makeDateFromStringAndFormat(tempConfig);
\r
1495 if (!isValid(tempConfig)) {
\r
1499 // if there is any input that was not parsed add a penalty for that format
\r
1500 currentScore += tempConfig._pf.charsLeftOver;
\r
1503 currentScore += tempConfig._pf.unusedTokens.length * 10;
\r
1505 tempConfig._pf.score = currentScore;
\r
1507 if (scoreToBeat == null || currentScore < scoreToBeat) {
\r
1508 scoreToBeat = currentScore;
\r
1509 bestMoment = tempConfig;
\r
1513 extend(config, bestMoment || tempConfig);
\r
1516 // date from iso format
\r
1517 function parseISO(config) {
\r
1519 string = config._i,
\r
1520 match = isoRegex.exec(string);
\r
1523 config._pf.iso = true;
\r
1524 for (i = 0, l = isoDates.length; i < l; i++) {
\r
1525 if (isoDates[i][1].exec(string)) {
\r
1526 // match[5] should be "T" or undefined
\r
1527 config._f = isoDates[i][0] + (match[6] || ' ');
\r
1531 for (i = 0, l = isoTimes.length; i < l; i++) {
\r
1532 if (isoTimes[i][1].exec(string)) {
\r
1533 config._f += isoTimes[i][0];
\r
1537 if (string.match(parseTokenTimezone)) {
\r
1540 makeDateFromStringAndFormat(config);
\r
1542 config._isValid = false;
\r
1546 // date from iso format or fallback
\r
1547 function makeDateFromString(config) {
\r
1549 if (config._isValid === false) {
\r
1550 delete config._isValid;
\r
1551 moment.createFromInputFallback(config);
\r
1555 function makeDateFromInput(config) {
\r
1556 var input = config._i, matched;
\r
1557 if (input === undefined) {
\r
1558 config._d = new Date();
\r
1559 } else if (isDate(input)) {
\r
1560 config._d = new Date(+input);
\r
1561 } else if ((matched = aspNetJsonRegex.exec(input)) !== null) {
\r
1562 config._d = new Date(+matched[1]);
\r
1563 } else if (typeof input === 'string') {
\r
1564 makeDateFromString(config);
\r
1565 } else if (isArray(input)) {
\r
1566 config._a = input.slice(0);
\r
1567 dateFromConfig(config);
\r
1568 } else if (typeof(input) === 'object') {
\r
1569 dateFromObject(config);
\r
1570 } else if (typeof(input) === 'number') {
\r
1571 // from milliseconds
\r
1572 config._d = new Date(input);
\r
1574 moment.createFromInputFallback(config);
\r
1578 function makeDate(y, m, d, h, M, s, ms) {
\r
1579 //can't just apply() to create a date:
\r
1580 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
\r
1581 var date = new Date(y, m, d, h, M, s, ms);
\r
1583 //the date constructor doesn't accept years < 1970
\r
1585 date.setFullYear(y);
\r
1590 function makeUTCDate(y) {
\r
1591 var date = new Date(Date.UTC.apply(null, arguments));
\r
1593 date.setUTCFullYear(y);
\r
1598 function parseWeekday(input, locale) {
\r
1599 if (typeof input === 'string') {
\r
1600 if (!isNaN(input)) {
\r
1601 input = parseInt(input, 10);
\r
1604 input = locale.weekdaysParse(input);
\r
1605 if (typeof input !== 'number') {
\r
1613 /************************************
\r
1615 ************************************/
\r
1618 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
\r
1619 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
\r
1620 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
\r
1623 function relativeTime(posNegDuration, withoutSuffix, locale) {
\r
1624 var duration = moment.duration(posNegDuration).abs(),
\r
1625 seconds = round(duration.as('s')),
\r
1626 minutes = round(duration.as('m')),
\r
1627 hours = round(duration.as('h')),
\r
1628 days = round(duration.as('d')),
\r
1629 months = round(duration.as('M')),
\r
1630 years = round(duration.as('y')),
\r
1632 args = seconds < relativeTimeThresholds.s && ['s', seconds] ||
\r
1633 minutes === 1 && ['m'] ||
\r
1634 minutes < relativeTimeThresholds.m && ['mm', minutes] ||
\r
1635 hours === 1 && ['h'] ||
\r
1636 hours < relativeTimeThresholds.h && ['hh', hours] ||
\r
1637 days === 1 && ['d'] ||
\r
1638 days < relativeTimeThresholds.d && ['dd', days] ||
\r
1639 months === 1 && ['M'] ||
\r
1640 months < relativeTimeThresholds.M && ['MM', months] ||
\r
1641 years === 1 && ['y'] || ['yy', years];
\r
1643 args[2] = withoutSuffix;
\r
1644 args[3] = +posNegDuration > 0;
\r
1646 return substituteTimeAgo.apply({}, args);
\r
1650 /************************************
\r
1652 ************************************/
\r
1655 // firstDayOfWeek 0 = sun, 6 = sat
\r
1656 // the day of the week that starts the week
\r
1657 // (usually sunday or monday)
\r
1658 // firstDayOfWeekOfYear 0 = sun, 6 = sat
\r
1659 // the first week is the week that contains the first
\r
1660 // of this day of the week
\r
1661 // (eg. ISO weeks use thursday (4))
\r
1662 function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
\r
1663 var end = firstDayOfWeekOfYear - firstDayOfWeek,
\r
1664 daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
\r
1668 if (daysToDayOfWeek > end) {
\r
1669 daysToDayOfWeek -= 7;
\r
1672 if (daysToDayOfWeek < end - 7) {
\r
1673 daysToDayOfWeek += 7;
\r
1676 adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');
\r
1678 week: Math.ceil(adjustedMoment.dayOfYear() / 7),
\r
1679 year: adjustedMoment.year()
\r
1683 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
\r
1684 function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
\r
1685 var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
\r
1687 d = d === 0 ? 7 : d;
\r
1688 weekday = weekday != null ? weekday : firstDayOfWeek;
\r
1689 daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
\r
1690 dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
\r
1693 year: dayOfYear > 0 ? year : year - 1,
\r
1694 dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
\r
1698 /************************************
\r
1699 Top Level Functions
\r
1700 ************************************/
\r
1702 function makeMoment(config) {
\r
1703 var input = config._i,
\r
1704 format = config._f;
\r
1706 config._locale = config._locale || moment.localeData(config._l);
\r
1708 if (input === null || (format === undefined && input === '')) {
\r
1709 return moment.invalid({nullInput: true});
\r
1712 if (typeof input === 'string') {
\r
1713 config._i = input = config._locale.preparse(input);
\r
1716 if (moment.isMoment(input)) {
\r
1717 return new Moment(input, true);
\r
1718 } else if (format) {
\r
1719 if (isArray(format)) {
\r
1720 makeDateFromStringAndArray(config);
\r
1722 makeDateFromStringAndFormat(config);
\r
1725 makeDateFromInput(config);
\r
1728 return new Moment(config);
\r
1731 moment = function (input, format, locale, strict) {
\r
1734 if (typeof(locale) === "boolean") {
\r
1736 locale = undefined;
\r
1738 // object construction must be done this way.
\r
1739 // https://github.com/moment/moment/issues/1423
\r
1741 c._isAMomentObject = true;
\r
1745 c._strict = strict;
\r
1747 c._pf = defaultParsingFlags();
\r
1749 return makeMoment(c);
\r
1752 moment.suppressDeprecationWarnings = false;
\r
1754 moment.createFromInputFallback = deprecate(
\r
1755 'moment construction falls back to js Date. This is ' +
\r
1756 'discouraged and will be removed in upcoming major ' +
\r
1757 'release. Please refer to ' +
\r
1758 'https://github.com/moment/moment/issues/1407 for more info.',
\r
1759 function (config) {
\r
1760 config._d = new Date(config._i);
\r
1764 // Pick a moment m from moments so that m[fn](other) is true for all
\r
1765 // other. This relies on the function fn to be transitive.
\r
1767 // moments should either be an array of moment objects or an array, whose
\r
1768 // first element is an array of moment objects.
\r
1769 function pickBy(fn, moments) {
\r
1771 if (moments.length === 1 && isArray(moments[0])) {
\r
1772 moments = moments[0];
\r
1774 if (!moments.length) {
\r
1778 for (i = 1; i < moments.length; ++i) {
\r
1779 if (moments[i][fn](res)) {
\r
1786 moment.min = function () {
\r
1787 var args = [].slice.call(arguments, 0);
\r
1789 return pickBy('isBefore', args);
\r
1792 moment.max = function () {
\r
1793 var args = [].slice.call(arguments, 0);
\r
1795 return pickBy('isAfter', args);
\r
1798 // creating with utc
\r
1799 moment.utc = function (input, format, locale, strict) {
\r
1802 if (typeof(locale) === "boolean") {
\r
1804 locale = undefined;
\r
1806 // object construction must be done this way.
\r
1807 // https://github.com/moment/moment/issues/1423
\r
1809 c._isAMomentObject = true;
\r
1815 c._strict = strict;
\r
1816 c._pf = defaultParsingFlags();
\r
1818 return makeMoment(c).utc();
\r
1821 // creating with unix timestamp (in seconds)
\r
1822 moment.unix = function (input) {
\r
1823 return moment(input * 1000);
\r
1827 moment.duration = function (input, key) {
\r
1828 var duration = input,
\r
1829 // matching against regexp is expensive, do it on demand
\r
1836 if (moment.isDuration(input)) {
\r
1838 ms: input._milliseconds,
\r
1842 } else if (typeof input === 'number') {
\r
1845 duration[key] = input;
\r
1847 duration.milliseconds = input;
\r
1849 } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
\r
1850 sign = (match[1] === '-') ? -1 : 1;
\r
1853 d: toInt(match[DATE]) * sign,
\r
1854 h: toInt(match[HOUR]) * sign,
\r
1855 m: toInt(match[MINUTE]) * sign,
\r
1856 s: toInt(match[SECOND]) * sign,
\r
1857 ms: toInt(match[MILLISECOND]) * sign
\r
1859 } else if (!!(match = isoDurationRegex.exec(input))) {
\r
1860 sign = (match[1] === '-') ? -1 : 1;
\r
1861 parseIso = function (inp) {
\r
1862 // We'd normally use ~~inp for this, but unfortunately it also
\r
1863 // converts floats to ints.
\r
1864 // inp may be undefined, so careful calling replace on it.
\r
1865 var res = inp && parseFloat(inp.replace(',', '.'));
\r
1866 // apply sign while we're at it
\r
1867 return (isNaN(res) ? 0 : res) * sign;
\r
1870 y: parseIso(match[2]),
\r
1871 M: parseIso(match[3]),
\r
1872 d: parseIso(match[4]),
\r
1873 h: parseIso(match[5]),
\r
1874 m: parseIso(match[6]),
\r
1875 s: parseIso(match[7]),
\r
1876 w: parseIso(match[8])
\r
1878 } else if (typeof duration === 'object' &&
\r
1879 ('from' in duration || 'to' in duration)) {
\r
1880 diffRes = momentsDifference(moment(duration.from), moment(duration.to));
\r
1883 duration.ms = diffRes.milliseconds;
\r
1884 duration.M = diffRes.months;
\r
1887 ret = new Duration(duration);
\r
1889 if (moment.isDuration(input) && input.hasOwnProperty('_locale')) {
\r
1890 ret._locale = input._locale;
\r
1897 moment.version = VERSION;
\r
1900 moment.defaultFormat = isoFormat;
\r
1902 // constant that refers to the ISO standard
\r
1903 moment.ISO_8601 = function () {};
\r
1905 // Plugins that add properties should also add the key here (null value),
\r
1906 // so we can properly clone ourselves.
\r
1907 moment.momentProperties = momentProperties;
\r
1909 // This function will be called whenever a moment is mutated.
\r
1910 // It is intended to keep the offset in sync with the timezone.
\r
1911 moment.updateOffset = function () {};
\r
1913 // This function allows you to set a threshold for relative time strings
\r
1914 moment.relativeTimeThreshold = function (threshold, limit) {
\r
1915 if (relativeTimeThresholds[threshold] === undefined) {
\r
1918 if (limit === undefined) {
\r
1919 return relativeTimeThresholds[threshold];
\r
1921 relativeTimeThresholds[threshold] = limit;
\r
1925 moment.lang = deprecate(
\r
1926 "moment.lang is deprecated. Use moment.locale instead.",
\r
1927 function (key, value) {
\r
1928 return moment.locale(key, value);
\r
1932 // This function will load locale and then set the global locale. If
\r
1933 // no arguments are passed in, it will simply return the current global
\r
1935 moment.locale = function (key, values) {
\r
1938 if (typeof(values) !== "undefined") {
\r
1939 data = moment.defineLocale(key, values);
\r
1942 data = moment.localeData(key);
\r
1946 moment.duration._locale = moment._locale = data;
\r
1950 return moment._locale._abbr;
\r
1953 moment.defineLocale = function (name, values) {
\r
1954 if (values !== null) {
\r
1955 values.abbr = name;
\r
1956 if (!locales[name]) {
\r
1957 locales[name] = new Locale();
\r
1959 locales[name].set(values);
\r
1961 // backwards compat for now: also set the locale
\r
1962 moment.locale(name);
\r
1964 return locales[name];
\r
1966 // useful for testing
\r
1967 delete locales[name];
\r
1972 moment.langData = deprecate(
\r
1973 "moment.langData is deprecated. Use moment.localeData instead.",
\r
1975 return moment.localeData(key);
\r
1979 // returns locale data
\r
1980 moment.localeData = function (key) {
\r
1983 if (key && key._locale && key._locale._abbr) {
\r
1984 key = key._locale._abbr;
\r
1988 return moment._locale;
\r
1991 if (!isArray(key)) {
\r
1992 //short-circuit everything else
\r
1993 locale = loadLocale(key);
\r
2000 return chooseLocale(key);
\r
2003 // compare moment object
\r
2004 moment.isMoment = function (obj) {
\r
2005 return obj instanceof Moment ||
\r
2006 (obj != null && obj.hasOwnProperty('_isAMomentObject'));
\r
2009 // for typechecking Duration objects
\r
2010 moment.isDuration = function (obj) {
\r
2011 return obj instanceof Duration;
\r
2014 for (i = lists.length - 1; i >= 0; --i) {
\r
2015 makeList(lists[i]);
\r
2018 moment.normalizeUnits = function (units) {
\r
2019 return normalizeUnits(units);
\r
2022 moment.invalid = function (flags) {
\r
2023 var m = moment.utc(NaN);
\r
2024 if (flags != null) {
\r
2025 extend(m._pf, flags);
\r
2028 m._pf.userInvalidated = true;
\r
2034 moment.parseZone = function () {
\r
2035 return moment.apply(null, arguments).parseZone();
\r
2038 moment.parseTwoDigitYear = function (input) {
\r
2039 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
\r
2042 /************************************
\r
2044 ************************************/
\r
2047 extend(moment.fn = Moment.prototype, {
\r
2049 clone : function () {
\r
2050 return moment(this);
\r
2053 valueOf : function () {
\r
2054 return +this._d + ((this._offset || 0) * 60000);
\r
2057 unix : function () {
\r
2058 return Math.floor(+this / 1000);
\r
2061 toString : function () {
\r
2062 return this.clone().locale('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
\r
2065 toDate : function () {
\r
2066 return this._offset ? new Date(+this) : this._d;
\r
2069 toISOString : function () {
\r
2070 var m = moment(this).utc();
\r
2071 if (0 < m.year() && m.year() <= 9999) {
\r
2072 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
\r
2074 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
\r
2078 toArray : function () {
\r
2091 isValid : function () {
\r
2092 return isValid(this);
\r
2095 isDSTShifted : function () {
\r
2097 return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
\r
2103 parsingFlags : function () {
\r
2104 return extend({}, this._pf);
\r
2107 invalidAt: function () {
\r
2108 return this._pf.overflow;
\r
2111 utc : function (keepLocalTime) {
\r
2112 return this.zone(0, keepLocalTime);
\r
2115 local : function (keepLocalTime) {
\r
2116 if (this._isUTC) {
\r
2117 this.zone(0, keepLocalTime);
\r
2118 this._isUTC = false;
\r
2120 if (keepLocalTime) {
\r
2121 this.add(this._d.getTimezoneOffset(), 'm');
\r
2127 format : function (inputString) {
\r
2128 var output = formatMoment(this, inputString || moment.defaultFormat);
\r
2129 return this.localeData().postformat(output);
\r
2132 add : createAdder(1, 'add'),
\r
2134 subtract : createAdder(-1, 'subtract'),
\r
2136 diff : function (input, units, asFloat) {
\r
2137 var that = makeAs(input, this),
\r
2138 zoneDiff = (this.zone() - that.zone()) * 6e4,
\r
2141 units = normalizeUnits(units);
\r
2143 if (units === 'year' || units === 'month') {
\r
2144 // average number of days in the months in the given dates
\r
2145 diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
\r
2146 // difference in months
\r
2147 output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
\r
2148 // adjust by taking difference in days, average number of days
\r
2149 // and dst in the given months.
\r
2150 output += ((this - moment(this).startOf('month')) -
\r
2151 (that - moment(that).startOf('month'))) / diff;
\r
2152 // same as above but with zones, to negate all dst
\r
2153 output -= ((this.zone() - moment(this).startOf('month').zone()) -
\r
2154 (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff;
\r
2155 if (units === 'year') {
\r
2156 output = output / 12;
\r
2159 diff = (this - that);
\r
2160 output = units === 'second' ? diff / 1e3 : // 1000
\r
2161 units === 'minute' ? diff / 6e4 : // 1000 * 60
\r
2162 units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
\r
2163 units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
\r
2164 units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
\r
2167 return asFloat ? output : absRound(output);
\r
2170 from : function (time, withoutSuffix) {
\r
2171 return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
\r
2174 fromNow : function (withoutSuffix) {
\r
2175 return this.from(moment(), withoutSuffix);
\r
2178 calendar : function (time) {
\r
2179 // We want to compare the start of today, vs this.
\r
2180 // Getting start-of-today depends on whether we're zone'd or not.
\r
2181 var now = time || moment(),
\r
2182 sod = makeAs(now, this).startOf('day'),
\r
2183 diff = this.diff(sod, 'days', true),
\r
2184 format = diff < -6 ? 'sameElse' :
\r
2185 diff < -1 ? 'lastWeek' :
\r
2186 diff < 0 ? 'lastDay' :
\r
2187 diff < 1 ? 'sameDay' :
\r
2188 diff < 2 ? 'nextDay' :
\r
2189 diff < 7 ? 'nextWeek' : 'sameElse';
\r
2190 return this.format(this.localeData().calendar(format, this));
\r
2193 isLeapYear : function () {
\r
2194 return isLeapYear(this.year());
\r
2197 isDST : function () {
\r
2198 return (this.zone() < this.clone().month(0).zone() ||
\r
2199 this.zone() < this.clone().month(5).zone());
\r
2202 day : function (input) {
\r
2203 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
\r
2204 if (input != null) {
\r
2205 input = parseWeekday(input, this.localeData());
\r
2206 return this.add(input - day, 'd');
\r
2212 month : makeAccessor('Month', true),
\r
2214 startOf : function (units) {
\r
2215 units = normalizeUnits(units);
\r
2216 // the following switch intentionally omits break keywords
\r
2217 // to utilize falling through the cases.
\r
2221 /* falls through */
\r
2225 /* falls through */
\r
2230 /* falls through */
\r
2233 /* falls through */
\r
2236 /* falls through */
\r
2238 this.milliseconds(0);
\r
2239 /* falls through */
\r
2242 // weeks are a special case
\r
2243 if (units === 'week') {
\r
2245 } else if (units === 'isoWeek') {
\r
2246 this.isoWeekday(1);
\r
2249 // quarters are also special
\r
2250 if (units === 'quarter') {
\r
2251 this.month(Math.floor(this.month() / 3) * 3);
\r
2257 endOf: function (units) {
\r
2258 units = normalizeUnits(units);
\r
2259 return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
\r
2262 isAfter: function (input, units) {
\r
2263 units = typeof units !== 'undefined' ? units : 'millisecond';
\r
2264 return +this.clone().startOf(units) > +moment(input).startOf(units);
\r
2267 isBefore: function (input, units) {
\r
2268 units = typeof units !== 'undefined' ? units : 'millisecond';
\r
2269 return +this.clone().startOf(units) < +moment(input).startOf(units);
\r
2272 isSame: function (input, units) {
\r
2273 units = units || 'ms';
\r
2274 return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
\r
2278 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
\r
2279 function (other) {
\r
2280 other = moment.apply(null, arguments);
\r
2281 return other < this ? this : other;
\r
2286 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
\r
2287 function (other) {
\r
2288 other = moment.apply(null, arguments);
\r
2289 return other > this ? this : other;
\r
2293 // keepLocalTime = true means only change the timezone, without
\r
2294 // affecting the local hour. So 5:31:26 +0300 --[zone(2, true)]-->
\r
2295 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist int zone
\r
2296 // +0200, so we adjust the time as needed, to be valid.
\r
2298 // Keeping the time actually adds/subtracts (one hour)
\r
2299 // from the actual represented time. That is why we call updateOffset
\r
2300 // a second time. In case it wants us to change the offset again
\r
2301 // _changeInProgress == true case, then we have to adjust, because
\r
2302 // there is no such time in the given timezone.
\r
2303 zone : function (input, keepLocalTime) {
\r
2304 var offset = this._offset || 0,
\r
2306 if (input != null) {
\r
2307 if (typeof input === 'string') {
\r
2308 input = timezoneMinutesFromString(input);
\r
2310 if (Math.abs(input) < 16) {
\r
2311 input = input * 60;
\r
2313 if (!this._isUTC && keepLocalTime) {
\r
2314 localAdjust = this._d.getTimezoneOffset();
\r
2316 this._offset = input;
\r
2317 this._isUTC = true;
\r
2318 if (localAdjust != null) {
\r
2319 this.subtract(localAdjust, 'm');
\r
2321 if (offset !== input) {
\r
2322 if (!keepLocalTime || this._changeInProgress) {
\r
2323 addOrSubtractDurationFromMoment(this,
\r
2324 moment.duration(offset - input, 'm'), 1, false);
\r
2325 } else if (!this._changeInProgress) {
\r
2326 this._changeInProgress = true;
\r
2327 moment.updateOffset(this, true);
\r
2328 this._changeInProgress = null;
\r
2332 return this._isUTC ? offset : this._d.getTimezoneOffset();
\r
2337 zoneAbbr : function () {
\r
2338 return this._isUTC ? 'UTC' : '';
\r
2341 zoneName : function () {
\r
2342 return this._isUTC ? 'Coordinated Universal Time' : '';
\r
2345 parseZone : function () {
\r
2347 this.zone(this._tzm);
\r
2348 } else if (typeof this._i === 'string') {
\r
2349 this.zone(this._i);
\r
2354 hasAlignedHourOffset : function (input) {
\r
2359 input = moment(input).zone();
\r
2362 return (this.zone() - input) % 60 === 0;
\r
2365 daysInMonth : function () {
\r
2366 return daysInMonth(this.year(), this.month());
\r
2369 dayOfYear : function (input) {
\r
2370 var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
\r
2371 return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
\r
2374 quarter : function (input) {
\r
2375 return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
\r
2378 weekYear : function (input) {
\r
2379 var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;
\r
2380 return input == null ? year : this.add((input - year), 'y');
\r
2383 isoWeekYear : function (input) {
\r
2384 var year = weekOfYear(this, 1, 4).year;
\r
2385 return input == null ? year : this.add((input - year), 'y');
\r
2388 week : function (input) {
\r
2389 var week = this.localeData().week(this);
\r
2390 return input == null ? week : this.add((input - week) * 7, 'd');
\r
2393 isoWeek : function (input) {
\r
2394 var week = weekOfYear(this, 1, 4).week;
\r
2395 return input == null ? week : this.add((input - week) * 7, 'd');
\r
2398 weekday : function (input) {
\r
2399 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
\r
2400 return input == null ? weekday : this.add(input - weekday, 'd');
\r
2403 isoWeekday : function (input) {
\r
2404 // behaves the same as moment#day except
\r
2405 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
\r
2406 // as a setter, sunday should belong to the previous week.
\r
2407 return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
\r
2410 isoWeeksInYear : function () {
\r
2411 return weeksInYear(this.year(), 1, 4);
\r
2414 weeksInYear : function () {
\r
2415 var weekInfo = this.localeData()._week;
\r
2416 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
\r
2419 get : function (units) {
\r
2420 units = normalizeUnits(units);
\r
2421 return this[units]();
\r
2424 set : function (units, value) {
\r
2425 units = normalizeUnits(units);
\r
2426 if (typeof this[units] === 'function') {
\r
2427 this[units](value);
\r
2432 // If passed a locale key, it will set the locale for this
\r
2433 // instance. Otherwise, it will return the locale configuration
\r
2434 // variables for this instance.
\r
2435 locale : function (key) {
\r
2436 if (key === undefined) {
\r
2437 return this._locale._abbr;
\r
2439 this._locale = moment.localeData(key);
\r
2445 "moment().lang() is deprecated. Use moment().localeData() instead.",
\r
2447 if (key === undefined) {
\r
2448 return this.localeData();
\r
2450 this._locale = moment.localeData(key);
\r
2456 localeData : function () {
\r
2457 return this._locale;
\r
2461 function rawMonthSetter(mom, value) {
\r
2464 // TODO: Move this out of here!
\r
2465 if (typeof value === 'string') {
\r
2466 value = mom.localeData().monthsParse(value);
\r
2467 // TODO: Another silent failure?
\r
2468 if (typeof value !== 'number') {
\r
2473 dayOfMonth = Math.min(mom.date(),
\r
2474 daysInMonth(mom.year(), value));
\r
2475 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
\r
2479 function rawGetter(mom, unit) {
\r
2480 return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
\r
2483 function rawSetter(mom, unit, value) {
\r
2484 if (unit === 'Month') {
\r
2485 return rawMonthSetter(mom, value);
\r
2487 return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
\r
2491 function makeAccessor(unit, keepTime) {
\r
2492 return function (value) {
\r
2493 if (value != null) {
\r
2494 rawSetter(this, unit, value);
\r
2495 moment.updateOffset(this, keepTime);
\r
2498 return rawGetter(this, unit);
\r
2503 moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);
\r
2504 moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);
\r
2505 moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);
\r
2506 // Setting the hour should keep the time, because the user explicitly
\r
2507 // specified which hour he wants. So trying to maintain the same hour (in
\r
2508 // a new timezone) makes sense. Adding/subtracting hours does not follow
\r
2510 moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);
\r
2511 // moment.fn.month is defined separately
\r
2512 moment.fn.date = makeAccessor('Date', true);
\r
2513 moment.fn.dates = deprecate('dates accessor is deprecated. Use date instead.', makeAccessor('Date', true));
\r
2514 moment.fn.year = makeAccessor('FullYear', true);
\r
2515 moment.fn.years = deprecate('years accessor is deprecated. Use year instead.', makeAccessor('FullYear', true));
\r
2517 // add plural methods
\r
2518 moment.fn.days = moment.fn.day;
\r
2519 moment.fn.months = moment.fn.month;
\r
2520 moment.fn.weeks = moment.fn.week;
\r
2521 moment.fn.isoWeeks = moment.fn.isoWeek;
\r
2522 moment.fn.quarters = moment.fn.quarter;
\r
2524 // add aliased format methods
\r
2525 moment.fn.toJSON = moment.fn.toISOString;
\r
2527 /************************************
\r
2528 Duration Prototype
\r
2529 ************************************/
\r
2532 function daysToYears (days) {
\r
2533 // 400 years have 146097 days (taking into account leap year rules)
\r
2534 return days * 400 / 146097;
\r
2537 function yearsToDays (years) {
\r
2538 // years * 365 + absRound(years / 4) -
\r
2539 // absRound(years / 100) + absRound(years / 400);
\r
2540 return years * 146097 / 400;
\r
2543 extend(moment.duration.fn = Duration.prototype, {
\r
2545 _bubble : function () {
\r
2546 var milliseconds = this._milliseconds,
\r
2547 days = this._days,
\r
2548 months = this._months,
\r
2549 data = this._data,
\r
2550 seconds, minutes, hours, years = 0;
\r
2552 // The following code bubbles up values, see the tests for
\r
2553 // examples of what that means.
\r
2554 data.milliseconds = milliseconds % 1000;
\r
2556 seconds = absRound(milliseconds / 1000);
\r
2557 data.seconds = seconds % 60;
\r
2559 minutes = absRound(seconds / 60);
\r
2560 data.minutes = minutes % 60;
\r
2562 hours = absRound(minutes / 60);
\r
2563 data.hours = hours % 24;
\r
2565 days += absRound(hours / 24);
\r
2567 // Accurately convert days to years, assume start from year 0.
\r
2568 years = absRound(daysToYears(days));
\r
2569 days -= absRound(yearsToDays(years));
\r
2571 // 30 days to a month
\r
2572 // TODO (iskren): Use anchor date (like 1st Jan) to compute this.
\r
2573 months += absRound(days / 30);
\r
2576 // 12 months -> 1 year
\r
2577 years += absRound(months / 12);
\r
2581 data.months = months;
\r
2582 data.years = years;
\r
2585 abs : function () {
\r
2586 this._milliseconds = Math.abs(this._milliseconds);
\r
2587 this._days = Math.abs(this._days);
\r
2588 this._months = Math.abs(this._months);
\r
2590 this._data.milliseconds = Math.abs(this._data.milliseconds);
\r
2591 this._data.seconds = Math.abs(this._data.seconds);
\r
2592 this._data.minutes = Math.abs(this._data.minutes);
\r
2593 this._data.hours = Math.abs(this._data.hours);
\r
2594 this._data.months = Math.abs(this._data.months);
\r
2595 this._data.years = Math.abs(this._data.years);
\r
2600 weeks : function () {
\r
2601 return absRound(this.days() / 7);
\r
2604 valueOf : function () {
\r
2605 return this._milliseconds +
\r
2606 this._days * 864e5 +
\r
2607 (this._months % 12) * 2592e6 +
\r
2608 toInt(this._months / 12) * 31536e6;
\r
2611 humanize : function (withSuffix) {
\r
2612 var output = relativeTime(this, !withSuffix, this.localeData());
\r
2615 output = this.localeData().pastFuture(+this, output);
\r
2618 return this.localeData().postformat(output);
\r
2621 add : function (input, val) {
\r
2622 // supports only 2.0-style add(1, 's') or add(moment)
\r
2623 var dur = moment.duration(input, val);
\r
2625 this._milliseconds += dur._milliseconds;
\r
2626 this._days += dur._days;
\r
2627 this._months += dur._months;
\r
2634 subtract : function (input, val) {
\r
2635 var dur = moment.duration(input, val);
\r
2637 this._milliseconds -= dur._milliseconds;
\r
2638 this._days -= dur._days;
\r
2639 this._months -= dur._months;
\r
2646 get : function (units) {
\r
2647 units = normalizeUnits(units);
\r
2648 return this[units.toLowerCase() + 's']();
\r
2651 as : function (units) {
\r
2653 units = normalizeUnits(units);
\r
2655 days = this._days + this._milliseconds / 864e5;
\r
2656 if (units === 'month' || units === 'year') {
\r
2657 months = this._months + daysToYears(days) * 12;
\r
2658 return units === 'month' ? months : months / 12;
\r
2660 days += yearsToDays(this._months / 12);
\r
2662 case 'week': return days / 7;
\r
2663 case 'day': return days;
\r
2664 case 'hour': return days * 24;
\r
2665 case 'minute': return days * 24 * 60;
\r
2666 case 'second': return days * 24 * 60 * 60;
\r
2667 case 'millisecond': return days * 24 * 60 * 60 * 1000;
\r
2668 default: throw new Error('Unknown unit ' + units);
\r
2673 lang : moment.fn.lang,
\r
2674 locale : moment.fn.locale,
\r
2676 toIsoString : deprecate(
\r
2677 "toIsoString() is deprecated. Please use toISOString() instead " +
\r
2678 "(notice the capitals)",
\r
2680 return this.toISOString();
\r
2684 toISOString : function () {
\r
2685 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
\r
2686 var years = Math.abs(this.years()),
\r
2687 months = Math.abs(this.months()),
\r
2688 days = Math.abs(this.days()),
\r
2689 hours = Math.abs(this.hours()),
\r
2690 minutes = Math.abs(this.minutes()),
\r
2691 seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
\r
2693 if (!this.asSeconds()) {
\r
2694 // this is the same as C#'s (Noda) and python (isodate)...
\r
2695 // but not other JS (goog.date)
\r
2699 return (this.asSeconds() < 0 ? '-' : '') +
\r
2701 (years ? years + 'Y' : '') +
\r
2702 (months ? months + 'M' : '') +
\r
2703 (days ? days + 'D' : '') +
\r
2704 ((hours || minutes || seconds) ? 'T' : '') +
\r
2705 (hours ? hours + 'H' : '') +
\r
2706 (minutes ? minutes + 'M' : '') +
\r
2707 (seconds ? seconds + 'S' : '');
\r
2710 localeData : function () {
\r
2711 return this._locale;
\r
2715 function makeDurationGetter(name) {
\r
2716 moment.duration.fn[name] = function () {
\r
2717 return this._data[name];
\r
2721 for (i in unitMillisecondFactors) {
\r
2722 if (unitMillisecondFactors.hasOwnProperty(i)) {
\r
2723 makeDurationGetter(i.toLowerCase());
\r
2727 moment.duration.fn.asMilliseconds = function () {
\r
2728 return this.as('ms');
\r
2730 moment.duration.fn.asSeconds = function () {
\r
2731 return this.as('s');
\r
2733 moment.duration.fn.asMinutes = function () {
\r
2734 return this.as('m');
\r
2736 moment.duration.fn.asHours = function () {
\r
2737 return this.as('h');
\r
2739 moment.duration.fn.asDays = function () {
\r
2740 return this.as('d');
\r
2742 moment.duration.fn.asWeeks = function () {
\r
2743 return this.as('weeks');
\r
2745 moment.duration.fn.asMonths = function () {
\r
2746 return this.as('M');
\r
2748 moment.duration.fn.asYears = function () {
\r
2749 return this.as('y');
\r
2752 /************************************
\r
2754 ************************************/
\r
2757 // Set default locale, other locale will inherit from English.
\r
2758 moment.locale('en', {
\r
2759 ordinal : function (number) {
\r
2760 var b = number % 10,
\r
2761 output = (toInt(number % 100 / 10) === 1) ? 'th' :
\r
2762 (b === 1) ? 'st' :
\r
2763 (b === 2) ? 'nd' :
\r
2764 (b === 3) ? 'rd' : 'th';
\r
2765 return number + output;
\r
2769 /* EMBED_LOCALES */
\r
2771 /************************************
\r
2773 ************************************/
\r
2775 function makeGlobal(shouldDeprecate) {
\r
2776 /*global ender:false */
\r
2777 if (typeof ender !== 'undefined') {
\r
2780 oldGlobalMoment = globalScope.moment;
\r
2781 if (shouldDeprecate) {
\r
2782 globalScope.moment = deprecate(
\r
2783 'Accessing Moment through the global scope is ' +
\r
2784 'deprecated, and will be removed in an upcoming ' +
\r
2788 globalScope.moment = moment;
\r
2792 // CommonJS module is defined
\r
2794 module.exports = moment;
\r
2795 } else if (typeof define === 'function' && define.amd) {
\r
2796 define('moment', function (require, exports, module) {
\r
2797 if (module.config && module.config() && module.config().noGlobal === true) {
\r
2798 // release the global variable
\r
2799 globalScope.moment = oldGlobalMoment;
\r