CLIENT GUI Framework
[vnfsdk/refrepo.git] / portal-common / src / main / webapp / common / thirdparty / bootstrap-daterangepicker / moment.js
1 //! moment.js\r
2 //! version : 2.8.1\r
3 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors\r
4 //! license : MIT\r
5 //! momentjs.com\r
6 \r
7 (function (undefined) {\r
8     /************************************\r
9         Constants\r
10     ************************************/\r
11 \r
12     var moment,\r
13         VERSION = '2.8.1',\r
14         // the global-scope this is NOT the global object in Node.js\r
15         globalScope = typeof global !== 'undefined' ? global : this,\r
16         oldGlobalMoment,\r
17         round = Math.round,\r
18         i,\r
19 \r
20         YEAR = 0,\r
21         MONTH = 1,\r
22         DATE = 2,\r
23         HOUR = 3,\r
24         MINUTE = 4,\r
25         SECOND = 5,\r
26         MILLISECOND = 6,\r
27 \r
28         // internal storage for locale config files\r
29         locales = {},\r
30 \r
31         // extra moment internal properties (plugins register props here)\r
32         momentProperties = [],\r
33 \r
34         // check for nodeJS\r
35         hasModule = (typeof module !== 'undefined' && module.exports),\r
36 \r
37         // ASP.NET json date format regex\r
38         aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,\r
39         aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,\r
40 \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
44 \r
45         // format tokens\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
48 \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
60 \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
68 \r
69         // iso 8601 regex\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
72 \r
73         isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',\r
74 \r
75         isoDates = [\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
81         ],\r
82 \r
83         // iso time formats and regexes\r
84         isoTimes = [\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
88             ['HH', /(T| )\d\d/]\r
89         ],\r
90 \r
91         // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]\r
92         parseTimezoneChunker = /([\+\-]|\d\d)/gi,\r
93 \r
94         // getter and setter names\r
95         proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),\r
96         unitMillisecondFactors = {\r
97             'Milliseconds' : 1,\r
98             'Seconds' : 1e3,\r
99             'Minutes' : 6e4,\r
100             'Hours' : 36e5,\r
101             'Days' : 864e5,\r
102             'Months' : 2592e6,\r
103             'Years' : 31536e6\r
104         },\r
105 \r
106         unitAliases = {\r
107             ms : 'millisecond',\r
108             s : 'second',\r
109             m : 'minute',\r
110             h : 'hour',\r
111             d : 'day',\r
112             D : 'date',\r
113             w : 'week',\r
114             W : 'isoWeek',\r
115             M : 'month',\r
116             Q : 'quarter',\r
117             y : 'year',\r
118             DDD : 'dayOfYear',\r
119             e : 'weekday',\r
120             E : 'isoWeekday',\r
121             gg: 'weekYear',\r
122             GG: 'isoWeekYear'\r
123         },\r
124 \r
125         camelFunctions = {\r
126             dayofyear : 'dayOfYear',\r
127             isoweekday : 'isoWeekday',\r
128             isoweek : 'isoWeek',\r
129             weekyear : 'weekYear',\r
130             isoweekyear : 'isoWeekYear'\r
131         },\r
132 \r
133         // format function strings\r
134         formatFunctions = {},\r
135 \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
143         },\r
144 \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
148 \r
149         formatTokenFunctions = {\r
150             M    : function () {\r
151                 return this.month() + 1;\r
152             },\r
153             MMM  : function (format) {\r
154                 return this.localeData().monthsShort(this, format);\r
155             },\r
156             MMMM : function (format) {\r
157                 return this.localeData().months(this, format);\r
158             },\r
159             D    : function () {\r
160                 return this.date();\r
161             },\r
162             DDD  : function () {\r
163                 return this.dayOfYear();\r
164             },\r
165             d    : function () {\r
166                 return this.day();\r
167             },\r
168             dd   : function (format) {\r
169                 return this.localeData().weekdaysMin(this, format);\r
170             },\r
171             ddd  : function (format) {\r
172                 return this.localeData().weekdaysShort(this, format);\r
173             },\r
174             dddd : function (format) {\r
175                 return this.localeData().weekdays(this, format);\r
176             },\r
177             w    : function () {\r
178                 return this.week();\r
179             },\r
180             W    : function () {\r
181                 return this.isoWeek();\r
182             },\r
183             YY   : function () {\r
184                 return leftZeroFill(this.year() % 100, 2);\r
185             },\r
186             YYYY : function () {\r
187                 return leftZeroFill(this.year(), 4);\r
188             },\r
189             YYYYY : function () {\r
190                 return leftZeroFill(this.year(), 5);\r
191             },\r
192             YYYYYY : function () {\r
193                 var y = this.year(), sign = y >= 0 ? '+' : '-';\r
194                 return sign + leftZeroFill(Math.abs(y), 6);\r
195             },\r
196             gg   : function () {\r
197                 return leftZeroFill(this.weekYear() % 100, 2);\r
198             },\r
199             gggg : function () {\r
200                 return leftZeroFill(this.weekYear(), 4);\r
201             },\r
202             ggggg : function () {\r
203                 return leftZeroFill(this.weekYear(), 5);\r
204             },\r
205             GG   : function () {\r
206                 return leftZeroFill(this.isoWeekYear() % 100, 2);\r
207             },\r
208             GGGG : function () {\r
209                 return leftZeroFill(this.isoWeekYear(), 4);\r
210             },\r
211             GGGGG : function () {\r
212                 return leftZeroFill(this.isoWeekYear(), 5);\r
213             },\r
214             e : function () {\r
215                 return this.weekday();\r
216             },\r
217             E : function () {\r
218                 return this.isoWeekday();\r
219             },\r
220             a    : function () {\r
221                 return this.localeData().meridiem(this.hours(), this.minutes(), true);\r
222             },\r
223             A    : function () {\r
224                 return this.localeData().meridiem(this.hours(), this.minutes(), false);\r
225             },\r
226             H    : function () {\r
227                 return this.hours();\r
228             },\r
229             h    : function () {\r
230                 return this.hours() % 12 || 12;\r
231             },\r
232             m    : function () {\r
233                 return this.minutes();\r
234             },\r
235             s    : function () {\r
236                 return this.seconds();\r
237             },\r
238             S    : function () {\r
239                 return toInt(this.milliseconds() / 100);\r
240             },\r
241             SS   : function () {\r
242                 return leftZeroFill(toInt(this.milliseconds() / 10), 2);\r
243             },\r
244             SSS  : function () {\r
245                 return leftZeroFill(this.milliseconds(), 3);\r
246             },\r
247             SSSS : function () {\r
248                 return leftZeroFill(this.milliseconds(), 3);\r
249             },\r
250             Z    : function () {\r
251                 var a = -this.zone(),\r
252                     b = '+';\r
253                 if (a < 0) {\r
254                     a = -a;\r
255                     b = '-';\r
256                 }\r
257                 return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);\r
258             },\r
259             ZZ   : function () {\r
260                 var a = -this.zone(),\r
261                     b = '+';\r
262                 if (a < 0) {\r
263                     a = -a;\r
264                     b = '-';\r
265                 }\r
266                 return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);\r
267             },\r
268             z : function () {\r
269                 return this.zoneAbbr();\r
270             },\r
271             zz : function () {\r
272                 return this.zoneName();\r
273             },\r
274             X    : function () {\r
275                 return this.unix();\r
276             },\r
277             Q : function () {\r
278                 return this.quarter();\r
279             }\r
280         },\r
281 \r
282         deprecations = {},\r
283 \r
284         lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];\r
285 \r
286     // Pick the first defined of two or three arguments. dfl comes from\r
287     // default.\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
293         }\r
294     }\r
295 \r
296     function defaultParsingFlags() {\r
297         // We need to deep clone this object, and es5 standard is not very\r
298         // helpful.\r
299         return {\r
300             empty : false,\r
301             unusedTokens : [],\r
302             unusedInput : [],\r
303             overflow : -2,\r
304             charsLeftOver : 0,\r
305             nullInput : false,\r
306             invalidMonth : null,\r
307             invalidFormat : false,\r
308             userInvalidated : false,\r
309             iso: false\r
310         };\r
311     }\r
312 \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
317         }\r
318     }\r
319 \r
320     function deprecate(msg, fn) {\r
321         var firstTime = true;\r
322         return extend(function () {\r
323             if (firstTime) {\r
324                 printMsg(msg);\r
325                 firstTime = false;\r
326             }\r
327             return fn.apply(this, arguments);\r
328         }, fn);\r
329     }\r
330 \r
331     function deprecateSimple(name, msg) {\r
332         if (!deprecations[name]) {\r
333             printMsg(msg);\r
334             deprecations[name] = true;\r
335         }\r
336     }\r
337 \r
338     function padToken(func, count) {\r
339         return function (a) {\r
340             return leftZeroFill(func.call(this, a), count);\r
341         };\r
342     }\r
343     function ordinalizeToken(func, period) {\r
344         return function (a) {\r
345             return this.localeData().ordinal(func.call(this, a), period);\r
346         };\r
347     }\r
348 \r
349     while (ordinalizeTokens.length) {\r
350         i = ordinalizeTokens.pop();\r
351         formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);\r
352     }\r
353     while (paddedTokens.length) {\r
354         i = paddedTokens.pop();\r
355         formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);\r
356     }\r
357     formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);\r
358 \r
359 \r
360     /************************************\r
361         Constructors\r
362     ************************************/\r
363 \r
364     function Locale() {\r
365     }\r
366 \r
367     // Moment prototype object\r
368     function Moment(config, skipOverflow) {\r
369         if (skipOverflow !== false) {\r
370             checkOverflow(config);\r
371         }\r
372         copyConfig(this, config);\r
373         this._d = new Date(+config._d);\r
374     }\r
375 \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
388 \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
397             weeks * 7;\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
400         // it separately.\r
401         this._months = +months +\r
402             quarters * 3 +\r
403             years * 12;\r
404 \r
405         this._data = {};\r
406 \r
407         this._locale = moment.localeData();\r
408 \r
409         this._bubble();\r
410     }\r
411 \r
412     /************************************\r
413         Helpers\r
414     ************************************/\r
415 \r
416 \r
417     function extend(a, b) {\r
418         for (var i in b) {\r
419             if (b.hasOwnProperty(i)) {\r
420                 a[i] = b[i];\r
421             }\r
422         }\r
423 \r
424         if (b.hasOwnProperty('toString')) {\r
425             a.toString = b.toString;\r
426         }\r
427 \r
428         if (b.hasOwnProperty('valueOf')) {\r
429             a.valueOf = b.valueOf;\r
430         }\r
431 \r
432         return a;\r
433     }\r
434 \r
435     function copyConfig(to, from) {\r
436         var i, prop, val;\r
437 \r
438         if (typeof from._isAMomentObject !== 'undefined') {\r
439             to._isAMomentObject = from._isAMomentObject;\r
440         }\r
441         if (typeof from._i !== 'undefined') {\r
442             to._i = from._i;\r
443         }\r
444         if (typeof from._f !== 'undefined') {\r
445             to._f = from._f;\r
446         }\r
447         if (typeof from._l !== 'undefined') {\r
448             to._l = from._l;\r
449         }\r
450         if (typeof from._strict !== 'undefined') {\r
451             to._strict = from._strict;\r
452         }\r
453         if (typeof from._tzm !== 'undefined') {\r
454             to._tzm = from._tzm;\r
455         }\r
456         if (typeof from._isUTC !== 'undefined') {\r
457             to._isUTC = from._isUTC;\r
458         }\r
459         if (typeof from._offset !== 'undefined') {\r
460             to._offset = from._offset;\r
461         }\r
462         if (typeof from._pf !== 'undefined') {\r
463             to._pf = from._pf;\r
464         }\r
465         if (typeof from._locale !== 'undefined') {\r
466             to._locale = from._locale;\r
467         }\r
468 \r
469         if (momentProperties.length > 0) {\r
470             for (i in momentProperties) {\r
471                 prop = momentProperties[i];\r
472                 val = from[prop];\r
473                 if (typeof val !== 'undefined') {\r
474                     to[prop] = val;\r
475                 }\r
476             }\r
477         }\r
478 \r
479         return to;\r
480     }\r
481 \r
482     function absRound(number) {\r
483         if (number < 0) {\r
484             return Math.ceil(number);\r
485         } else {\r
486             return Math.floor(number);\r
487         }\r
488     }\r
489 \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
495 \r
496         while (output.length < targetLength) {\r
497             output = '0' + output;\r
498         }\r
499         return (sign ? (forceSign ? '+' : '') : '-') + output;\r
500     }\r
501 \r
502     function positiveMomentsDifference(base, other) {\r
503         var res = {milliseconds: 0, months: 0};\r
504 \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
508             --res.months;\r
509         }\r
510 \r
511         res.milliseconds = +other - +(base.clone().add(res.months, 'M'));\r
512 \r
513         return res;\r
514     }\r
515 \r
516     function momentsDifference(base, other) {\r
517         var res;\r
518         other = makeAs(other, base);\r
519         if (base.isBefore(other)) {\r
520             res = positiveMomentsDifference(base, other);\r
521         } else {\r
522             res = positiveMomentsDifference(other, base);\r
523             res.milliseconds = -res.milliseconds;\r
524             res.months = -res.months;\r
525         }\r
526 \r
527         return res;\r
528     }\r
529 \r
530     // TODO: remove 'name' arg after deprecation is removed\r
531     function createAdder(direction, name) {\r
532         return function (val, period) {\r
533             var dur, tmp;\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
538             }\r
539 \r
540             val = typeof val === 'string' ? +val : val;\r
541             dur = moment.duration(val, period);\r
542             addOrSubtractDurationFromMoment(this, dur, direction);\r
543             return this;\r
544         };\r
545     }\r
546 \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
552 \r
553         if (milliseconds) {\r
554             mom._d.setTime(+mom._d + milliseconds * isAdding);\r
555         }\r
556         if (days) {\r
557             rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);\r
558         }\r
559         if (months) {\r
560             rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);\r
561         }\r
562         if (updateOffset) {\r
563             moment.updateOffset(mom, days || months);\r
564         }\r
565     }\r
566 \r
567     // check if is an array\r
568     function isArray(input) {\r
569         return Object.prototype.toString.call(input) === '[object Array]';\r
570     }\r
571 \r
572     function isDate(input) {\r
573         return Object.prototype.toString.call(input) === '[object Date]' ||\r
574             input instanceof Date;\r
575     }\r
576 \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
581             diffs = 0,\r
582             i;\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
586                 diffs++;\r
587             }\r
588         }\r
589         return diffs + lengthDiff;\r
590     }\r
591 \r
592     function normalizeUnits(units) {\r
593         if (units) {\r
594             var lowered = units.toLowerCase().replace(/(.)s$/, '$1');\r
595             units = unitAliases[units] || camelFunctions[lowered] || lowered;\r
596         }\r
597         return units;\r
598     }\r
599 \r
600     function normalizeObjectUnits(inputObject) {\r
601         var normalizedInput = {},\r
602             normalizedProp,\r
603             prop;\r
604 \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
610                 }\r
611             }\r
612         }\r
613 \r
614         return normalizedInput;\r
615     }\r
616 \r
617     function makeList(field) {\r
618         var count, setter;\r
619 \r
620         if (field.indexOf('week') === 0) {\r
621             count = 7;\r
622             setter = 'day';\r
623         }\r
624         else if (field.indexOf('month') === 0) {\r
625             count = 12;\r
626             setter = 'month';\r
627         }\r
628         else {\r
629             return;\r
630         }\r
631 \r
632         moment[field] = function (format, index) {\r
633             var i, getter,\r
634                 method = moment._locale[field],\r
635                 results = [];\r
636 \r
637             if (typeof format === 'number') {\r
638                 index = format;\r
639                 format = undefined;\r
640             }\r
641 \r
642             getter = function (i) {\r
643                 var m = moment().utc().set(setter, i);\r
644                 return method.call(moment._locale, m, format || '');\r
645             };\r
646 \r
647             if (index != null) {\r
648                 return getter(index);\r
649             }\r
650             else {\r
651                 for (i = 0; i < count; i++) {\r
652                     results.push(getter(i));\r
653                 }\r
654                 return results;\r
655             }\r
656         };\r
657     }\r
658 \r
659     function toInt(argumentForCoercion) {\r
660         var coercedNumber = +argumentForCoercion,\r
661             value = 0;\r
662 \r
663         if (coercedNumber !== 0 && isFinite(coercedNumber)) {\r
664             if (coercedNumber >= 0) {\r
665                 value = Math.floor(coercedNumber);\r
666             } else {\r
667                 value = Math.ceil(coercedNumber);\r
668             }\r
669         }\r
670 \r
671         return value;\r
672     }\r
673 \r
674     function daysInMonth(year, month) {\r
675         return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();\r
676     }\r
677 \r
678     function weeksInYear(year, dow, doy) {\r
679         return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;\r
680     }\r
681 \r
682     function daysInYear(year) {\r
683         return isLeapYear(year) ? 366 : 365;\r
684     }\r
685 \r
686     function isLeapYear(year) {\r
687         return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\r
688     }\r
689 \r
690     function checkOverflow(m) {\r
691         var overflow;\r
692         if (m._a && m._pf.overflow === -2) {\r
693             overflow =\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
700                 -1;\r
701 \r
702             if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {\r
703                 overflow = DATE;\r
704             }\r
705 \r
706             m._pf.overflow = overflow;\r
707         }\r
708     }\r
709 \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
714                 !m._pf.empty &&\r
715                 !m._pf.invalidMonth &&\r
716                 !m._pf.nullInput &&\r
717                 !m._pf.invalidFormat &&\r
718                 !m._pf.userInvalidated;\r
719 \r
720             if (m._strict) {\r
721                 m._isValid = m._isValid &&\r
722                     m._pf.charsLeftOver === 0 &&\r
723                     m._pf.unusedTokens.length === 0;\r
724             }\r
725         }\r
726         return m._isValid;\r
727     }\r
728 \r
729     function normalizeLocale(key) {\r
730         return key ? key.toLowerCase().replace('_', '-') : key;\r
731     }\r
732 \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
738 \r
739         while (i < names.length) {\r
740             split = normalizeLocale(names[i]).split('-');\r
741             j = split.length;\r
742             next = normalizeLocale(names[i + 1]);\r
743             next = next ? next.split('-') : null;\r
744             while (j > 0) {\r
745                 locale = loadLocale(split.slice(0, j).join('-'));\r
746                 if (locale) {\r
747                     return locale;\r
748                 }\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
751                     break;\r
752                 }\r
753                 j--;\r
754             }\r
755             i++;\r
756         }\r
757         return null;\r
758     }\r
759 \r
760     function loadLocale(name) {\r
761         var oldLocale = null;\r
762         if (!locales[name] && hasModule) {\r
763             try {\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
768             } catch (e) { }\r
769         }\r
770         return locales[name];\r
771     }\r
772 \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
777     }\r
778 \r
779     /************************************\r
780         Locale\r
781     ************************************/\r
782 \r
783 \r
784     extend(Locale.prototype, {\r
785 \r
786         set : function (config) {\r
787             var prop, i;\r
788             for (i in config) {\r
789                 prop = config[i];\r
790                 if (typeof prop === 'function') {\r
791                     this[i] = prop;\r
792                 } else {\r
793                     this['_' + i] = prop;\r
794                 }\r
795             }\r
796         },\r
797 \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
801         },\r
802 \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
806         },\r
807 \r
808         monthsParse : function (monthName) {\r
809             var i, mom, regex;\r
810 \r
811             if (!this._monthsParse) {\r
812                 this._monthsParse = [];\r
813             }\r
814 \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
821                 }\r
822                 // test the regex\r
823                 if (this._monthsParse[i].test(monthName)) {\r
824                     return i;\r
825                 }\r
826             }\r
827         },\r
828 \r
829         _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),\r
830         weekdays : function (m) {\r
831             return this._weekdays[m.day()];\r
832         },\r
833 \r
834         _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),\r
835         weekdaysShort : function (m) {\r
836             return this._weekdaysShort[m.day()];\r
837         },\r
838 \r
839         _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),\r
840         weekdaysMin : function (m) {\r
841             return this._weekdaysMin[m.day()];\r
842         },\r
843 \r
844         weekdaysParse : function (weekdayName) {\r
845             var i, mom, regex;\r
846 \r
847             if (!this._weekdaysParse) {\r
848                 this._weekdaysParse = [];\r
849             }\r
850 \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
857                 }\r
858                 // test the regex\r
859                 if (this._weekdaysParse[i].test(weekdayName)) {\r
860                     return i;\r
861                 }\r
862             }\r
863         },\r
864 \r
865         _longDateFormat : {\r
866             LT : 'h:mm A',\r
867             L : 'MM/DD/YYYY',\r
868             LL : 'MMMM D, YYYY',\r
869             LLL : 'MMMM D, YYYY LT',\r
870             LLLL : 'dddd, MMMM D, YYYY LT'\r
871         },\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
877                 });\r
878                 this._longDateFormat[key] = output;\r
879             }\r
880             return output;\r
881         },\r
882 \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
887         },\r
888 \r
889         _meridiemParse : /[ap]\.?m?\.?/i,\r
890         meridiem : function (hours, minutes, isLower) {\r
891             if (hours > 11) {\r
892                 return isLower ? 'pm' : 'PM';\r
893             } else {\r
894                 return isLower ? 'am' : 'AM';\r
895             }\r
896         },\r
897 \r
898         _calendar : {\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
904             sameElse : 'L'\r
905         },\r
906         calendar : function (key, mom) {\r
907             var output = this._calendar[key];\r
908             return typeof output === 'function' ? output.apply(mom) : output;\r
909         },\r
910 \r
911         _relativeTime : {\r
912             future : 'in %s',\r
913             past : '%s ago',\r
914             s : 'a few seconds',\r
915             m : 'a minute',\r
916             mm : '%d minutes',\r
917             h : 'an hour',\r
918             hh : '%d hours',\r
919             d : 'a day',\r
920             dd : '%d days',\r
921             M : 'a month',\r
922             MM : '%d months',\r
923             y : 'a year',\r
924             yy : '%d years'\r
925         },\r
926 \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
932         },\r
933 \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
937         },\r
938 \r
939         ordinal : function (number) {\r
940             return this._ordinal.replace('%d', number);\r
941         },\r
942         _ordinal : '%d',\r
943 \r
944         preparse : function (string) {\r
945             return string;\r
946         },\r
947 \r
948         postformat : function (string) {\r
949             return string;\r
950         },\r
951 \r
952         week : function (mom) {\r
953             return weekOfYear(mom, this._week.dow, this._week.doy).week;\r
954         },\r
955 \r
956         _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
959         },\r
960 \r
961         _invalidDate: 'Invalid date',\r
962         invalidDate: function () {\r
963             return this._invalidDate;\r
964         }\r
965     });\r
966 \r
967     /************************************\r
968         Formatting\r
969     ************************************/\r
970 \r
971 \r
972     function removeFormattingTokens(input) {\r
973         if (input.match(/\[[\s\S]/)) {\r
974             return input.replace(/^\[|\]$/g, '');\r
975         }\r
976         return input.replace(/\\/g, '');\r
977     }\r
978 \r
979     function makeFormatFunction(format) {\r
980         var array = format.match(formattingTokens), i, length;\r
981 \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
985             } else {\r
986                 array[i] = removeFormattingTokens(array[i]);\r
987             }\r
988         }\r
989 \r
990         return function (mom) {\r
991             var output = '';\r
992             for (i = 0; i < length; i++) {\r
993                 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];\r
994             }\r
995             return output;\r
996         };\r
997     }\r
998 \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
1003         }\r
1004 \r
1005         format = expandFormat(format, m.localeData());\r
1006 \r
1007         if (!formatFunctions[format]) {\r
1008             formatFunctions[format] = makeFormatFunction(format);\r
1009         }\r
1010 \r
1011         return formatFunctions[format](m);\r
1012     }\r
1013 \r
1014     function expandFormat(format, locale) {\r
1015         var i = 5;\r
1016 \r
1017         function replaceLongDateFormatTokens(input) {\r
1018             return locale.longDateFormat(input) || input;\r
1019         }\r
1020 \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
1025             i -= 1;\r
1026         }\r
1027 \r
1028         return format;\r
1029     }\r
1030 \r
1031 \r
1032     /************************************\r
1033         Parsing\r
1034     ************************************/\r
1035 \r
1036 \r
1037     // get the regex to find the next token\r
1038     function getParseRegexForToken(token, config) {\r
1039         var a, strict = config._strict;\r
1040         switch (token) {\r
1041         case 'Q':\r
1042             return parseTokenOneDigit;\r
1043         case 'DDDD':\r
1044             return parseTokenThreeDigits;\r
1045         case 'YYYY':\r
1046         case 'GGGG':\r
1047         case 'gggg':\r
1048             return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;\r
1049         case 'Y':\r
1050         case 'G':\r
1051         case 'g':\r
1052             return parseTokenSignedNumber;\r
1053         case 'YYYYYY':\r
1054         case 'YYYYY':\r
1055         case 'GGGGG':\r
1056         case 'ggggg':\r
1057             return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;\r
1058         case 'S':\r
1059             if (strict) {\r
1060                 return parseTokenOneDigit;\r
1061             }\r
1062             /* falls through */\r
1063         case 'SS':\r
1064             if (strict) {\r
1065                 return parseTokenTwoDigits;\r
1066             }\r
1067             /* falls through */\r
1068         case 'SSS':\r
1069             if (strict) {\r
1070                 return parseTokenThreeDigits;\r
1071             }\r
1072             /* falls through */\r
1073         case 'DDD':\r
1074             return parseTokenOneToThreeDigits;\r
1075         case 'MMM':\r
1076         case 'MMMM':\r
1077         case 'dd':\r
1078         case 'ddd':\r
1079         case 'dddd':\r
1080             return parseTokenWord;\r
1081         case 'a':\r
1082         case 'A':\r
1083             return config._locale._meridiemParse;\r
1084         case 'X':\r
1085             return parseTokenTimestampMs;\r
1086         case 'Z':\r
1087         case 'ZZ':\r
1088             return parseTokenTimezone;\r
1089         case 'T':\r
1090             return parseTokenT;\r
1091         case 'SSSS':\r
1092             return parseTokenDigits;\r
1093         case 'MM':\r
1094         case 'DD':\r
1095         case 'YY':\r
1096         case 'GG':\r
1097         case 'gg':\r
1098         case 'HH':\r
1099         case 'hh':\r
1100         case 'mm':\r
1101         case 'ss':\r
1102         case 'ww':\r
1103         case 'WW':\r
1104             return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;\r
1105         case 'M':\r
1106         case 'D':\r
1107         case 'd':\r
1108         case 'H':\r
1109         case 'h':\r
1110         case 'm':\r
1111         case 's':\r
1112         case 'w':\r
1113         case 'W':\r
1114         case 'e':\r
1115         case 'E':\r
1116             return parseTokenOneOrTwoDigits;\r
1117         case 'Do':\r
1118             return parseTokenOrdinal;\r
1119         default :\r
1120             a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), 'i'));\r
1121             return a;\r
1122         }\r
1123     }\r
1124 \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
1131 \r
1132         return parts[0] === '+' ? -minutes : minutes;\r
1133     }\r
1134 \r
1135     // function to convert string input to date\r
1136     function addTimeToArrayFromToken(token, input, config) {\r
1137         var a, datePartArray = config._a;\r
1138 \r
1139         switch (token) {\r
1140         // QUARTER\r
1141         case 'Q':\r
1142             if (input != null) {\r
1143                 datePartArray[MONTH] = (toInt(input) - 1) * 3;\r
1144             }\r
1145             break;\r
1146         // MONTH\r
1147         case 'M' : // fall through to MM\r
1148         case 'MM' :\r
1149             if (input != null) {\r
1150                 datePartArray[MONTH] = toInt(input) - 1;\r
1151             }\r
1152             break;\r
1153         case 'MMM' : // fall through to MMMM\r
1154         case 'MMMM' :\r
1155             a = config._locale.monthsParse(input);\r
1156             // if we didn't find a month name, mark the date as invalid.\r
1157             if (a != null) {\r
1158                 datePartArray[MONTH] = a;\r
1159             } else {\r
1160                 config._pf.invalidMonth = input;\r
1161             }\r
1162             break;\r
1163         // DAY OF MONTH\r
1164         case 'D' : // fall through to DD\r
1165         case 'DD' :\r
1166             if (input != null) {\r
1167                 datePartArray[DATE] = toInt(input);\r
1168             }\r
1169             break;\r
1170         case 'Do' :\r
1171             if (input != null) {\r
1172                 datePartArray[DATE] = toInt(parseInt(input, 10));\r
1173             }\r
1174             break;\r
1175         // DAY OF YEAR\r
1176         case 'DDD' : // fall through to DDDD\r
1177         case 'DDDD' :\r
1178             if (input != null) {\r
1179                 config._dayOfYear = toInt(input);\r
1180             }\r
1181 \r
1182             break;\r
1183         // YEAR\r
1184         case 'YY' :\r
1185             datePartArray[YEAR] = moment.parseTwoDigitYear(input);\r
1186             break;\r
1187         case 'YYYY' :\r
1188         case 'YYYYY' :\r
1189         case 'YYYYYY' :\r
1190             datePartArray[YEAR] = toInt(input);\r
1191             break;\r
1192         // AM / PM\r
1193         case 'a' : // fall through to A\r
1194         case 'A' :\r
1195             config._isPm = config._locale.isPM(input);\r
1196             break;\r
1197         // 24 HOUR\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
1201         case 'hh' :\r
1202             datePartArray[HOUR] = toInt(input);\r
1203             break;\r
1204         // MINUTE\r
1205         case 'm' : // fall through to mm\r
1206         case 'mm' :\r
1207             datePartArray[MINUTE] = toInt(input);\r
1208             break;\r
1209         // SECOND\r
1210         case 's' : // fall through to ss\r
1211         case 'ss' :\r
1212             datePartArray[SECOND] = toInt(input);\r
1213             break;\r
1214         // MILLISECOND\r
1215         case 'S' :\r
1216         case 'SS' :\r
1217         case 'SSS' :\r
1218         case 'SSSS' :\r
1219             datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);\r
1220             break;\r
1221         // UNIX TIMESTAMP WITH MS\r
1222         case 'X':\r
1223             config._d = new Date(parseFloat(input) * 1000);\r
1224             break;\r
1225         // TIMEZONE\r
1226         case 'Z' : // fall through to ZZ\r
1227         case 'ZZ' :\r
1228             config._useUTC = true;\r
1229             config._tzm = timezoneMinutesFromString(input);\r
1230             break;\r
1231         // WEEKDAY - human\r
1232         case 'dd':\r
1233         case 'ddd':\r
1234         case 'dddd':\r
1235             a = config._locale.weekdaysParse(input);\r
1236             // if we didn't get a weekday name, mark the date as invalid\r
1237             if (a != null) {\r
1238                 config._w = config._w || {};\r
1239                 config._w['d'] = a;\r
1240             } else {\r
1241                 config._pf.invalidWeekday = input;\r
1242             }\r
1243             break;\r
1244         // WEEK, WEEK DAY - numeric\r
1245         case 'w':\r
1246         case 'ww':\r
1247         case 'W':\r
1248         case 'WW':\r
1249         case 'd':\r
1250         case 'e':\r
1251         case 'E':\r
1252             token = token.substr(0, 1);\r
1253             /* falls through */\r
1254         case 'gggg':\r
1255         case 'GGGG':\r
1256         case 'GGGGG':\r
1257             token = token.substr(0, 2);\r
1258             if (input) {\r
1259                 config._w = config._w || {};\r
1260                 config._w[token] = toInt(input);\r
1261             }\r
1262             break;\r
1263         case 'gg':\r
1264         case 'GG':\r
1265             config._w = config._w || {};\r
1266             config._w[token] = moment.parseTwoDigitYear(input);\r
1267         }\r
1268     }\r
1269 \r
1270     function dayOfYearFromWeekInfo(config) {\r
1271         var w, weekYear, week, weekday, dow, doy, temp;\r
1272 \r
1273         w = config._w;\r
1274         if (w.GG != null || w.W != null || w.E != null) {\r
1275             dow = 1;\r
1276             doy = 4;\r
1277 \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
1281             // create now).\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
1285         } else {\r
1286             dow = config._locale._week.dow;\r
1287             doy = config._locale._week.doy;\r
1288 \r
1289             weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);\r
1290             week = dfl(w.w, 1);\r
1291 \r
1292             if (w.d != null) {\r
1293                 // weekday -- low day numbers are considered next week\r
1294                 weekday = w.d;\r
1295                 if (weekday < dow) {\r
1296                     ++week;\r
1297                 }\r
1298             } else if (w.e != null) {\r
1299                 // local weekday -- counting starts from begining of week\r
1300                 weekday = w.e + dow;\r
1301             } else {\r
1302                 // default to begining of week\r
1303                 weekday = dow;\r
1304             }\r
1305         }\r
1306         temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);\r
1307 \r
1308         config._a[YEAR] = temp.year;\r
1309         config._dayOfYear = temp.dayOfYear;\r
1310     }\r
1311 \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
1318 \r
1319         if (config._d) {\r
1320             return;\r
1321         }\r
1322 \r
1323         currentDate = currentDateArray(config);\r
1324 \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
1328         }\r
1329 \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
1333 \r
1334             if (config._dayOfYear > daysInYear(yearToUse)) {\r
1335                 config._pf._overflowDayOfYear = true;\r
1336             }\r
1337 \r
1338             date = makeUTCDate(yearToUse, 0, config._dayOfYear);\r
1339             config._a[MONTH] = date.getUTCMonth();\r
1340             config._a[DATE] = date.getUTCDate();\r
1341         }\r
1342 \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
1350         }\r
1351 \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
1355         }\r
1356 \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
1362         }\r
1363     }\r
1364 \r
1365     function dateFromObject(config) {\r
1366         var normalizedInput;\r
1367 \r
1368         if (config._d) {\r
1369             return;\r
1370         }\r
1371 \r
1372         normalizedInput = normalizeObjectUnits(config._i);\r
1373         config._a = [\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
1381         ];\r
1382 \r
1383         dateFromConfig(config);\r
1384     }\r
1385 \r
1386     function currentDateArray(config) {\r
1387         var now = new Date();\r
1388         if (config._useUTC) {\r
1389             return [\r
1390                 now.getUTCFullYear(),\r
1391                 now.getUTCMonth(),\r
1392                 now.getUTCDate()\r
1393             ];\r
1394         } else {\r
1395             return [now.getFullYear(), now.getMonth(), now.getDate()];\r
1396         }\r
1397     }\r
1398 \r
1399     // date from string and format string\r
1400     function makeDateFromStringAndFormat(config) {\r
1401         if (config._f === moment.ISO_8601) {\r
1402             parseISO(config);\r
1403             return;\r
1404         }\r
1405 \r
1406         config._a = [];\r
1407         config._pf.empty = true;\r
1408 \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
1414 \r
1415         tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];\r
1416 \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
1424                 }\r
1425                 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);\r
1426                 totalParsedInputLength += parsedInput.length;\r
1427             }\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
1432                 }\r
1433                 else {\r
1434                     config._pf.unusedTokens.push(token);\r
1435                 }\r
1436                 addTimeToArrayFromToken(token, parsedInput, config);\r
1437             }\r
1438             else if (config._strict && !parsedInput) {\r
1439                 config._pf.unusedTokens.push(token);\r
1440             }\r
1441         }\r
1442 \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
1447         }\r
1448 \r
1449         // handle am pm\r
1450         if (config._isPm && config._a[HOUR] < 12) {\r
1451             config._a[HOUR] += 12;\r
1452         }\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
1456         }\r
1457 \r
1458         dateFromConfig(config);\r
1459         checkOverflow(config);\r
1460     }\r
1461 \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
1465         });\r
1466     }\r
1467 \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
1471     }\r
1472 \r
1473     // date from string and array of format strings\r
1474     function makeDateFromStringAndArray(config) {\r
1475         var tempConfig,\r
1476             bestMoment,\r
1477 \r
1478             scoreToBeat,\r
1479             i,\r
1480             currentScore;\r
1481 \r
1482         if (config._f.length === 0) {\r
1483             config._pf.invalidFormat = true;\r
1484             config._d = new Date(NaN);\r
1485             return;\r
1486         }\r
1487 \r
1488         for (i = 0; i < config._f.length; i++) {\r
1489             currentScore = 0;\r
1490             tempConfig = copyConfig({}, config);\r
1491             tempConfig._pf = defaultParsingFlags();\r
1492             tempConfig._f = config._f[i];\r
1493             makeDateFromStringAndFormat(tempConfig);\r
1494 \r
1495             if (!isValid(tempConfig)) {\r
1496                 continue;\r
1497             }\r
1498 \r
1499             // if there is any input that was not parsed add a penalty for that format\r
1500             currentScore += tempConfig._pf.charsLeftOver;\r
1501 \r
1502             //or tokens\r
1503             currentScore += tempConfig._pf.unusedTokens.length * 10;\r
1504 \r
1505             tempConfig._pf.score = currentScore;\r
1506 \r
1507             if (scoreToBeat == null || currentScore < scoreToBeat) {\r
1508                 scoreToBeat = currentScore;\r
1509                 bestMoment = tempConfig;\r
1510             }\r
1511         }\r
1512 \r
1513         extend(config, bestMoment || tempConfig);\r
1514     }\r
1515 \r
1516     // date from iso format\r
1517     function parseISO(config) {\r
1518         var i, l,\r
1519             string = config._i,\r
1520             match = isoRegex.exec(string);\r
1521 \r
1522         if (match) {\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
1528                     break;\r
1529                 }\r
1530             }\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
1534                     break;\r
1535                 }\r
1536             }\r
1537             if (string.match(parseTokenTimezone)) {\r
1538                 config._f += 'Z';\r
1539             }\r
1540             makeDateFromStringAndFormat(config);\r
1541         } else {\r
1542             config._isValid = false;\r
1543         }\r
1544     }\r
1545 \r
1546     // date from iso format or fallback\r
1547     function makeDateFromString(config) {\r
1548         parseISO(config);\r
1549         if (config._isValid === false) {\r
1550             delete config._isValid;\r
1551             moment.createFromInputFallback(config);\r
1552         }\r
1553     }\r
1554 \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
1573         } else {\r
1574             moment.createFromInputFallback(config);\r
1575         }\r
1576     }\r
1577 \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
1582 \r
1583         //the date constructor doesn't accept years < 1970\r
1584         if (y < 1970) {\r
1585             date.setFullYear(y);\r
1586         }\r
1587         return date;\r
1588     }\r
1589 \r
1590     function makeUTCDate(y) {\r
1591         var date = new Date(Date.UTC.apply(null, arguments));\r
1592         if (y < 1970) {\r
1593             date.setUTCFullYear(y);\r
1594         }\r
1595         return date;\r
1596     }\r
1597 \r
1598     function parseWeekday(input, locale) {\r
1599         if (typeof input === 'string') {\r
1600             if (!isNaN(input)) {\r
1601                 input = parseInt(input, 10);\r
1602             }\r
1603             else {\r
1604                 input = locale.weekdaysParse(input);\r
1605                 if (typeof input !== 'number') {\r
1606                     return null;\r
1607                 }\r
1608             }\r
1609         }\r
1610         return input;\r
1611     }\r
1612 \r
1613     /************************************\r
1614         Relative Time\r
1615     ************************************/\r
1616 \r
1617 \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
1621     }\r
1622 \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
1631 \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
1642 \r
1643         args[2] = withoutSuffix;\r
1644         args[3] = +posNegDuration > 0;\r
1645         args[4] = locale;\r
1646         return substituteTimeAgo.apply({}, args);\r
1647     }\r
1648 \r
1649 \r
1650     /************************************\r
1651         Week of Year\r
1652     ************************************/\r
1653 \r
1654 \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
1665             adjustedMoment;\r
1666 \r
1667 \r
1668         if (daysToDayOfWeek > end) {\r
1669             daysToDayOfWeek -= 7;\r
1670         }\r
1671 \r
1672         if (daysToDayOfWeek < end - 7) {\r
1673             daysToDayOfWeek += 7;\r
1674         }\r
1675 \r
1676         adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');\r
1677         return {\r
1678             week: Math.ceil(adjustedMoment.dayOfYear() / 7),\r
1679             year: adjustedMoment.year()\r
1680         };\r
1681     }\r
1682 \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
1686 \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
1691 \r
1692         return {\r
1693             year: dayOfYear > 0 ? year : year - 1,\r
1694             dayOfYear: dayOfYear > 0 ?  dayOfYear : daysInYear(year - 1) + dayOfYear\r
1695         };\r
1696     }\r
1697 \r
1698     /************************************\r
1699         Top Level Functions\r
1700     ************************************/\r
1701 \r
1702     function makeMoment(config) {\r
1703         var input = config._i,\r
1704             format = config._f;\r
1705 \r
1706         config._locale = config._locale || moment.localeData(config._l);\r
1707 \r
1708         if (input === null || (format === undefined && input === '')) {\r
1709             return moment.invalid({nullInput: true});\r
1710         }\r
1711 \r
1712         if (typeof input === 'string') {\r
1713             config._i = input = config._locale.preparse(input);\r
1714         }\r
1715 \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
1721             } else {\r
1722                 makeDateFromStringAndFormat(config);\r
1723             }\r
1724         } else {\r
1725             makeDateFromInput(config);\r
1726         }\r
1727 \r
1728         return new Moment(config);\r
1729     }\r
1730 \r
1731     moment = function (input, format, locale, strict) {\r
1732         var c;\r
1733 \r
1734         if (typeof(locale) === "boolean") {\r
1735             strict = locale;\r
1736             locale = undefined;\r
1737         }\r
1738         // object construction must be done this way.\r
1739         // https://github.com/moment/moment/issues/1423\r
1740         c = {};\r
1741         c._isAMomentObject = true;\r
1742         c._i = input;\r
1743         c._f = format;\r
1744         c._l = locale;\r
1745         c._strict = strict;\r
1746         c._isUTC = false;\r
1747         c._pf = defaultParsingFlags();\r
1748 \r
1749         return makeMoment(c);\r
1750     };\r
1751 \r
1752     moment.suppressDeprecationWarnings = false;\r
1753 \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
1761         }\r
1762     );\r
1763 \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
1766     //\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
1770         var res, i;\r
1771         if (moments.length === 1 && isArray(moments[0])) {\r
1772             moments = moments[0];\r
1773         }\r
1774         if (!moments.length) {\r
1775             return moment();\r
1776         }\r
1777         res = moments[0];\r
1778         for (i = 1; i < moments.length; ++i) {\r
1779             if (moments[i][fn](res)) {\r
1780                 res = moments[i];\r
1781             }\r
1782         }\r
1783         return res;\r
1784     }\r
1785 \r
1786     moment.min = function () {\r
1787         var args = [].slice.call(arguments, 0);\r
1788 \r
1789         return pickBy('isBefore', args);\r
1790     };\r
1791 \r
1792     moment.max = function () {\r
1793         var args = [].slice.call(arguments, 0);\r
1794 \r
1795         return pickBy('isAfter', args);\r
1796     };\r
1797 \r
1798     // creating with utc\r
1799     moment.utc = function (input, format, locale, strict) {\r
1800         var c;\r
1801 \r
1802         if (typeof(locale) === "boolean") {\r
1803             strict = locale;\r
1804             locale = undefined;\r
1805         }\r
1806         // object construction must be done this way.\r
1807         // https://github.com/moment/moment/issues/1423\r
1808         c = {};\r
1809         c._isAMomentObject = true;\r
1810         c._useUTC = true;\r
1811         c._isUTC = true;\r
1812         c._l = locale;\r
1813         c._i = input;\r
1814         c._f = format;\r
1815         c._strict = strict;\r
1816         c._pf = defaultParsingFlags();\r
1817 \r
1818         return makeMoment(c).utc();\r
1819     };\r
1820 \r
1821     // creating with unix timestamp (in seconds)\r
1822     moment.unix = function (input) {\r
1823         return moment(input * 1000);\r
1824     };\r
1825 \r
1826     // duration\r
1827     moment.duration = function (input, key) {\r
1828         var duration = input,\r
1829             // matching against regexp is expensive, do it on demand\r
1830             match = null,\r
1831             sign,\r
1832             ret,\r
1833             parseIso,\r
1834             diffRes;\r
1835 \r
1836         if (moment.isDuration(input)) {\r
1837             duration = {\r
1838                 ms: input._milliseconds,\r
1839                 d: input._days,\r
1840                 M: input._months\r
1841             };\r
1842         } else if (typeof input === 'number') {\r
1843             duration = {};\r
1844             if (key) {\r
1845                 duration[key] = input;\r
1846             } else {\r
1847                 duration.milliseconds = input;\r
1848             }\r
1849         } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {\r
1850             sign = (match[1] === '-') ? -1 : 1;\r
1851             duration = {\r
1852                 y: 0,\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
1858             };\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
1868             };\r
1869             duration = {\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
1877             };\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
1881 \r
1882             duration = {};\r
1883             duration.ms = diffRes.milliseconds;\r
1884             duration.M = diffRes.months;\r
1885         }\r
1886 \r
1887         ret = new Duration(duration);\r
1888 \r
1889         if (moment.isDuration(input) && input.hasOwnProperty('_locale')) {\r
1890             ret._locale = input._locale;\r
1891         }\r
1892 \r
1893         return ret;\r
1894     };\r
1895 \r
1896     // version number\r
1897     moment.version = VERSION;\r
1898 \r
1899     // default format\r
1900     moment.defaultFormat = isoFormat;\r
1901 \r
1902     // constant that refers to the ISO standard\r
1903     moment.ISO_8601 = function () {};\r
1904 \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
1908 \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
1912 \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
1916             return false;\r
1917         }\r
1918         if (limit === undefined) {\r
1919             return relativeTimeThresholds[threshold];\r
1920         }\r
1921         relativeTimeThresholds[threshold] = limit;\r
1922         return true;\r
1923     };\r
1924 \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
1929         }\r
1930     );\r
1931 \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
1934     // locale key.\r
1935     moment.locale = function (key, values) {\r
1936         var data;\r
1937         if (key) {\r
1938             if (typeof(values) !== "undefined") {\r
1939                 data = moment.defineLocale(key, values);\r
1940             }\r
1941             else {\r
1942                 data = moment.localeData(key);\r
1943             }\r
1944 \r
1945             if (data) {\r
1946                 moment.duration._locale = moment._locale = data;\r
1947             }\r
1948         }\r
1949 \r
1950         return moment._locale._abbr;\r
1951     };\r
1952 \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
1958             }\r
1959             locales[name].set(values);\r
1960 \r
1961             // backwards compat for now: also set the locale\r
1962             moment.locale(name);\r
1963 \r
1964             return locales[name];\r
1965         } else {\r
1966             // useful for testing\r
1967             delete locales[name];\r
1968             return null;\r
1969         }\r
1970     };\r
1971 \r
1972     moment.langData = deprecate(\r
1973         "moment.langData is deprecated. Use moment.localeData instead.",\r
1974         function (key) {\r
1975             return moment.localeData(key);\r
1976         }\r
1977     );\r
1978 \r
1979     // returns locale data\r
1980     moment.localeData = function (key) {\r
1981         var locale;\r
1982 \r
1983         if (key && key._locale && key._locale._abbr) {\r
1984             key = key._locale._abbr;\r
1985         }\r
1986 \r
1987         if (!key) {\r
1988             return moment._locale;\r
1989         }\r
1990 \r
1991         if (!isArray(key)) {\r
1992             //short-circuit everything else\r
1993             locale = loadLocale(key);\r
1994             if (locale) {\r
1995                 return locale;\r
1996             }\r
1997             key = [key];\r
1998         }\r
1999 \r
2000         return chooseLocale(key);\r
2001     };\r
2002 \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
2007     };\r
2008 \r
2009     // for typechecking Duration objects\r
2010     moment.isDuration = function (obj) {\r
2011         return obj instanceof Duration;\r
2012     };\r
2013 \r
2014     for (i = lists.length - 1; i >= 0; --i) {\r
2015         makeList(lists[i]);\r
2016     }\r
2017 \r
2018     moment.normalizeUnits = function (units) {\r
2019         return normalizeUnits(units);\r
2020     };\r
2021 \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
2026         }\r
2027         else {\r
2028             m._pf.userInvalidated = true;\r
2029         }\r
2030 \r
2031         return m;\r
2032     };\r
2033 \r
2034     moment.parseZone = function () {\r
2035         return moment.apply(null, arguments).parseZone();\r
2036     };\r
2037 \r
2038     moment.parseTwoDigitYear = function (input) {\r
2039         return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);\r
2040     };\r
2041 \r
2042     /************************************\r
2043         Moment Prototype\r
2044     ************************************/\r
2045 \r
2046 \r
2047     extend(moment.fn = Moment.prototype, {\r
2048 \r
2049         clone : function () {\r
2050             return moment(this);\r
2051         },\r
2052 \r
2053         valueOf : function () {\r
2054             return +this._d + ((this._offset || 0) * 60000);\r
2055         },\r
2056 \r
2057         unix : function () {\r
2058             return Math.floor(+this / 1000);\r
2059         },\r
2060 \r
2061         toString : function () {\r
2062             return this.clone().locale('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");\r
2063         },\r
2064 \r
2065         toDate : function () {\r
2066             return this._offset ? new Date(+this) : this._d;\r
2067         },\r
2068 \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
2073             } else {\r
2074                 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');\r
2075             }\r
2076         },\r
2077 \r
2078         toArray : function () {\r
2079             var m = this;\r
2080             return [\r
2081                 m.year(),\r
2082                 m.month(),\r
2083                 m.date(),\r
2084                 m.hours(),\r
2085                 m.minutes(),\r
2086                 m.seconds(),\r
2087                 m.milliseconds()\r
2088             ];\r
2089         },\r
2090 \r
2091         isValid : function () {\r
2092             return isValid(this);\r
2093         },\r
2094 \r
2095         isDSTShifted : function () {\r
2096             if (this._a) {\r
2097                 return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;\r
2098             }\r
2099 \r
2100             return false;\r
2101         },\r
2102 \r
2103         parsingFlags : function () {\r
2104             return extend({}, this._pf);\r
2105         },\r
2106 \r
2107         invalidAt: function () {\r
2108             return this._pf.overflow;\r
2109         },\r
2110 \r
2111         utc : function (keepLocalTime) {\r
2112             return this.zone(0, keepLocalTime);\r
2113         },\r
2114 \r
2115         local : function (keepLocalTime) {\r
2116             if (this._isUTC) {\r
2117                 this.zone(0, keepLocalTime);\r
2118                 this._isUTC = false;\r
2119 \r
2120                 if (keepLocalTime) {\r
2121                     this.add(this._d.getTimezoneOffset(), 'm');\r
2122                 }\r
2123             }\r
2124             return this;\r
2125         },\r
2126 \r
2127         format : function (inputString) {\r
2128             var output = formatMoment(this, inputString || moment.defaultFormat);\r
2129             return this.localeData().postformat(output);\r
2130         },\r
2131 \r
2132         add : createAdder(1, 'add'),\r
2133 \r
2134         subtract : createAdder(-1, 'subtract'),\r
2135 \r
2136         diff : function (input, units, asFloat) {\r
2137             var that = makeAs(input, this),\r
2138                 zoneDiff = (this.zone() - that.zone()) * 6e4,\r
2139                 diff, output;\r
2140 \r
2141             units = normalizeUnits(units);\r
2142 \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
2157                 }\r
2158             } else {\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
2165                     diff;\r
2166             }\r
2167             return asFloat ? output : absRound(output);\r
2168         },\r
2169 \r
2170         from : function (time, withoutSuffix) {\r
2171             return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);\r
2172         },\r
2173 \r
2174         fromNow : function (withoutSuffix) {\r
2175             return this.from(moment(), withoutSuffix);\r
2176         },\r
2177 \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
2191         },\r
2192 \r
2193         isLeapYear : function () {\r
2194             return isLeapYear(this.year());\r
2195         },\r
2196 \r
2197         isDST : function () {\r
2198             return (this.zone() < this.clone().month(0).zone() ||\r
2199                 this.zone() < this.clone().month(5).zone());\r
2200         },\r
2201 \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
2207             } else {\r
2208                 return day;\r
2209             }\r
2210         },\r
2211 \r
2212         month : makeAccessor('Month', true),\r
2213 \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
2218             switch (units) {\r
2219             case 'year':\r
2220                 this.month(0);\r
2221                 /* falls through */\r
2222             case 'quarter':\r
2223             case 'month':\r
2224                 this.date(1);\r
2225                 /* falls through */\r
2226             case 'week':\r
2227             case 'isoWeek':\r
2228             case 'day':\r
2229                 this.hours(0);\r
2230                 /* falls through */\r
2231             case 'hour':\r
2232                 this.minutes(0);\r
2233                 /* falls through */\r
2234             case 'minute':\r
2235                 this.seconds(0);\r
2236                 /* falls through */\r
2237             case 'second':\r
2238                 this.milliseconds(0);\r
2239                 /* falls through */\r
2240             }\r
2241 \r
2242             // weeks are a special case\r
2243             if (units === 'week') {\r
2244                 this.weekday(0);\r
2245             } else if (units === 'isoWeek') {\r
2246                 this.isoWeekday(1);\r
2247             }\r
2248 \r
2249             // quarters are also special\r
2250             if (units === 'quarter') {\r
2251                 this.month(Math.floor(this.month() / 3) * 3);\r
2252             }\r
2253 \r
2254             return this;\r
2255         },\r
2256 \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
2260         },\r
2261 \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
2265         },\r
2266 \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
2270         },\r
2271 \r
2272         isSame: function (input, units) {\r
2273             units = units || 'ms';\r
2274             return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);\r
2275         },\r
2276 \r
2277         min: deprecate(\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
2282                  }\r
2283          ),\r
2284 \r
2285         max: deprecate(\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
2290                 }\r
2291         ),\r
2292 \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
2297         //\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
2305                 localAdjust;\r
2306             if (input != null) {\r
2307                 if (typeof input === 'string') {\r
2308                     input = timezoneMinutesFromString(input);\r
2309                 }\r
2310                 if (Math.abs(input) < 16) {\r
2311                     input = input * 60;\r
2312                 }\r
2313                 if (!this._isUTC && keepLocalTime) {\r
2314                     localAdjust = this._d.getTimezoneOffset();\r
2315                 }\r
2316                 this._offset = input;\r
2317                 this._isUTC = true;\r
2318                 if (localAdjust != null) {\r
2319                     this.subtract(localAdjust, 'm');\r
2320                 }\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
2329                     }\r
2330                 }\r
2331             } else {\r
2332                 return this._isUTC ? offset : this._d.getTimezoneOffset();\r
2333             }\r
2334             return this;\r
2335         },\r
2336 \r
2337         zoneAbbr : function () {\r
2338             return this._isUTC ? 'UTC' : '';\r
2339         },\r
2340 \r
2341         zoneName : function () {\r
2342             return this._isUTC ? 'Coordinated Universal Time' : '';\r
2343         },\r
2344 \r
2345         parseZone : function () {\r
2346             if (this._tzm) {\r
2347                 this.zone(this._tzm);\r
2348             } else if (typeof this._i === 'string') {\r
2349                 this.zone(this._i);\r
2350             }\r
2351             return this;\r
2352         },\r
2353 \r
2354         hasAlignedHourOffset : function (input) {\r
2355             if (!input) {\r
2356                 input = 0;\r
2357             }\r
2358             else {\r
2359                 input = moment(input).zone();\r
2360             }\r
2361 \r
2362             return (this.zone() - input) % 60 === 0;\r
2363         },\r
2364 \r
2365         daysInMonth : function () {\r
2366             return daysInMonth(this.year(), this.month());\r
2367         },\r
2368 \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
2372         },\r
2373 \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
2376         },\r
2377 \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
2381         },\r
2382 \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
2386         },\r
2387 \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
2391         },\r
2392 \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
2396         },\r
2397 \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
2401         },\r
2402 \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
2408         },\r
2409 \r
2410         isoWeeksInYear : function () {\r
2411             return weeksInYear(this.year(), 1, 4);\r
2412         },\r
2413 \r
2414         weeksInYear : function () {\r
2415             var weekInfo = this.localeData()._week;\r
2416             return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);\r
2417         },\r
2418 \r
2419         get : function (units) {\r
2420             units = normalizeUnits(units);\r
2421             return this[units]();\r
2422         },\r
2423 \r
2424         set : function (units, value) {\r
2425             units = normalizeUnits(units);\r
2426             if (typeof this[units] === 'function') {\r
2427                 this[units](value);\r
2428             }\r
2429             return this;\r
2430         },\r
2431 \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
2438             } else {\r
2439                 this._locale = moment.localeData(key);\r
2440                 return this;\r
2441             }\r
2442         },\r
2443 \r
2444         lang : deprecate(\r
2445             "moment().lang() is deprecated. Use moment().localeData() instead.",\r
2446             function (key) {\r
2447                 if (key === undefined) {\r
2448                     return this.localeData();\r
2449                 } else {\r
2450                     this._locale = moment.localeData(key);\r
2451                     return this;\r
2452                 }\r
2453             }\r
2454         ),\r
2455 \r
2456         localeData : function () {\r
2457             return this._locale;\r
2458         }\r
2459     });\r
2460 \r
2461     function rawMonthSetter(mom, value) {\r
2462         var dayOfMonth;\r
2463 \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
2469                 return mom;\r
2470             }\r
2471         }\r
2472 \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
2476         return mom;\r
2477     }\r
2478 \r
2479     function rawGetter(mom, unit) {\r
2480         return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();\r
2481     }\r
2482 \r
2483     function rawSetter(mom, unit, value) {\r
2484         if (unit === 'Month') {\r
2485             return rawMonthSetter(mom, value);\r
2486         } else {\r
2487             return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);\r
2488         }\r
2489     }\r
2490 \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
2496                 return this;\r
2497             } else {\r
2498                 return rawGetter(this, unit);\r
2499             }\r
2500         };\r
2501     }\r
2502 \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
2509     // this rule.\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
2516 \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
2523 \r
2524     // add aliased format methods\r
2525     moment.fn.toJSON = moment.fn.toISOString;\r
2526 \r
2527     /************************************\r
2528         Duration Prototype\r
2529     ************************************/\r
2530 \r
2531 \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
2535     }\r
2536 \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
2541     }\r
2542 \r
2543     extend(moment.duration.fn = Duration.prototype, {\r
2544 \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
2551 \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
2555 \r
2556             seconds = absRound(milliseconds / 1000);\r
2557             data.seconds = seconds % 60;\r
2558 \r
2559             minutes = absRound(seconds / 60);\r
2560             data.minutes = minutes % 60;\r
2561 \r
2562             hours = absRound(minutes / 60);\r
2563             data.hours = hours % 24;\r
2564 \r
2565             days += absRound(hours / 24);\r
2566 \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
2570 \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
2574             days %= 30;\r
2575 \r
2576             // 12 months -> 1 year\r
2577             years += absRound(months / 12);\r
2578             months %= 12;\r
2579 \r
2580             data.days = days;\r
2581             data.months = months;\r
2582             data.years = years;\r
2583         },\r
2584 \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
2589 \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
2596 \r
2597             return this;\r
2598         },\r
2599 \r
2600         weeks : function () {\r
2601             return absRound(this.days() / 7);\r
2602         },\r
2603 \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
2609         },\r
2610 \r
2611         humanize : function (withSuffix) {\r
2612             var output = relativeTime(this, !withSuffix, this.localeData());\r
2613 \r
2614             if (withSuffix) {\r
2615                 output = this.localeData().pastFuture(+this, output);\r
2616             }\r
2617 \r
2618             return this.localeData().postformat(output);\r
2619         },\r
2620 \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
2624 \r
2625             this._milliseconds += dur._milliseconds;\r
2626             this._days += dur._days;\r
2627             this._months += dur._months;\r
2628 \r
2629             this._bubble();\r
2630 \r
2631             return this;\r
2632         },\r
2633 \r
2634         subtract : function (input, val) {\r
2635             var dur = moment.duration(input, val);\r
2636 \r
2637             this._milliseconds -= dur._milliseconds;\r
2638             this._days -= dur._days;\r
2639             this._months -= dur._months;\r
2640 \r
2641             this._bubble();\r
2642 \r
2643             return this;\r
2644         },\r
2645 \r
2646         get : function (units) {\r
2647             units = normalizeUnits(units);\r
2648             return this[units.toLowerCase() + 's']();\r
2649         },\r
2650 \r
2651         as : function (units) {\r
2652             var days, months;\r
2653             units = normalizeUnits(units);\r
2654 \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
2659             } else {\r
2660                 days += yearsToDays(this._months / 12);\r
2661                 switch (units) {\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
2669                 }\r
2670             }\r
2671         },\r
2672 \r
2673         lang : moment.fn.lang,\r
2674         locale : moment.fn.locale,\r
2675 \r
2676         toIsoString : deprecate(\r
2677             "toIsoString() is deprecated. Please use toISOString() instead " +\r
2678             "(notice the capitals)",\r
2679             function () {\r
2680                 return this.toISOString();\r
2681             }\r
2682         ),\r
2683 \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
2692 \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
2696                 return 'P0D';\r
2697             }\r
2698 \r
2699             return (this.asSeconds() < 0 ? '-' : '') +\r
2700                 'P' +\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
2708         },\r
2709 \r
2710         localeData : function () {\r
2711             return this._locale;\r
2712         }\r
2713     });\r
2714 \r
2715     function makeDurationGetter(name) {\r
2716         moment.duration.fn[name] = function () {\r
2717             return this._data[name];\r
2718         };\r
2719     }\r
2720 \r
2721     for (i in unitMillisecondFactors) {\r
2722         if (unitMillisecondFactors.hasOwnProperty(i)) {\r
2723             makeDurationGetter(i.toLowerCase());\r
2724         }\r
2725     }\r
2726 \r
2727     moment.duration.fn.asMilliseconds = function () {\r
2728         return this.as('ms');\r
2729     };\r
2730     moment.duration.fn.asSeconds = function () {\r
2731         return this.as('s');\r
2732     };\r
2733     moment.duration.fn.asMinutes = function () {\r
2734         return this.as('m');\r
2735     };\r
2736     moment.duration.fn.asHours = function () {\r
2737         return this.as('h');\r
2738     };\r
2739     moment.duration.fn.asDays = function () {\r
2740         return this.as('d');\r
2741     };\r
2742     moment.duration.fn.asWeeks = function () {\r
2743         return this.as('weeks');\r
2744     };\r
2745     moment.duration.fn.asMonths = function () {\r
2746         return this.as('M');\r
2747     };\r
2748     moment.duration.fn.asYears = function () {\r
2749         return this.as('y');\r
2750     };\r
2751 \r
2752     /************************************\r
2753         Default Locale\r
2754     ************************************/\r
2755 \r
2756 \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
2766         }\r
2767     });\r
2768 \r
2769     /* EMBED_LOCALES */\r
2770 \r
2771     /************************************\r
2772         Exposing Moment\r
2773     ************************************/\r
2774 \r
2775     function makeGlobal(shouldDeprecate) {\r
2776         /*global ender:false */\r
2777         if (typeof ender !== 'undefined') {\r
2778             return;\r
2779         }\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
2785                     'release.',\r
2786                     moment);\r
2787         } else {\r
2788             globalScope.moment = moment;\r
2789         }\r
2790     }\r
2791 \r
2792     // CommonJS module is defined\r
2793     if (hasModule) {\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
2800             }\r
2801 \r
2802             return moment;\r
2803         });\r
2804         makeGlobal(true);\r
2805     } else {\r
2806         makeGlobal();\r
2807     }\r
2808 }).call(this);