PageSourceSearch

https://portmeirion.wales/js/datepicker-xs.js?ver=2026092412

js portmeirion.wales collected 2026-09-24 11:18:24 UTC 114,115 bytes, 3,184 lines download raw bytes

1/*! UIkit 2.26.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2(function(addon) {
3
4    var component;
5
6    if (window.UIkit) {
7        component = addon(UIkit);
8    }
9
10    if (typeof define == "function" && define.amd) {
11        define("uikit-datepicker", ["uikit"], function(){
12            return component || addon(UIkit);
13        });
14    }
15
16})(function(UI){
17
18    "use strict";
19
20    // Datepicker
21
22    var active = false, dropdown, moment;
23
24    UI.component('datepicker', {
25
26        defaults: {
27            mobile: false,
28            weekstart: 1,
29            i18n: {
30                months        : ['January','February','March','April','May','June','July','August','September','October','November','December'],
31                weekdays      : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
32            },
33            format: "YYYY-MM-DD",
34            offsettop: 5,
35            maxDate: false,
36            minDate: false,
37            pos: 'auto',
38            template: function(data, opts) {
39
40                var content = '', i;
41
42                content += '<div class="xsuk-datepicker-nav">';
43                content += '<a href="" class="xsuk-datepicker-previous"></a>';
44                content += '<a href="" class="xsuk-datepicker-next"></a>';
45
46                if (UI.formSelect) {
47
48                    var currentyear = (new Date()).getFullYear(), options = [], months, years, minYear, maxYear;
49
50                    for (i=0;i<opts.i18n.months.length;i++) {
51                        if(i==data.month) {
52                            options.push('<option value="'+i+'" selected>'+opts.i18n.months[i]+'</option>');
53                        } else {
54                            options.push('<option value="'+i+'">'+opts.i18n.months[i]+'</option>');
55                        }
56                    }
57
58                    months = '<span class="xsuk-form-select">'+ opts.i18n.months[data.month] + '<select class="update-picker-month">'+options.join('')+'</select></span>';
59
60                    // --
61
62                    options = [];
63
64                    minYear = data.minDate ? data.minDate.year() : currentyear - 50;
65                    maxYear = data.maxDate ? data.maxDate.year() : currentyear + 20;
66
67                    for (i=minYear;i<=maxYear;i++) {
68                        if (i == data.year) {
69                            options.push('<option value="'+i+'" selected>'+i+'</option>');
70                        } else {
71                            options.push('<option value="'+i+'">'+i+'</option>');
72                        }
73                    }
74
75                    years  = '<span class="xsuk-form-select">'+ data.year + '<select class="update-picker-year">'+options.join('')+'</select></span>';
76
77                    content += '<div class="xsuk-datepicker-heading">'+ months + ' ' + years +'</div>';
78
79                } else {
80                    content += '<div class="xsuk-datepicker-heading">'+ opts.i18n.months[data.month] +' '+ data.year+'</div>';
81                }
82
83                content += '</div>';
84
85                content += '<table class="xsuk-datepicker-table">';
86                content += '<thead>';
87                for(i = 0; i < data.weekdays.length; i++) {
88                    if (data.weekdays[i]) {
89                        content += '<th>'+data.weekdays[i]+'</th>';
90                    }
91                }
92                content += '</thead>';
93
94                content += '<tbody>';
95                for(i = 0; i < data.days.length; i++) {
96                    if (data.days[i] && data.days[i].length){
97                        content += '<tr>';
98                        for(var d = 0; d < data.days[i].length; d++) {
99                            if (data.days[i][d]) {
100                                var day = data.days[i][d],
101                                    cls = [];
102
103                                if(!day.inmonth) cls.push("xsuk-datepicker-table-muted");
104                                if(day.selected) cls.push("xsuk-active");
105                                if(day.disabled) cls.push('xsuk-datepicker-date-disabled xsuk-datepicker-table-muted');
106
107                                content += '<td><a href="" class="'+cls.join(" ")+'" data-date="'+day.day.format()+'">'+day.day.format("D")+'</a></td>';
108                            }
109                        }
110                        content += '</tr>';
111                    }
112                }
113                content += '</tbody>';
114
115                content += '</table>';
116
117                return content;
118            }
119        },
120
121        boot: function() {
122
123            UI.$win.on("resize orientationchange", function() {
124
125                if (active) {
126                    active.hide();
127                }
128            });
129
130            // init code
131            UI.$html.on("focus.datepicker.uikit", "[data-xsuk-datepicker]", function(e) {
132
133                var ele = UI.$(this);
134
135                if (!ele.data("datepicker")) {
136                    e.preventDefault();
137                    UI.datepicker(ele, UI.Utils.options(ele.attr("data-xsuk-datepicker")));
138                    ele.trigger("focus");
139                }
140
141            });
142
143            UI.$html.on("click focus", '*', function(e) {
144
145                var target = UI.$(e.target);
146
147                if (active && target[0] != dropdown[0] && !target.data("datepicker") && !target.parents(".xsuk-datepicker:first").length) {
148                    active.hide();
149                }
150            });
151        },
152
153        init: function() {
154            // use native datepicker on touch devices
155            if (UI.support.touch && this.element.attr('type')=='date' && !this.options.mobile) {
156                return;
157            }
158
159            var $this = this;
160
161            this.current  = this.element.val() ? moment(this.element.val(), this.options.format) : moment();
162
163            this.on("click focus", function(){
164                if (active!==$this) $this.pick(this.value ? this.value:($this.options.minDate ? $this.options.minDate :''), $($this.element[0]).parent()[0].id);
165            }).on("change", function(){
166
167                if ($this.element.val() && !moment($this.element.val(), $this.options.format).isValid()) {
168                   $this.element.val(moment().format($this.options.format));
169                }
170            });
171
172            // init dropdown
173            // if (!dropdown) {
174
175                dropdown = UI.$('<div class="xsuk-dropdown xsuk-datepicker"></div>');
176
177                dropdown.on("click", ".xsuk-datepicker-next, .xsuk-datepicker-previous, [data-date]", function(e){
178
179                    e.stopPropagation();
180                    e.preventDefault();
181
182                    var ele = UI.$(this);
183
184                    if (ele.hasClass('xsuk-datepicker-date-disabled')) return false;
185
186                    if (ele.is('[data-date]')) {
187                        active.current = moment(ele.data("date"));
188                        active.element.val(active.current.isValid() ? active.current.format(active.options.format) : null).trigger("change");
189                        active.hide();
190                    } else {
191                       active.add((ele.hasClass("xsuk-datepicker-next") ? 1:-1), "months");
192                    }
193                });
194
195                dropdown.on('change', '.update-picker-month, .update-picker-year', function(){
196
197                    var select = UI.$(this);
198                    active[select.is('.update-picker-year') ? 'setYear':'setMonth'](Number(select.val()));
199                });
200
201                var parentId = $($this.element[0]).parent()[0].id;
202                dropdown.appendTo('#' + parentId);
203
204                // dropdown.appendTo("#xsuk_datepicker");
205                // dropdown.appendTo("#xsuk_datepicker_page");
206            // } else {
207            //     console.log(dropdown);
208            // }
209        },
210
211        pick: function(initdate, parentId) {
212            
213            dropdown = UI.$('#'+parentId + ' .xsuk-dropdown');
214
215            var offset = this.element.offset(),
216                css    = {"left": offset.left, "right":""};
217
218            this.current  = isNaN(initdate) ? moment(initdate, this.options.format):moment();
219            this.initdate = this.current.format("YYYY-MM-DD");
220
221            this.update();
222
223            if (UI.langdirection == 'right') {
224                css.right = window.innerWidth - (css.left + this.element.outerWidth());
225                css.left  = "";
226            }
227
228            var posTop    = (offset.top - this.element.outerHeight() + this.element.height()) - this.options.offsettop - dropdown.outerHeight(),
229                posBottom = offset.top + this.element.outerHeight() + this.options.offsettop;
230
231            css.top = posBottom;
232
233            if (this.options.pos == 'top') {
234                css.top = posTop;
235            } else if(this.options.pos == 'auto' && (window.innerHeight - posBottom - dropdown.outerHeight() < 0 && posTop >= 0) ) {
236                css.top = posTop;
237            }
238
239            dropdown.css(css).show();
240            this.trigger('show.uk.datepicker');
241
242            active = this;
243        },
244
245        add: function(unit, value) {
246            this.current.add(unit, value);
247            this.update();
248        },
249
250        setMonth: function(month) {
251            this.current.month(month);
252            this.update();
253        },
254
255        setYear: function(year) {
256            this.current.year(year);
257            this.update();
258        },
259
260        update: function() {
261
262            var data = this.getRows(this.current.year(), this.current.month()),
263                tpl  = this.options.template(data, this.options);
264
265            dropdown.html(tpl);
266
267            this.trigger('update.uk.datepicker');
268        },
269
270        getRows: function(year, month) {
271
272            var opts   = this.options,
273                now    = moment().format('YYYY-MM-DD'),
274                days   = [31, (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month],
275                before = new Date(year, month, 1, 12).getDay(),
276                data   = {"month":month, "year":year,"weekdays":[],"days":[], "maxDate": false, "minDate": false},
277                row    = [];
278
279            if (opts.maxDate!==false){
280                data.maxDate = isNaN(opts.maxDate) ? moment(opts.maxDate, opts.format) : moment().add(opts.maxDate, 'days');
281            }
282
283            if (opts.minDate!==false){
284                data.minDate = isNaN(opts.minDate) ? moment(opts.minDate, opts.format) : moment().add(opts.minDate-1, 'days');
285            }
286
287            data.weekdays = (function(){
288
289                for (var i=0, arr=[]; i < 7; i++) {
290
291                    var day = i + (opts.weekstart || 0);
292
293                    while (day >= 7) {
294                        day -= 7;
295                    }
296
297                    arr.push(opts.i18n.weekdays[day]);
298                }
299
300                return arr;
301            })();
302
303            if (opts.weekstart && opts.weekstart > 0) {
304                before -= opts.weekstart;
305                if (before < 0) {
306                    before += 7;
307                }
308            }
309
310            var cells = days + before, after = cells;
311
312            while(after > 7) { after -= 7; }
313
314            cells += 7 - after;
315
316            var day, isDisabled, isSelected, isToday, isInMonth;
317
318            for (var i = 0, r = 0; i < cells; i++) {
319
320                day        = new Date(year, month, 1 + (i - before), 12);
321                isDisabled = (data.minDate && data.minDate > day) || (data.maxDate && day > data.maxDate);
322                isInMonth  = !(i < before || i >= (days + before));
323
324				if ($('#accomodationType').val() == "PMLTDSELF") {
325					if ($('#noNights').val() == 3) {
326						if (day.getDay() !== 5) { isDisabled = true; }
327					} else if ($('#noNights').val() == 4) {
328						if (day.getDay() !== 1) { isDisabled = true; }
329					} else if ($('#noNights').val() == 7) {
330						if (day.getDay() == 1 || day.getDay() == 5) { isDisabled = false; } else { isDisabled = true; }
331					}
332				}
333				
334                day = moment(day);
335
336                isSelected = this.initdate == day.format("YYYY-MM-DD");
337                isToday    = now == day.format("YYYY-MM-DD");
338
339                row.push({"selected": isSelected, "today": isToday, "disabled": isDisabled, "day":day, "inmonth":isInMonth});
340
341                if (++r === 7) {
342                    data.days.push(row);
343                    row = [];
344                    r = 0;
345                }
346            }
347
348            return data;
349        },
350
351        hide: function() {
352
353            if (active && active === this) {
354                dropdown.hide();
355                active = false;
356
357                this.trigger('hide.uk.datepicker');
358            }
359        }
360    });
361
362    //! moment.js
363    //! version : 2.8.3
364    //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
365    //! license : MIT
366    //! momentjs.com
367
368    moment = (function (undefined) {
369        /************************************
370            Constants
371        ************************************/
372        var moment,
373            VERSION = '2.8.3',
374            // the global-scope this is NOT the global object in Node.js
375            globalScope = typeof global !== 'undefined' ? global : this,
376            oldGlobalMoment,
377            round = Math.round,
378            hasOwnProperty = Object.prototype.hasOwnProperty,
379            i,
380
381            YEAR = 0,
382            MONTH = 1,
383            DATE = 2,
384            HOUR = 3,
385            MINUTE = 4,
386            SECOND = 5,
387            MILLISECOND = 6,
388
389            // internal storage for locale config files
390            locales = {},
391
392            // extra moment internal properties (plugins register props here)
393            momentProperties = [],
394
395            // check for nodeJS
396            hasModule = (typeof module !== 'undefined' && module.exports),
397
398            // ASP.NET json date format regex
399            aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
400            aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
401
402            // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
403            // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
404            isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
405
406            // format tokens
407            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,
408            localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
409
410            // parsing token regexes
411            parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
412            parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
413            parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
414            parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
415            parseTokenDigits = /\d+/, // nonzero number of digits
416            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.
417            parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
418            parseTokenT = /T/i, // T (ISO separator)
419            parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
420            parseTokenOrdinal = /\d{1,2}/,
421
422            //strict parsing regexes
423            parseTokenOneDigit = /\d/, // 0 - 9
424            parseTokenTwoDigits = /\d\d/, // 00 - 99
425            parseTokenThreeDigits = /\d{3}/, // 000 - 999
426            parseTokenFourDigits = /\d{4}/, // 0000 - 9999
427            parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
428            parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
429
430            // iso 8601 regex
431            // 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)
432            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)?)?$/,
433
434            isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
435
436            isoDates = [
437                ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
438                ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
439                ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
440                ['GGGG-[W]WW', /\d{4}-W\d{2}/],
441                ['YYYY-DDD', /\d{4}-\d{3}/]
442            ],
443
444            // iso time formats and regexes
445            isoTimes = [
446                ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
447                ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
448                ['HH:mm', /(T| )\d\d:\d\d/],
449                ['HH', /(T| )\d\d/]
450            ],
451
452            // timezone chunker '+10:00' > ['10', '00'] or '-1530' > ['-15', '30']
453            parseTimezoneChunker = /([\+\-]|\d\d)/gi,
454
455            // getter and setter names
456            proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
457            unitMillisecondFactors = {
458                'Milliseconds' : 1,
459                'Seconds' : 1e3,
460                'Minutes' : 6e4,
461                'Hours' : 36e5,
462                'Days' : 864e5,
463                'Months' : 2592e6,
464                'Years' : 31536e6
465            },
466
467            unitAliases = {
468                ms : 'millisecond',
469                s : 'second',
470                m : 'minute',
471                h : 'hour',
472                d : 'day',
473                D : 'date',
474                w : 'week',
475                W : 'isoWeek',
476                M : 'month',
477                Q : 'quarter',
478                y : 'year',
479                DDD : 'dayOfYear',
480                e : 'weekday',
481                E : 'isoWeekday',
482                gg: 'weekYear',
483                GG: 'isoWeekYear'
484            },
485
486            camelFunctions = {
487                dayofyear : 'dayOfYear',
488                isoweekday : 'isoWeekday',
489                isoweek : 'isoWeek',
490                weekyear : 'weekYear',
491                isoweekyear : 'isoWeekYear'
492            },
493
494            // format function strings
495            formatFunctions = {},
496
497            // default relative time thresholds
498            relativeTimeThresholds = {
499                s: 45,  // seconds to minute
500                m: 45,  // minutes to hour
501                h: 22,  // hours to day
502                d: 26,  // days to month
503                M: 11   // months to year
504            },
505
506            // tokens to ordinalize and pad
507            ordinalizeTokens = 'DDD w W M D d'.split(' '),
508            paddedTokens = 'M D H h m s w W'.split(' '),
509
510            formatTokenFunctions = {
511                M    : function () {
512                    return this.month() + 1;
513                },
514                MMM  : function (format) {
515                    return this.localeData().monthsShort(this, format);
516                },
517                MMMM : function (format) {
518                    return this.localeData().months(this, format);
519                },
520                D    : function () {
521                    return this.date();
522                },
523                DDD  : function () {
524                    return this.dayOfYear();
525                },
526                d    : function () {
527                    return this.day();
528                },
529                dd   : function (format) {
530                    return this.localeData().weekdaysMin(this, format);
531                },
532                ddd  : function (format) {
533                    return this.localeData().weekdaysShort(this, format);
534                },
535                dddd : function (format) {
536                    return this.localeData().weekdays(this, format);
537                },
538                w    : function () {
539                    return this.week();
540                },
541                W    : function () {
542                    return this.isoWeek();
543                },
544                YY   : function () {
545                    return leftZeroFill(this.year() % 100, 2);
546                },
547                YYYY : function () {
548                    return leftZeroFill(this.year(), 4);
549                },
550                YYYYY : function () {
551                    return leftZeroFill(this.year(), 5);
552                },
553                YYYYYY : function () {
554                    var y = this.year(), sign = y >= 0 ? '+' : '-';
555                    return sign + leftZeroFill(Math.abs(y), 6);
556                },
557                gg   : function () {
558                    return leftZeroFill(this.weekYear() % 100, 2);
559                },
560                gggg : function () {
561                    return leftZeroFill(this.weekYear(), 4);
562                },
563                ggggg : function () {
564                    return leftZeroFill(this.weekYear(), 5);
565                },
566                GG   : function () {
567                    return leftZeroFill(this.isoWeekYear() % 100, 2);
568                },
569                GGGG : function () {
570                    return leftZeroFill(this.isoWeekYear(), 4);
571                },
572                GGGGG : function () {
573                    return leftZeroFill(this.isoWeekYear(), 5);
574                },
575                e : function () {
576                    return this.weekday();
577                },
578                E : function () {
579                    return this.isoWeekday();
580                },
581                a    : function () {
582                    return this.localeData().meridiem(this.hours(), this.minutes(), true);
583                },
584                A    : function () {
585                    return this.localeData().meridiem(this.hours(), this.minutes(), false);
586                },
587                H    : function () {
588                    return this.hours();
589                },
590                h    : function () {
591                    return this.hours() % 12 || 12;
592                },
593                m    : function () {
594                    return this.minutes();
595                },
596                s    : function () {
597                    return this.seconds();
598                },
599                S    : function () {
600                    return toInt(this.milliseconds() / 100);
601                },
602                SS   : function () {
603                    return leftZeroFill(toInt(this.milliseconds() / 10), 2);
604                },
605                SSS  : function () {
606                    return leftZeroFill(this.milliseconds(), 3);
607                },
608                SSSS : function () {
609                    return leftZeroFill(this.milliseconds(), 3);
610                },
611                Z    : function () {
612                    var a = -this.zone(),
613                        b = '+';
614                    if (a < 0) {
615                        a = -a;
616                        b = '-';
617                    }
618                    return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);
619                },
620                ZZ   : function () {
621                    var a = -this.zone(),
622                        b = '+';
623                    if (a < 0) {
624                        a = -a;
625                        b = '-';
626                    }
627                    return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
628                },
629                z : function () {
630                    return this.zoneAbbr();
631                },
632                zz : function () {
633                    return this.zoneName();
634                },
635                X    : function () {
636                    return this.unix();
637                },
638                Q : function () {
639                    return this.quarter();
640                }
641            },
642
643            deprecations = {},
644
645            lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
646
647        // Pick the first defined of two or three arguments. dfl comes from
648        // default.
649        function dfl(a, b, c) {
650            switch (arguments.length) {
651                case 2: return a != null ? a : b;
652                case 3: return a != null ? a : b != null ? b : c;
653                default: throw new Error('Implement me');
654            }
655        }
656
657        function hasOwnProp(a, b) {
658            return hasOwnProperty.call(a, b);
659        }
660
661        function defaultParsingFlags() {
662            // We need to deep clone this object, and es5 standard is not very
663            // helpful.
664            return {
665                empty : false,
666                unusedTokens : [],
667                unusedInput : [],
668                overflow : -2,
669                charsLeftOver : 0,
670                nullInput : false,
671                invalidMonth : null,
672                invalidFormat : false,
673                userInvalidated : false,
674                iso: false
675            };
676        }
677
678        function printMsg(msg) {
679            if (moment.suppressDeprecationWarnings === false &&
680                    typeof console !== 'undefined' && console.warn) {
681                console.warn('Deprecation warning: ' + msg);
682            }
683        }
684
685        function deprecate(msg, fn) {
686            var firstTime = true;
687            return extend(function () {
688                if (firstTime) {
689                    printMsg(msg);
690                    firstTime = false;
691                }
692                return fn.apply(this, arguments);
693            }, fn);
694        }
695
696        function deprecateSimple(name, msg) {
697            if (!deprecations[name]) {
698                printMsg(msg);
699                deprecations[name] = true;
700            }
701        }
702
703        function padToken(func, count) {
704            return function (a) {
705                return leftZeroFill(func.call(this, a), count);
706            };
707        }
708        function ordinalizeToken(func, period) {
709            return function (a) {
710                return this.localeData().ordinal(func.call(this, a), period);
711            };
712        }
713
714        while (ordinalizeTokens.length) {
715            i = ordinalizeTokens.pop();
716            formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
717        }
718        while (paddedTokens.length) {
719            i = paddedTokens.pop();
720            formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
721        }
722        formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
723
724
725        /************************************
726            Constructors
727        ************************************/
728
729        function Locale() {
730        }
731
732        // Moment prototype object
733        function Moment(config, skipOverflow) {
734            if (skipOverflow !== false) {
735                checkOverflow(config);
736            }
737            copyConfig(this, config);
738            this._d = new Date(+config._d);
739        }
740
741        // Duration Constructor
742        function Duration(duration) {
743            var normalizedInput = normalizeObjectUnits(duration),
744                years = normalizedInput.year || 0,
745                quarters = normalizedInput.quarter || 0,
746                months = normalizedInput.month || 0,
747                weeks = normalizedInput.week || 0,
748                days = normalizedInput.day || 0,
749                hours = normalizedInput.hour || 0,
750                minutes = normalizedInput.minute || 0,
751                seconds = normalizedInput.second || 0,
752                milliseconds = normalizedInput.millisecond || 0;
753
754            // representation for dateAddRemove
755            this._milliseconds = +milliseconds +
756                seconds * 1e3 + // 1000
757                minutes * 6e4 + // 1000 * 60
758                hours * 36e5; // 1000 * 60 * 60
759            // Because of dateAddRemove treats 24 hours as different from a
760            // day when working around DST, we need to store them separately
761            this._days = +days +
762                weeks * 7;
763            // It is impossible translate months into days without knowing
764            // which months you are are talking about, so we have to store
765            // it separately.
766            this._months = +months +
767                quarters * 3 +
768                years * 12;
769
770            this._data = {};
771
772            this._locale = moment.localeData();
773
774            this._bubble();
775        }
776
777        /************************************
778            Helpers
779        ************************************/
780
781
782        function extend(a, b) {
783            for (var i in b) {
784                if (hasOwnProp(b, i)) {
785                    a[i] = b[i];
786                }
787            }
788
789            if (hasOwnProp(b, 'toString')) {
790                a.toString = b.toString;
791            }
792
793            if (hasOwnProp(b, 'valueOf')) {
794                a.valueOf = b.valueOf;
795            }
796
797            return a;
798        }
799
800        function copyConfig(to, from) {
801            var i, prop, val;
802
803            if (typeof from._isAMomentObject !== 'undefined') {
804                to._isAMomentObject = from._isAMomentObject;
805            }
806            if (typeof from._i !== 'undefined') {
807                to._i = from._i;
808            }
809            if (typeof from._f !== 'undefined') {
810                to._f = from._f;
811            }
812            if (typeof from._l !== 'undefined') {
813                to._l = from._l;
814            }
815            if (typeof from._strict !== 'undefined') {
816                to._strict = from._strict;
817            }
818            if (typeof from._tzm !== 'undefined') {
819                to._tzm = from._tzm;
820            }
821            if (typeof from._isUTC !== 'undefined') {
822                to._isUTC = from._isUTC;
823            }
824            if (typeof from._offset !== 'undefined') {
825                to._offset = from._offset;
826            }
827            if (typeof from._pf !== 'undefined') {
828                to._pf = from._pf;
829            }
830            if (typeof from._locale !== 'undefined') {
831                to._locale = from._locale;
832            }
833
834            if (momentProperties.length > 0) {
835                for (i in momentProperties) {
836                    prop = momentProperties[i];
837                    val = from[prop];
838                    if (typeof val !== 'undefined') {
839                        to[prop] = val;
840                    }
841                }
842            }
843
844            return to;
845        }
846
847        function absRound(number) {
848            if (number < 0) {
849                return Math.ceil(number);
850            } else {
851                return Math.floor(number);
852            }
853        }
854
855        // left zero fill a number
856        // see http://jsperf.com/left-zero-filling for performance comparison
857        function leftZeroFill(number, targetLength, forceSign) {
858            var output = '' + Math.abs(number),
859                sign = number >= 0;
860
861            while (output.length < targetLength) {
862                output = '0' + output;
863            }
864            return (sign ? (forceSign ? '+' : '') : '-') + output;
865        }
866
867        function positiveMomentsDifference(base, other) {
868            var res = {milliseconds: 0, months: 0};
869
870            res.months = other.month() - base.month() +
871                (other.year() - base.year()) * 12;
872            if (base.clone().add(res.months, 'M').isAfter(other)) {
873                --res.months;
874            }
875
876            res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
877
878            return res;
879        }
880
881        function momentsDifference(base, other) {
882            var res;
883            other = makeAs(other, base);
884            if (base.isBefore(other)) {
885                res = positiveMomentsDifference(base, other);
886            } else {
887                res = positiveMomentsDifference(other, base);
888                res.milliseconds = -res.milliseconds;
889                res.months = -res.months;
890            }
891
892            return res;
893        }
894
895        // TODO: remove 'name' arg after deprecation is removed
896        function createAdder(direction, name) {
897            return function (val, period) {
898                var dur, tmp;
899                //invert the arguments, but complain about it
900                if (period !== null && !isNaN(+period)) {
901                    deprecateSimple(name, 'moment().' + name  + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
902                    tmp = val; val = period; period = tmp;
903                }
904
905                val = typeof val === 'string' ? +val : val;
906                dur = moment.duration(val, period);
907                addOrSubtractDurationFromMoment(this, dur, direction);
908                return this;
909            };
910        }
911
912        function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {
913            var milliseconds = duration._milliseconds,
914                days = duration._days,
915                months = duration._months;
916            updateOffset = updateOffset == null ? true : updateOffset;
917
918            if (milliseconds) {
919                mom._d.setTime(+mom._d + milliseconds * isAdding);
920            }
921            if (days) {
922                rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);
923            }
924            if (months) {
925                rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);
926            }
927            if (updateOffset) {
928                moment.updateOffset(mom, days || months);
929            }
930        }
931
932        // check if is an array
933        function isArray(input) {
934            return Object.prototype.toString.call(input) === '[object Array]';
935        }
936
937        function isDate(input) {
938            return Object.prototype.toString.call(input) === '[object Date]' ||
939                input instanceof Date;
940        }
941
942        // compare two arrays, return the number of differences
943        function compareArrays(array1, array2, dontConvert) {
944            var len = Math.min(array1.length, array2.length),
945                lengthDiff = Math.abs(array1.length - array2.length),
946                diffs = 0,
947                i;
948            for (i = 0; i < len; i++) {
949                if ((dontConvert && array1[i] !== array2[i]) ||
950                    (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
951                    diffs++;
952                }
953            }
954            return diffs + lengthDiff;
955        }
956
957        function normalizeUnits(units) {
958            if (units) {
959                var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
960                units = unitAliases[units] || camelFunctions[lowered] || lowered;
961            }
962            return units;
963        }
964
965        function normalizeObjectUnits(inputObject) {
966            var normalizedInput = {},
967                normalizedProp,
968                prop;
969
970            for (prop in inputObject) {
971                if (hasOwnProp(inputObject, prop)) {
972                    normalizedProp = normalizeUnits(prop);
973                    if (normalizedProp) {
974                        normalizedInput[normalizedProp] = inputObject[prop];
975                    }
976                }
977            }
978
979            return normalizedInput;
980        }
981
982        function makeList(field) {
983            var count, setter;
984
985            if (field.indexOf('week') === 0) {
986                count = 7;
987                setter = 'day';
988            }
989            else if (field.indexOf('month') === 0) {
990                count = 12;
991                setter = 'month';
992            }
993            else {
994                return;
995            }
996
997            moment[field] = function (format, index) {
998                var i, getter,
999                    method = moment._locale[field],
1000                    results = [];
1001
1002                if (typeof format === 'number') {
1003                    index = format;
1004                    format = undefined;
1005                }
1006
1007                getter = function (i) {
1008                    var m = moment().utc().set(setter, i);
1009                    return method.call(moment._locale, m, format || '');
1010                };
1011
1012                if (index != null) {
1013                    return getter(index);
1014                }
1015                else {
1016                    for (i = 0; i < count; i++) {
1017                        results.push(getter(i));
1018                    }
1019                    return results;
1020                }
1021            };
1022        }
1023
1024        function toInt(argumentForCoercion) {
1025            var coercedNumber = +argumentForCoercion,
1026                value = 0;
1027
1028            if (coercedNumber !== 0 && isFinite(coercedNumber)) {
1029                if (coercedNumber >= 0) {
1030                    value = Math.floor(coercedNumber);
1031                } else {
1032                    value = Math.ceil(coercedNumber);
1033                }
1034            }
1035
1036            return value;
1037        }
1038
1039        function daysInMonth(year, month) {
1040            return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
1041        }
1042
1043        function weeksInYear(year, dow, doy) {
1044            return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;
1045        }
1046
1047        function daysInYear(year) {
1048            return isLeapYear(year) ? 366 : 365;
1049        }
1050
1051        function isLeapYear(year) {
1052            return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
1053        }
1054
1055        function checkOverflow(m) {
1056            var overflow;
1057            if (m._a && m._pf.overflow === -2) {
1058                overflow =
1059                    m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
1060                    m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
1061                    m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
1062                    m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
1063                    m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
1064                    m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
1065                    -1;
1066
1067                if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
1068                    overflow = DATE;
1069                }
1070
1071                m._pf.overflow = overflow;
1072            }
1073        }
1074
1075        function isValid(m) {
1076            if (m._isValid == null) {
1077                m._isValid = !isNaN(m._d.getTime()) &&
1078                    m._pf.overflow < 0 &&
1079                    !m._pf.empty &&
1080                    !m._pf.invalidMonth &&
1081                    !m._pf.nullInput &&
1082                    !m._pf.invalidFormat &&
1083                    !m._pf.userInvalidated;
1084
1085                if (m._strict) {
1086                    m._isValid = m._isValid &&
1087                        m._pf.charsLeftOver === 0 &&
1088                        m._pf.unusedTokens.length === 0;
1089                }
1090            }
1091            return m._isValid;
1092        }
1093
1094        function normalizeLocale(key) {
1095            return key ? key.toLowerCase().replace('_', '-') : key;
1096        }
1097
1098        // pick the locale from the array
1099        // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list tr
1099ying each
1100        // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
1101        function chooseLocale(names) {
1102            var i = 0, j, next, locale, split;
1103
1104            while (i < names.length) {
1105                split = normalizeLocale(names[i]).split('-');
1106                j = split.length;
1107                next = normalizeLocale(names[i + 1]);
1108                next = next ? next.split('-') : null;
1109                while (j > 0) {
1110                    locale = loadLocale(split.slice(0, j).join('-'));
1111                    if (locale) {
1112                        return locale;
1113                    }
1114                    if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
1115                        //the next array item is better than a shallower substring of this one
1116                        break;
1117                    }
1118                    j--;
1119                }
1120                i++;
1121            }
1122            return null;
1123        }
1124
1125        function loadLocale(name) {
1126            var oldLocale = null;
1127            if (!locales[name] && hasModule) {
1128                try {
1129                    oldLocale = moment.locale();
1130                    require('./locale/' + name);
1131                    // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales
1132                    moment.locale(oldLocale);
1133                } catch (e) { }
1134            }
1135            return locales[name];
1136        }
1137
1138        // Return a moment from input, that is local/utc/zone equivalent to model.
1139        function makeAs(input, model) {
1140            return model._isUTC ? moment(input).zone(model._offset || 0) :
1141                moment(input).local();
1142        }
1143
1144        /************************************
1145            Locale
1146        ************************************/
1147
1148
1149        extend(Locale.prototype, {
1150
1151            set : function (config) {
1152                var prop, i;
1153                for (i in config) {
1154                    prop = config[i];
1155                    if (typeof prop === 'function') {
1156                        this[i] = prop;
1157                    } else {
1158                        this['_' + i] = prop;
1159                    }
1160                }
1161            },
1162
1163            _months : 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
1164            months : function (m) {
1165                return this._months[m.month()];
1166            },
1167
1168            _monthsShort : 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
1169            monthsShort : function (m) {
1170                return this._monthsShort[m.month()];
1171            },
1172
1173            monthsParse : function (monthName) {
1174                var i, mom, regex;
1175
1176                if (!this._monthsParse) {
1177                    this._monthsParse = [];
1178                }
1179
1180                for (i = 0; i < 12; i++) {
1181                    // make the regex if we don't have it already
1182                    if (!this._monthsParse[i]) {
1183                        mom = moment.utc([2000, i]);
1184                        regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
1185                        this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
1186                    }
1187                    // test the regex
1188                    if (this._monthsParse[i].test(monthName)) {
1189                        return i;
1190                    }
1191                }
1192            },
1193
1194            _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
1195            weekdays : function (m) {
1196                return this._weekdays[m.day()];
1197            },
1198
1199            _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
1200            weekdaysShort : function (m) {
1201                return this._weekdaysShort[m.day()];
1202            },
1203
1204            _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
1205            weekdaysMin : function (m) {
1206                return this._weekdaysMin[m.day()];
1207            },
1208
1209            weekdaysParse : function (weekdayName) {
1210                var i, mom, regex;
1211
1212                if (!this._weekdaysParse) {
1213                    this._weekdaysParse = [];
1214                }
1215
1216                for (i = 0; i < 7; i++) {
1217                    // make the regex if we don't have it already
1218                    if (!this._weekdaysParse[i]) {
1219                        mom = moment([2000, 1]).day(i);
1220                        regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
1221                        this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
1222                    }
1223                    // test the regex
1224                    if (this._weekdaysParse[i].test(weekdayName)) {
1225                        return i;
1226                    }
1227                }
1228            },
1229
1230            _longDateFormat : {
1231                LT : 'h:mm A',
1232                L : 'MM/DD/YYYY',
1233                LL : 'MMMM D, YYYY',
1234                LLL : 'MMMM D, YYYY LT',
1235                LLLL : 'dddd, MMMM D, YYYY LT'
1236            },
1237            longDateFormat : function (key) {
1238                var output = this._longDateFormat[key];
1239                if (!output && this._longDateFormat[key.toUpperCase()]) {
1240                    output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
1241                        return val.slice(1);
1242                    });
1243                    this._longDateFormat[key] = output;
1244                }
1245                return output;
1246            },
1247
1248            isPM : function (input) {
1249                // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing str
1249ings like arrays
1250                // Using charAt should be more compatible.
1251                return ((input + '').toLowerCase().charAt(0) === 'p');
1252            },
1253
1254            _meridiemParse : /[ap]\.?m?\.?/i,
1255            meridiem : function (hours, minutes, isLower) {
1256                if (hours > 11) {
1257                    return isLower ? 'pm' : 'PM';
1258                } else {
1259                    return isLower ? 'am' : 'AM';
1260                }
1261            },
1262
1263            _calendar : {
1264                sameDay : '[Today at] LT',
1265                nextDay : '[Tomorrow at] LT',
1266                nextWeek : 'dddd [at] LT',
1267                lastDay : '[Yesterday at] LT',
1268                lastWeek : '[Last] dddd [at] LT',
1269                sameElse : 'L'
1270            },
1271            calendar : function (key, mom) {
1272                var output = this._calendar[key];
1273                return typeof output === 'function' ? output.apply(mom) : output;
1274            },
1275
1276            _relativeTime : {
1277                future : 'in %s',
1278                past : '%s ago',
1279                s : 'a few seconds',
1280                m : 'a minute',
1281                mm : '%d minutes',
1282                h : 'an hour',
1283                hh : '%d hours',
1284                d : 'a day',
1285                dd : '%d days',
1286                M : 'a month',
1287                MM : '%d months',
1288                y : 'a year',
1289                yy : '%d years'
1290            },
1291
1292            relativeTime : function (number, withoutSuffix, string, isFuture) {
1293                var output = this._relativeTime[string];
1294                return (typeof output === 'function') ?
1295                    output(number, withoutSuffix, string, isFuture) :
1296                    output.replace(/%d/i, number);
1297            },
1298
1299            pastFuture : function (diff, output) {
1300                var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
1301                return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
1302            },
1303
1304            ordinal : function (number) {
1305                return this._ordinal.replace('%d', number);
1306            },
1307            _ordinal : '%d',
1308
1309            preparse : function (string) {
1310                return string;
1311            },
1312
1313            postformat : function (string) {
1314                return string;
1315            },
1316
1317            week : function (mom) {
1318                return weekOfYear(mom, this._week.dow, this._week.doy).week;
1319            },
1320
1321            _week : {
1322                dow : 0, // Sunday is the first day of the week.
1323                doy : 6  // The week that contains Jan 1st is the first week of the year.
1324            },
1325
1326            _invalidDate: 'Invalid date',
1327            invalidDate: function () {
1328                return this._invalidDate;
1329            }
1330        });
1331
1332        /************************************
1333            Formatting
1334        ************************************/
1335
1336
1337        function removeFormattingTokens(input) {
1338            if (input.match(/\[[\s\S]/)) {
1339                return input.replace(/^\[|\]$/g, '');
1340            }
1341            return input.replace(/\\/g, '');
1342        }
1343
1344        function makeFormatFunction(format) {
1345            var array = format.match(formattingTokens), i, length;
1346
1347            for (i = 0, length = array.length; i < length; i++) {
1348                if (formatTokenFunctions[array[i]]) {
1349                    array[i] = formatTokenFunctions[array[i]];
1350                } else {
1351                    array[i] = removeFormattingTokens(array[i]);
1352                }
1353            }
1354
1355            return function (mom) {
1356                var output = '';
1357                for (i = 0; i < length; i++) {
1358                    output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
1359                }
1360                return output;
1361            };
1362        }
1363
1364        // format date using native date object
1365        function formatMoment(m, format) {
1366            if (!m.isValid()) {
1367                return m.localeData().invalidDate();
1368            }
1369
1370            format = expandFormat(format, m.localeData());
1371
1372            if (!formatFunctions[format]) {
1373                formatFunctions[format] = makeFormatFunction(format);
1374            }
1375
1376            return formatFunctions[format](m);
1377        }
1378
1379        function expandFormat(format, locale) {
1380            var i = 5;
1381
1382            function replaceLongDateFormatTokens(input) {
1383                return locale.longDateFormat(input) || input;
1384            }
1385
1386            localFormattingTokens.lastIndex = 0;
1387            while (i >= 0 && localFormattingTokens.test(format)) {
1388                format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
1389                localFormattingTokens.lastIndex = 0;
1390                i -= 1;
1391            }
1392
1393            return format;
1394        }
1395
1396
1397        /************************************
1398            Parsing
1399        ************************************/
1400
1401
1402        // get the regex to find the next token
1403        function getParseRegexForToken(token, config) {
1404            var a, strict = config._strict;
1405            switch (token) {
1406            case 'Q':
1407                return parseTokenOneDigit;
1408            case 'DDDD':
1409                return parseTokenThreeDigits;
1410            case 'YYYY':
1411            case 'GGGG':
1412            case 'gggg':
1413                return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
1414            case 'Y':
1415            case 'G':
1416            case 'g':
1417                return parseTokenSignedNumber;
1418            case 'YYYYYY':
1419            case 'YYYYY':
1420            case 'GGGGG':
1421            case 'ggggg':
1422                return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
1423            case 'S':
1424                if (strict) {
1425                    return parseTokenOneDigit;
1426                }
1427                /* falls through */
1428            case 'SS':
1429                if (strict) {
1430                    return parseTokenTwoDigits;
1431                }
1432                /* falls through */
1433            case 'SSS':
1434                if (strict) {
1435                    return parseTokenThreeDigits;
1436                }
1437                /* falls through */
1438            case 'DDD':
1439                return parseTokenOneToThreeDigits;
1440            case 'MMM':
1441            case 'MMMM':
1442            case 'dd':
1443            case 'ddd':
1444            case 'dddd':
1445                return parseTokenWord;
1446            case 'a':
1447            case 'A':
1448                return config._locale._meridiemParse;
1449            case 'X':
1450                return parseTokenTimestampMs;
1451            case 'Z':
1452            case 'ZZ':
1453                return parseTokenTimezone;
1454            case 'T':
1455                return parseTokenT;
1456            case 'SSSS':
1457                return parseTokenDigits;
1458            case 'MM':
1459            case 'DD':
1460            case 'YY':
1461            case 'GG':
1462            case 'gg':
1463            case 'HH':
1464            case 'hh':
1465            case 'mm':
1466            case 'ss':
1467            case 'ww':
1468            case 'WW':
1469                return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
1470            case 'M':
1471            case 'D':
1472            case 'd':
1473            case 'H':
1474            case 'h':
1475            case 'm':
1476            case 's':
1477            case 'w':
1478            case 'W':
1479            case 'e':
1480            case 'E':
1481                return parseTokenOneOrTwoDigits;
1482            case 'Do':
1483                return parseTokenOrdinal;
1484            default :
1485                a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), 'i'));
1486                return a;
1487            }
1488        }
1489
1490        function timezoneMinutesFromString(string) {
1491            string = string || '';
1492            var possibleTzMatches = (string.match(parseTokenTimezone) || []),
1493                tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
1494                parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
1495                minutes = +(parts[1] * 60) + toInt(parts[2]);
1496
1497            return parts[0] === '+' ? -minutes : minutes;
1498        }
1499
1500        // function to convert string input to date
1501        function addTimeToArrayFromToken(token, input, config) {
1502            var a, datePartArray = config._a;
1503
1504            switch (token) {
1505            // QUARTER
1506            case 'Q':
1507                if (input != null) {
1508                    datePartArray[MONTH] = (toInt(input) - 1) * 3;
1509                }
1510                break;
1511            // MONTH
1512            case 'M' : // fall through to MM
1513            case 'MM' :
1514                if (input != null) {
1515                    datePartArray[MONTH] = toInt(input) - 1;
1516                }
1517                break;
1518            case 'MMM' : // fall through to MMMM
1519            case 'MMMM' :
1520                a = config._locale.monthsParse(input);
1521                // if we didn't find a month name, mark the date as invalid.
1522                if (a != null) {
1523                    datePartArray[MONTH] = a;
1524                } else {
1525                    config._pf.invalidMonth = input;
1526                }
1527                break;
1528            // DAY OF MONTH
1529            case 'D' : // fall through to DD
1530            case 'DD' :
1531                if (input != null) {
1532                    datePartArray[DATE] = toInt(input);
1533                }
1534                break;
1535            case 'Do' :
1536                if (input != null) {
1537                    datePartArray[DATE] = toInt(parseInt(input, 10));
1538                }
1539                break;
1540            // DAY OF YEAR
1541            case 'DDD' : // fall through to DDDD
1542            case 'DDDD' :
1543                if (input != null) {
1544                    config._dayOfYear = toInt(input);
1545                }
1546
1547                break;
1548            // YEAR
1549            case 'YY' :
1550                datePartArray[YEAR] = moment.parseTwoDigitYear(input);
1551                break;
1552            case 'YYYY' :
1553            case 'YYYYY' :
1554            case 'YYYYYY' :
1555                datePartArray[YEAR] = toInt(input);
1556                break;
1557            // AM / PM
1558            case 'a' : // fall through to A
1559            case 'A' :
1560                config._isPm = config._locale.isPM(input);
1561                break;
1562            // 24 HOUR
1563            case 'H' : // fall through to hh
1564            case 'HH' : // fall through to hh
1565            case 'h' : // fall through to hh
1566            case 'hh' :
1567                datePartArray[HOUR] = toInt(input);
1568                break;
1569            // MINUTE
1570            case 'm' : // fall through to mm
1571            case 'mm' :
1572                datePartArray[MINUTE] = toInt(input);
1573                break;
1574            // SECOND
1575            case 's' : // fall through to ss
1576            case 'ss' :
1577                datePartArray[SECOND] = toInt(input);
1578                break;
1579            // MILLISECOND
1580            case 'S' :
1581            case 'SS' :
1582            case 'SSS' :
1583            case 'SSSS' :
1584                datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
1585                break;
1586            // UNIX TIMESTAMP WITH MS
1587            case 'X':
1588                config._d = new Date(parseFloat(input) * 1000);
1589                break;
1590            // TIMEZONE
1591            case 'Z' : // fall through to ZZ
1592            case 'ZZ' :
1593                config._useUTC = true;
1594                config._tzm = timezoneMinutesFromString(input);
1595                break;
1596            // WEEKDAY - human
1597            case 'dd':
1598            case 'ddd':
1599            case 'dddd':
1600                a = config._locale.weekdaysParse(input);
1601                // if we didn't get a weekday name, mark the date as invalid
1602                if (a != null) {
1603                    config._w = config._w || {};
1604                    config._w['d'] = a;
1605                } else {
1606                    config._pf.invalidWeekday = input;
1607                }
1608                break;
1609            // WEEK, WEEK DAY - numeric
1610            case 'w':
1611            case 'ww':
1612            case 'W':
1613            case 'WW':
1614            case 'd':
1615            case 'e':
1616            case 'E':
1617                token = token.substr(0, 1);
1618                /* falls through */
1619            case 'gggg':
1620            case 'GGGG':
1621            case 'GGGGG':
1622                token = token.substr(0, 2);
1623                if (input) {
1624                    config._w = config._w || {};
1625                    config._w[token] = toInt(input);
1626                }
1627                break;
1628            case 'gg':
1629            case 'GG':
1630                config._w = config._w || {};
1631                config._w[token] = moment.parseTwoDigitYear(input);
1632            }
1633        }
1634
1635        function dayOfYearFromWeekInfo(config) {
1636            var w, weekYear, week, weekday, dow, doy, temp;
1637
1638            w = config._w;
1639            if (w.GG != null || w.W != null || w.E != null) {
1640                dow = 1;
1641                doy = 4;
1642
1643                // TODO: We need to take the current isoWeekYear, but that depends on
1644                // how we interpret now (local, utc, fixed offset). So create
1645                // a now version of current config (take local/utc/offset flags, and
1646                // create now).
1647                weekYear = dfl(w.GG, config._a[YEAR], weekOfYear(moment(), 1, 4).year);
1648                week = dfl(w.W, 1);
1649                weekday = dfl(w.E, 1);
1650            } else {
1651                dow = config._locale._week.dow;
1652                doy = config._locale._week.doy;
1653
1654                weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);
1655                week = dfl(w.w, 1);
1656
1657                if (w.d != null) {
1658                    // weekday -- low day numbers are considered next week
1659                    weekday = w.d;
1660                    if (weekday < dow) {
1661                        ++week;
1662                    }
1663                } else if (w.e != null) {
1664                    // local weekday -- counting starts from begining of week
1665                    weekday = w.e + dow;
1666                } else {
1667                    // default to begining of week
1668                    weekday = dow;
1669                }
1670            }
1671            temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
1672
1673            config._a[YEAR] = temp.year;
1674            config._dayOfYear = temp.dayOfYear;
1675        }
1676
1677        // convert an array to a date.
1678        // the array should mirror the parameters below
1679        // note: all values past the year are optional and will default to the lowest possible value.
1680        // [year, month, day , hour, minute, second, millisecond]
1681        function dateFromConfig(config) {
1682            var i, date, input = [], currentDate, yearToUse;
1683
1684            if (config._d) {
1685                return;
1686            }
1687
1688            currentDate = currentDateArray(config);
1689
1690            //compute day of the year from weeks and weekdays
1691            if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
1692                dayOfYearFromWeekInfo(config);
1693            }
1694
1695            //if the day of the year is set, figure out what it is
1696            if (config._dayOfYear) {
1697                yearToUse = dfl(config._a[YEAR], currentDate[YEAR]);
1698
1699                if (config._dayOfYear > daysInYear(yearToUse)) {
1700                    config._pf._overflowDayOfYear = true;
1701                }
1702
1703                date = makeUTCDate(yearToUse, 0, config._dayOfYear);
1704                config._a[MONTH] = date.getUTCMonth();
1705                config._a[DATE] = date.getUTCDate();
1706            }
1707
1708            // Default to current date.
1709            // * if no year, month, day of month are given, default to today
1710            // * if day of month is given, default month and year
1711            // * if month is given, default only year
1712            // * if year is given, don't default anything
1713            for (i = 0; i < 3 && config._a[i] == null; ++i) {
1714                config._a[i] = input[i] = currentDate[i];
1715            }
1716
1717            // Zero out whatever was not defaulted, including time
1718            for (; i < 7; i++) {
1719                config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
1720            }
1721
1722            config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
1723            // Apply timezone offset from input. The actual zone can be changed
1724            // with parseZone.
1725            if (config._tzm != null) {
1726                config._d.setUTCMinutes(config._d.getUTCMinutes() + config._tzm);
1727            }
1728        }
1729
1730        function dateFromObject(config) {
1731            var normalizedInput;
1732
1733            if (config._d) {
1734                return;
1735            }
1736
1737            normalizedInput = normalizeObjectUnits(config._i);
1738            config._a = [
1739                normalizedInput.year,
1740                normalizedInput.month,
1741                normalizedInput.day,
1742                normalizedInput.hour,
1743                normalizedInput.minute,
1744                normalizedInput.second,
1745                normalizedInput.millisecond
1746            ];
1747
1748            dateFromConfig(config);
1749        }
1750
1751        function currentDateArray(config) {
1752            var now = new Date();
1753            if (config._useUTC) {
1754                return [
1755                    now.getUTCFullYear(),
1756                    now.getUTCMonth(),
1757                    now.getUTCDate()
1758                ];
1759            } else {
1760                return [now.getFullYear(), now.getMonth(), now.getDate()];
1761            }
1762        }
1763
1764        // date from string and format string
1765        function makeDateFromStringAndFormat(config) {
1766            if (config._f === moment.ISO_8601) {
1767                parseISO(config);
1768                return;
1769            }
1770
1771            config._a = [];
1772            config._pf.empty = true;
1773
1774            // This array is used to make a Date, either with `new Date` or `Date.UTC`
1775            var string = '' + config._i,
1776                i, parsedInput, tokens, token, skipped,
1777                stringLength = string.length,
1778                totalParsedInputLength = 0;
1779
1780            tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
1781
1782            for (i = 0; i < tokens.length; i++) {
1783                token = tokens[i];
1784                parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
1785                if (parsedInput) {
1786                    skipped = string.substr(0, string.indexOf(parsedInput));
1787                    if (skipped.length > 0) {
1788                        config._pf.unusedInput.push(skipped);
1789                    }
1790                    string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
1791                    totalParsedInputLength += parsedInput.length;
1792                }
1793                // don't parse if it's not a known token
1794                if (formatTokenFunctions[token]) {
1795                    if (parsedInput) {
1796                        config._pf.empty = false;
1797                    }
1798                    else {
1799                        config._pf.unusedTokens.push(token);
1800                    }
1801                    addTimeToArrayFromToken(token, parsedInput, config);
1802                }
1803                else if (config._strict && !parsedInput) {
1804                    config._pf.unusedTokens.push(token);
1805                }
1806            }
1807
1808            // add remaining unparsed input length to the string
1809            config._pf.charsLeftOver = stringLength - totalParsedInputLength;
1810            if (string.length > 0) {
1811                config._pf.unusedInput.push(string);
1812            }
1813
1814            // handle am pm
1815            if (config._isPm && config._a[HOUR] < 12) {
1816                config._a[HOUR] += 12;
1817            }
1818            // if is 12 am, change hours to 0
1819            if (config._isPm === false && config._a[HOUR] === 12) {
1820                config._a[HOUR] = 0;
1821            }
1822
1823            dateFromConfig(config);
1824            checkOverflow(config);
1825        }
1826
1827        function unescapeFormat(s) {
1828            return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
1829                return p1 || p2 || p3 || p4;
1830            });
1831        }
1832
1833        // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
1834        function regexpEscape(s) {
1835            return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
1836        }
1837
1838        // date from string and array of format strings
1839        function makeDateFromStringAndArray(config) {
1840            var tempConfig,
1841                bestMoment,
1842
1843                scoreToBeat,
1844                i,
1845                currentScore;
1846
1847            if (config._f.length === 0) {
1848                config._pf.invalidFormat = true;
1849                config._d = new Date(NaN);
1850                return;
1851            }
1852
1853            for (i = 0; i < config._f.length; i++) {
1854                currentScore = 0;
1855                tempConfig = copyConfig({}, config);
1856                if (config._useUTC != null) {
1857                    tempConfig._useUTC = config._useUTC;
1858                }
1859                tempConfig._pf = defaultParsingFlags();
1860                tempConfig._f = config._f[i];
1861                makeDateFromStringAndFormat(tempConfig);
1862
1863                if (!isValid(tempConfig)) {
1864                    continue;
1865                }
1866
1867                // if there is any input that was not parsed add a penalty for that format
1868                currentScore += tempConfig._pf.charsLeftOver;
1869
1870                //or tokens
1871                currentScore += tempConfig._pf.unusedTokens.length * 10;
1872
1873                tempConfig._pf.score = currentScore;
1874
1875                if (scoreToBeat == null || currentScore < scoreToBeat) {
1876                    scoreToBeat = currentScore;
1877                    bestMoment = tempConfig;
1878                }
1879            }
1880
1881            extend(config, bestMoment || tempConfig);
1882        }
1883
1884        // date from iso format
1885        function parseISO(config) {
1886            var i, l,
1887                string = config._i,
1888                match = isoRegex.exec(string);
1889
1890            if (match) {
1891                config._pf.iso = true;
1892                for (i = 0, l = isoDates.length; i < l; i++) {
1893                    if (isoDates[i][1].exec(string)) {
1894                        // match[5] should be 'T' or undefined
1895                        config._f = isoDates[i][0] + (match[6] || ' ');
1896                        break;
1897                    }
1898                }
1899                for (i = 0, l = isoTimes.length; i < l; i++) {
1900                    if (isoTimes[i][1].exec(string)) {
1901                        config._f += isoTimes[i][0];
1902                        break;
1903                    }
1904                }
1905                if (string.match(parseTokenTimezone)) {
1906                    config._f += 'Z';
1907                }
1908                makeDateFromStringAndFormat(config);
1909            } else {
1910                config._isValid = false;
1911            }
1912        }
1913
1914        // date from iso format or fallback
1915        function makeDateFromString(config) {
1916            parseISO(config);
1917            if (config._isValid === false) {
1918                delete config._isValid;
1919                moment.createFromInputFallback(config);
1920            }
1921        }
1922
1923        function map(arr, fn) {
1924            var res = [], i;
1925            for (i = 0; i < arr.length; ++i) {
1926                res.push(fn(arr[i], i));
1927            }
1928            return res;
1929        }
1930
1931        function makeDateFromInput(config) {
1932            var input = config._i, matched;
1933            if (input === undefined) {
1934                config._d = new Date();
1935            } else if (isDate(input)) {
1936                config._d = new Date(+input);
1937            } else if ((matched = aspNetJsonRegex.exec(input)) !== null) {
1938                config._d = new Date(+matched[1]);
1939            } else if (typeof input === 'string') {
1940                makeDateFromString(config);
1941            } else if (isArray(input)) {
1942                config._a = map(input.slice(0), function (obj) {
1943                    return parseInt(obj, 10);
1944                });
1945                dateFromConfig(config);
1946            } else if (typeof(input) === 'object') {
1947                dateFromObject(config);
1948            } else if (typeof(input) === 'number') {
1949                // from milliseconds
1950                config._d = new Date(input);
1951            } else {
1952                moment.createFromInputFallback(config);
1953            }
1954        }
1955
1956        function makeDate(y, m, d, h, M, s, ms) {
1957            //can't just apply() to create a date:
1958            //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
1959            var date = new Date(y, m, d, h, M, s, ms);
1960
1961            //the date constructor doesn't accept years < 1970
1962            if (y < 1970) {
1963                date.setFullYear(y);
1964            }
1965            return date;
1966        }
1967
1968        function makeUTCDate(y) {
1969            var date = new Date(Date.UTC.apply(null, arguments));
1970            if (y < 1970) {
1971                date.setUTCFullYear(y);
1972            }
1973            return date;
1974        }
1975
1976        function parseWeekday(input, locale) {
1977            if (typeof input === 'string') {
1978                if (!isNaN(input)) {
1979                    input = parseInt(input, 10);
1980                }
1981                else {
1982                    input = locale.weekdaysParse(input);
1983                    if (typeof input !== 'number') {
1984                        return null;
1985                    }
1986                }
1987            }
1988            return input;
1989        }
1990
1991        /************************************
1992            Relative Time
1993        ************************************/
1994
1995
1996        // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
1997        function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
1998            return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
1999        }
2000
2001        function relativeTime(posNegDuration, withoutSuffix, locale) {
2002            var duration = moment.duration(posNegDuration).abs(),
2003                seconds = round(duration.as('s')),
2004                minutes = round(duration.as('m')),
2005                hours = round(duration.as('h')),
2006                days = round(duration.as('d')),
2007                months = round(duration.as('M')),
2008                years = round(duration.as('y')),
2009
2010                args = seconds < relativeTimeThresholds.s && ['s', seconds] ||
2011                    minutes === 1 && ['m'] ||
2012                    minutes < relativeTimeThresholds.m && ['mm', minutes] ||
2013                    hours === 1 && ['h'] ||
2014                    hours < relativeTimeThresholds.h && ['hh', hours] ||
2015                    days === 1 && ['d'] ||
2016                    days < relativeTimeThresholds.d && ['dd', days] ||
2017                    months === 1 && ['M'] ||
2018                    months < relativeTimeThresholds.M && ['MM', months] ||
2019                    years === 1 && ['y'] || ['yy', years];
2020
2021            args[2] = withoutSuffix;
2022            args[3] = +posNegDuration > 0;
2023            args[4] = locale;
2024            return substituteTimeAgo.apply({}, args);
2025        }
2026
2027
2028        /************************************
2029            Week of Year
2030        ************************************/
2031
2032
2033        // firstDayOfWeek       0 = sun, 6 = sat
2034        //                      the day of the week that starts the week
2035        //                      (usually sunday or monday)
2036        // firstDayOfWeekOfYear 0 = sun, 6 = sat
2037        //                      the first week is the week that contains the first
2038        //                      of this day of the week
2039        //                      (eg. ISO weeks use thursday (4))
2040        function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
2041            var end = firstDayOfWeekOfYear - firstDayOfWeek,
2042                daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
2043                adjustedMoment;
2044
2045
2046            if (daysToDayOfWeek > end) {
2047                daysToDayOfWeek -= 7;
2048            }
2049
2050            if (daysToDayOfWeek < end - 7) {
2051                daysToDayOfWeek += 7;
2052            }
2053
2054            adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');
2055            return {
2056                week: Math.ceil(adjustedMoment.dayOfYear() / 7),
2057                year: adjustedMoment.year()
2058            };
2059        }
2060
2061        //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
2062        function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
2063            var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
2064
2065            d = d === 0 ? 7 : d;
2066            weekday = weekday != null ? weekday : firstDayOfWeek;
2067            daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
2068            dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
2069
2070            return {
2071                year: dayOfYear > 0 ? year : year - 1,
2072                dayOfYear: dayOfYear > 0 ?  dayOfYear : daysInYear(year - 1) + dayOfYear
2073            };
2074        }
2075
2076        /************************************
2077            Top Level Functions
2078        ************************************/
2079
2080        function makeMoment(config) {
2081            var input = config._i,
2082                format = config._f;
2083
2084            config._locale = config._locale || moment.localeData(config._l);
2085
2086            if (input === null || (format === undefined && input === '')) {
2087                return moment.invalid({nullInput: true});
2088            }
2089
2090            if (typeof input === 'string') {
2091                config._i = input = config._locale.preparse(input);
2092            }
2093
2094            if (moment.isMoment(input)) {
2095                return new Moment(input, true);
2096            } else if (format) {
2097                if (isArray(format)) {
2098                    makeDateFromStringAndArray(config);
2099                } else {
2100                    makeDateFromStringAndFormat(config);
2101                }
2102            } else {
2103                makeDateFromInput(config);
2104            }
2105
2106            return new Moment(config);
2107        }
2108
2109        moment = function (input, format, locale, strict) {
2110            var c;
2111
2112            if (typeof(locale) === 'boolean') {
2113                strict = locale;
2114                locale = undefined;
2115            }
2116            // object construction must be done this way.
2117            // https://github.com/moment/moment/issues/1423
2118            c = {};
2119            c._isAMomentObject = true;
2120            c._i = input;
2121            c._f = format;
2122            c._l = locale;
2123            c._strict = strict;
2124            c._isUTC = false;
2125            c._pf = defaultParsingFlags();
2126
2127            return makeMoment(c);
2128        };
2129
2130        moment.suppressDeprecationWarnings = false;
2131
2132        moment.createFromInputFallback = deprecate(
2133            'moment construction falls back to js Date. This is ' +
2134            'discouraged and will be removed in upcoming major ' +
2135            'release. Please refer to ' +
2136            'https://github.com/moment/moment/issues/1407 for more info.',
2137            function (config) {
2138                config._d = new Date(config._i);
2139            }
2140        );
2141
2142        // Pick a moment m from moments so that m[fn](other) is true for all
2143        // other. This relies on the function fn to be transitive.
2144        //
2145        // moments should either be an array of moment objects or an array, whose
2146        // first element is an array of moment objects.
2147        function pickBy(fn, moments) {
2148            var res, i;
2149            if (moments.length === 1 && isArray(moments[0])) {
2150                moments = moments[0];
2151            }
2152            if (!moments.length) {
2153                return moment();
2154            }
2155            res = moments[0];
2156            for (i = 1; i < moments.length; ++i) {
2157                if (moments[i][fn](res)) {
2158                    res = moments[i];
2159                }
2160            }
2161            return res;
2162        }
2163
2164        moment.min = function () {
2165            var args = [].slice.call(arguments, 0);
2166
2167            return pickBy('isBefore', args);
2168        };
2169
2170        moment.max = function () {
2171            var args = [].slice.call(arguments, 0);
2172
2173            return pickBy('isAfter', args);
2174        };
2175
2176        // creating with utc
2177        moment.utc = function (input, format, locale, strict) {
2178            var c;
2179
2180            if (typeof(locale) === 'boolean') {
2181                strict = locale;
2182                locale = undefined;
2183            }
2184            // object construction must be done this way.
2185            // https://github.com/moment/moment/issues/1423
2186            c = {};
2187            c._isAMomentObject = true;
2188            c._useUTC = true;
2189            c._isUTC = true;
2190            c._l = locale;
2191            c._i = input;
2192            c._f = format;
2193            c._strict = strict;
2194            c._pf = defaultParsingFlags();
2195
2196            return makeMoment(c).utc();
2197        };
2198
2199        // creating with unix timestamp (in seconds)
2200        moment.unix = function (input) {
2201            return moment(input * 1000);
2202        };
2203
2204        // duration
2205        moment.duration = function (input, key) {
2206            var duration = input,
2207                // matching against regexp is expensive, do it on demand
2208                match = null,
2209                sign,
2210                ret,
2211                parseIso,
2212                diffRes;
2213
2214            if (moment.isDuration(input)) {
2215                duration = {
2216                    ms: input._milliseconds,
2217                    d: input._days,
2218                    M: input._months
2219                };
2220            } else if (typeof input === 'number') {
2221                duration = {};
2222                if (key) {
2223                    duration[key] = input;
2224                } else {
2225                    duration.milliseconds = input;
2226                }
2227            } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
2228                sign = (match[1] === '-') ? -1 : 1;
2229                duration = {
2230                    y: 0,
2231                    d: toInt(match[DATE]) * sign,
2232                    h: toInt(match[HOUR]) * sign,
2233                    m: toInt(match[MINUTE]) * sign,
2234                    s: toInt(match[SECOND]) * sign,
2235                    ms: toInt(match[MILLISECOND]) * sign
2236                };
2237            } else if (!!(match = isoDurationRegex.exec(input))) {
2238                sign = (match[1] === '-') ? -1 : 1;
2239                parseIso = function (inp) {
2240                    // We'd normally use ~~inp for this, but unfortunately it also
2241                    // converts floats to ints.
2242                    // inp may be undefined, so careful calling replace on it.
2243                    var res = inp && parseFloat(inp.replace(',', '.'));
2244                    // apply sign while we're at it
2245                    return (isNaN(res) ? 0 : res) * sign;
2246                };
2247                duration = {
2248                    y: parseIso(match[2]),
2249                    M: parseIso(match[3]),
2250                    d: parseIso(match[4]),
2251                    h: parseIso(match[5]),
2252                    m: parseIso(match[6]),
2253                    s: parseIso(match[7]),
2254                    w: parseIso(match[8])
2255                };
2256            } else if (typeof duration === 'object' &&
2257                    ('from' in duration || 'to' in duration)) {
2258                diffRes = momentsDifference(moment(duration.from), moment(duration.to));
2259
2260                duration = {};
2261                duration.ms = diffRes.milliseconds;
2262                duration.M = diffRes.months;
2263            }
2264
2265            ret = new Duration(duration);
2266
2267            if (moment.isDuration(input) && hasOwnProp(input, '_locale')) {
2268                ret._locale = input._locale;
2269            }
2270
2271            return ret;
2272        };
2273
2274        // version number
2275        moment.version = VERSION;
2276
2277        // default format
2278        moment.defaultFormat = isoFormat;
2279
2280        // constant that refers to the ISO standard
2281        moment.ISO_8601 = function () {};
2282
2283        // Plugins that add properties should also add the key here (null value),
2284        // so we can properly clone ourselves.
2285        moment.momentProperties = momentProperties;
2286
2287        // This function will be called whenever a moment is mutated.
2288        // It is intended to keep the offset in sync with the timezone.
2289        moment.updateOffset = function () {};
2290
2291        // This function allows you to set a threshold for relative time strings
2292        moment.relativeTimeThreshold = function (threshold, limit) {
2293            if (relativeTimeThresholds[threshold] === undefined) {
2294                return false;
2295            }
2296            if (limit === undefined) {
2297                return relativeTimeThresholds[threshold];
2298            }
2299            relativeTimeThresholds[threshold] = limit;
2300            return true;
2301        };
2302
2303        moment.lang = deprecate(
2304            'moment.lang is deprecated. Use moment.locale instead.',
2305            function (key, value) {
2306                return moment.locale(key, value);
2307            }
2308        );
2309
2310        // This function will load locale and then set the global locale.  If
2311        // no arguments are passed in, it will simply return the current global
2312        // locale key.
2313        moment.locale = function (key, values) {
2314            var data;
2315            if (key) {
2316                if (typeof(values) !== 'undefined') {
2317                    data = moment.defineLocale(key, values);
2318                }
2319                else {
2320                    data = moment.localeData(key);
2321                }
2322
2323                if (data) {
2324                    moment.duration._locale = moment._locale = data;
2325                }
2326            }
2327
2328            return moment._locale._abbr;
2329        };
2330
2331        moment.defineLocale = function (name, values) {
2332            if (values !== null) {
2333                values.abbr = name;
2334                if (!locales[name]) {
2335                    locales[name] = new Locale();
2336                }
2337                locales[name].set(values);
2338
2339                // backwards compat for now: also set the locale
2340                moment.locale(name);
2341
2342                return locales[name];
2343            } else {
2344                // useful for testing
2345                delete locales[name];
2346                return null;
2347            }
2348        };
2349
2350        moment.langData = deprecate(
2351            'moment.langData is deprecated. Use moment.localeData instead.',
2352            function (key) {
2353                return moment.localeData(key);
2354            }
2355        );
2356
2357        // returns locale data
2358        moment.localeData = function (key) {
2359            var locale;
2360
2361            if (key && key._locale && key._locale._abbr) {
2362                key = key._locale._abbr;
2363            }
2364
2365            if (!key) {
2366                return moment._locale;
2367            }
2368
2369            if (!isArray(key)) {
2370                //short-circuit everything else
2371                locale = loadLocale(key);
2372                if (locale) {
2373                    return locale;
2374                }
2375                key = [key];
2376            }
2377
2378            return chooseLocale(key);
2379        };
2380
2381        // compare moment object
2382        moment.isMoment = function (obj) {
2383            return obj instanceof Moment ||
2384                (obj != null && hasOwnProp(obj, '_isAMomentObject'));
2385        };
2386
2387        // for typechecking Duration objects
2388        moment.isDuration = function (obj) {
2389            return obj instanceof Duration;
2390        };
2391
2392        for (i = lists.length - 1; i >= 0; --i) {
2393            makeList(lists[i]);
2394        }
2395
2396        moment.normalizeUnits = function (units) {
2397            return normalizeUnits(units);
2398        };
2399
2400        moment.invalid = function (flags) {
2401            var m = moment.utc(NaN);
2402            if (flags != null) {
2403                extend(m._pf, flags);
2404            }
2405            else {
2406                m._pf.userInvalidated = true;
2407            }
2408
2409            return m;
2410        };
2411
2412        moment.parseZone = function () {
2413            return moment.apply(null, arguments).parseZone();
2414        };
2415
2416        moment.parseTwoDigitYear = function (input) {
2417            return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
2418        };
2419
2420        /************************************
2421            Moment Prototype
2422        ************************************/
2423
2424
2425        extend(moment.fn = Moment.prototype, {
2426
2427            clone : function () {
2428                return moment(this);
2429            },
2430
2431            valueOf : function () {
2432                return +this._d + ((this._offset || 0) * 60000);
2433            },
2434
2435            unix : function () {
2436                return Math.floor(+this / 1000);
2437            },
2438
2439            toString : function () {
2440                return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
2441            },
2442
2443            toDate : function () {
2444                return this._offset ? new Date(+this) : this._d;
2445            },
2446
2447            toISOString : function () {
2448                var m = moment(this).utc();
2449                if (0 < m.year() && m.year() <= 9999) {
2450                    return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2451                } else {
2452                    return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
2453                }
2454            },
2455
2456            toArray : function () {
2457                var m = this;
2458                return [
2459                    m.year(),
2460                    m.month(),
2461                    m.date(),
2462                    m.hours(),
2463                    m.minutes(),
2464                    m.seconds(),
2465                    m.milliseconds()
2466                ];
2467            },
2468
2469            isValid : function () {
2470                return isValid(this);
2471            },
2472
2473            isDSTShifted : function () {
2474                if (this._a) {
2475                    return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
2476                }
2477
2478                return false;
2479            },
2480
2481            parsingFlags : function () {
2482                return extend({}, this._pf);
2483            },
2484
2485            invalidAt: function () {
2486                return this._pf.overflow;
2487            },
2488
2489            utc : function (keepLocalTime) {
2490                return this.zone(0, keepLocalTime);
2491            },
2492
2493            local : function (keepLocalTime) {
2494                if (this._isUTC) {
2495                    this.zone(0, keepLocalTime);
2496                    this._isUTC = false;
2497
2498                    if (keepLocalTime) {
2499                        this.add(this._dateTzOffset(), 'm');
2500                    }
2501                }
2502                return this;
2503            },
2504
2505            format : function (inputString) {
2506                var output = formatMoment(this, inputString || moment.defaultFormat);
2507                return this.localeData().postformat(output);
2508            },
2509
2510            add : createAdder(1, 'add'),
2511
2512            subtract : createAdder(-1, 'subtract'),
2513
2514            diff : function (input, units, asFloat) {
2515                var that = makeAs(input, this),
2516                    zoneDiff = (this.zone() - that.zone()) * 6e4,
2517                    diff, output, daysAdjust;
2518
2519                units = normalizeUnits(units);
2520
2521                if (units === 'year' || units === 'month') {
2522                    // average number of days in the months in the given dates
2523                    diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
2524                    // difference in months
2525                    output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
2526                    // adjust by taking difference in days, average number of days
2527                    // and dst in the given months.
2528                    daysAdjust = (this - moment(this).startOf('month')) -
2529                        (that - moment(that).startOf('month'));
2530                    // same as above but with zones, to negate all dst
2531                    daysAdjust -= ((this.zone() - moment(this).startOf('month').zone()) -
2532                            (that.zone() - moment(that).startOf('month').zone())) * 6e4;
2533                    output += daysAdjust / diff;
2534                    if (units === 'year') {
2535                        output = output / 12;
2536                    }
2537                } else {
2538                    diff = (this - that);
2539                    output = units === 'second' ? diff / 1e3 : // 1000
2540                        units === 'minute' ? diff / 6e4 : // 1000 * 60
2541                        units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
2542                        units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
2543                        units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
2544                        diff;
2545                }
2546                return asFloat ? output : absRound(output);
2547            },
2548
2549            from : function (time, withoutSuffix) {
2550                return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
2551            },
2552
2553            fromNow : function (withoutSuffix) {
2554                return this.from(moment(), withoutSuffix);
2555            },
2556
2557            calendar : function (time) {
2558                // We want to compare the start of today, vs this.
2559                // Getting start-of-today depends on whether we're zone'd or not.
2560                var now = time || moment(),
2561                    sod = makeAs(now, this).startOf('day'),
2562                    diff = this.diff(sod, 'days', true),
2563                    format = diff < -6 ? 'sameElse' :
2564                        diff < -1 ? 'lastWeek' :
2565                        diff < 0 ? 'lastDay' :
2566                        diff < 1 ? 'sameDay' :
2567                        diff < 2 ? 'nextDay' :
2568                        diff < 7 ? 'nextWeek' : 'sameElse';
2569                return this.format(this.localeData().calendar(format, this));
2570            },
2571
2572            isLeapYear : function () {
2573                return isLeapYear(this.year());
2574            },
2575
2576            isDST : function () {
2577                return (this.zone() < this.clone().month(0).zone() ||
2578                    this.zone() < this.clone().month(5).zone());
2579            },
2580
2581            day : function (input) {
2582                var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
2583                if (input != null) {
2584                    input = parseWeekday(input, this.localeData());
2585                    return this.add(input - day, 'd');
2586                } else {
2587                    return day;
2588                }
2589            },
2590
2591            month : makeAccessor('Month', true),
2592
2593            startOf : function (units) {
2594                units = normalizeUnits(units);
2595                // the following switch intentionally omits break keywords
2596                // to utilize falling through the cases.
2597                switch (units) {
2598                case 'year':
2599                    this.month(0);
2600                    /* falls through */
2601                case 'quarter':
2602                case 'month':
2603                    this.date(1);
2604                    /* falls through */
2605                case 'week':
2606                case 'isoWeek':
2607                case 'day':
2608                    this.hours(0);
2609                    /* falls through */
2610                case 'hour':
2611                    this.minutes(0);
2612                    /* falls through */
2613                case 'minute':
2614                    this.seconds(0);
2615                    /* falls through */
2616                case 'second':
2617                    this.milliseconds(0);
2618                    /* falls through */
2619                }
2620
2621                // weeks are a special case
2622                if (units === 'week') {
2623                    this.weekday(0);
2624                } else if (units === 'isoWeek') {
2625                    this.isoWeekday(1);
2626                }
2627
2628                // quarters are also special
2629                if (units === 'quarter') {
2630                    this.month(Math.floor(this.month() / 3) * 3);
2631                }
2632
2633                return this;
2634            },
2635
2636            endOf: function (units) {
2637                units = normalizeUnits(units);
2638                return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
2639            },
2640
2641            isAfter: function (input, units) {
2642                units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
2643                if (units === 'millisecond') {
2644                    input = moment.isMoment(input) ? input : moment(input);
2645                    return +this > +input;
2646                } else {
2647                    return +this.clone().startOf(units) > +moment(input).startOf(units);
2648                }
2649            },
2650
2651            isBefore: function (input, units) {
2652                units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');
2653                if (units === 'millisecond') {
2654                    input = moment.isMoment(input) ? input : moment(input);
2655                    return +this < +input;
2656                } else {
2657                    return +this.clone().startOf(units) < +moment(input).startOf(units);
2658                }
2659            },
2660
2661            isSame: function (input, units) {
2662                units = normalizeUnits(units || 'millisecond');
2663                if (units === 'millisecond') {
2664                    input = moment.isMoment(input) ? input : moment(input);
2665                    return +this === +input;
2666                } else {
2667                    return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
2668                }
2669            },
2670
2671            min: deprecate(
2672                     'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
2673                     function (other) {
2674                         other = moment.apply(null, arguments);
2675                         return other < this ? this : other;
2676                     }
2677             ),
2678
2679            max: deprecate(
2680                    'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
2681                    function (other) {
2682                        other = moment.apply(null, arguments);
2683                        return other > this ? this : other;
2684                    }
2685            ),
2686
2687            // keepLocalTime = true means only change the timezone, without
2688            // affecting the local hour. So 5:31:26 +0300 --[zone(2, true)]-->
2689            // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist int zone
2690            // +0200, so we adjust the time as needed, to be valid.
2691            //
2692            // Keeping the time actually adds/subtracts (one hour)
2693            // from the actual represented time. That is why we call updateOffset
2694            // a second time. In case it wants us to change the offset again
2695            // _changeInProgress == true case, then we have to adjust, because
2696            // there is no such time in the given timezone.
2697            zone : function (input, keepLocalTime) {
2698                var offset = this._offset || 0,
2699                    localAdjust;
2700                if (input != null) {
2701                    if (typeof input === 'string') {
2702                        input = timezoneMinutesFromString(input);
2703                    }
2704                    if (Math.abs(input) < 16) {
2705                        input = input * 60;
2706                    }
2707                    if (!this._isUTC && keepLocalTime) {
2708                        localAdjust = this._dateTzOffset();
2709                    }
2710                    this._offset = input;
2711                    this._isUTC = true;
2712                    if (localAdjust != null) {
2713                        this.subtract(localAdjust, 'm');
2714                    }
2715                    if (offset !== input) {
2716                        if (!keepLocalTime || this._changeInProgress) {
2717                            addOrSubtractDurationFromMoment(this,
2718                                    moment.duration(offset - input, 'm'), 1, false);
2719                        } else if (!this._changeInProgress) {
2720                            this._changeInProgress = true;
2721                            moment.updateOffset(this, true);
2722                            this._changeInProgress = null;
2723                        }
2724                    }
2725                } else {
2726                    return this._isUTC ? offset : this._dateTzOffset();
2727                }
2728                return this;
2729            },
2730
2731            zoneAbbr : function () {
2732                return this._isUTC ? 'UTC' : '';
2733            },
2734
2735            zoneName : function () {
2736                return this._isUTC ? 'Coordinated Universal Time' : '';
2737            },
2738
2739            parseZone : function () {
2740                if (this._tzm) {
2741                    this.zone(this._tzm);
2742                } else if (typeof this._i === 'string') {
2743                    this.zone(this._i);
2744                }
2745                return this;
2746            },
2747
2748            hasAlignedHourOffset : function (input) {
2749                if (!input) {
2750                    input = 0;
2751                }
2752                else {
2753                    input = moment(input).zone();
2754                }
2755
2756                return (this.zone() - input) % 60 === 0;
2757            },
2758
2759            daysInMonth : function () {
2760                return daysInMonth(this.year(), this.month());
2761            },
2762
2763            dayOfYear : function (input) {
2764                var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
2765                return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
2766            },
2767
2768            quarter : function (input) {
2769                return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
2770            },
2771
2772            weekYear : function (input) {
2773                var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;
2774                return input == null ? year : this.add((input - year), 'y');
2775            },
2776
2777            isoWeekYear : function (input) {
2778                var year = weekOfYear(this, 1, 4).year;
2779                return input == null ? year : this.add((input - year), 'y');
2780            },
2781
2782            week : function (input) {
2783                var week = this.localeData().week(this);
2784                return input == null ? week : this.add((input - week) * 7, 'd');
2785            },
2786
2787            isoWeek : function (input) {
2788                var week = weekOfYear(this, 1, 4).week;
2789                return input == null ? week : this.add((input - week) * 7, 'd');
2790            },
2791
2792            weekday : function (input) {
2793                var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
2794                return input == null ? weekday : this.add(input - weekday, 'd');
2795            },
2796
2797            isoWeekday : function (input) {
2798                // behaves the same as moment#day except
2799                // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
2800                // as a setter, sunday should belong to the previous week.
2801                return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
2802            },
2803
2804            isoWeeksInYear : function () {
2805                return weeksInYear(this.year(), 1, 4);
2806            },
2807
2808            weeksInYear : function () {
2809                var weekInfo = this.localeData()._week;
2810                return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
2811            },
2812
2813            get : function (units) {
2814                units = normalizeUnits(units);
2815                return this[units]();
2816            },
2817
2818            set : function (units, value) {
2819                units = normalizeUnits(units);
2820                if (typeof this[units] === 'function') {
2821                    this[units](value);
2822                }
2823                return this;
2824            },
2825
2826            // If passed a locale key, it will set the locale for this
2827            // instance.  Otherwise, it will return the locale configuration
2828            // variables for this instance.
2829            locale : function (key) {
2830                var newLocaleData;
2831
2832                if (key === undefined) {
2833                    return this._locale._abbr;
2834                } else {
2835                    newLocaleData = moment.localeData(key);
2836                    if (newLocaleData != null) {
2837                        this._locale = newLocaleData;
2838                    }
2839                    return this;
2840                }
2841            },
2842
2843            lang : deprecate(
2844                'moment().lang() is deprecated. Use moment().localeData() instead.',
2845                function (key) {
2846                    if (key === undefined) {
2847                        return this.localeData();
2848                    } else {
2849                        return this.locale(key);
2850                    }
2851                }
2852            ),
2853
2854            localeData : function () {
2855                return this._locale;
2856            },
2857
2858            _dateTzOffset : function () {
2859                // On Firefox.24 Date#getTimezoneOffset returns a floating point.
2860                // https://github.com/moment/moment/pull/1871
2861                return Math.round(this._d.getTimezoneOffset() / 15) * 15;
2862            }
2863        });
2864
2865        function rawMonthSetter(mom, value) {
2866            var dayOfMonth;
2867
2868            // TODO: Move this out of here!
2869            if (typeof value === 'string') {
2870                value = mom.localeData().monthsParse(value);
2871                // TODO: Another silent failure?
2872                if (typeof value !== 'number') {
2873                    return mom;
2874                }
2875            }
2876
2877            dayOfMonth = Math.min(mom.date(),
2878                    daysInMonth(mom.year(), value));
2879            mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
2880            return mom;
2881        }
2882
2883        function rawGetter(mom, unit) {
2884            return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
2885        }
2886
2887        function rawSetter(mom, unit, value) {
2888            if (unit === 'Month') {
2889                return rawMonthSetter(mom, value);
2890            } else {
2891                return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
2892            }
2893        }
2894
2895        function makeAccessor(unit, keepTime) {
2896            return function (value) {
2897                if (value != null) {
2898                    rawSetter(this, unit, value);
2899                    moment.updateOffset(this, keepTime);
2900                    return this;
2901                } else {
2902                    return rawGetter(this, unit);
2903                }
2904            };
2905        }
2906
2907        moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);
2908        moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);
2909        moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);
2910        // Setting the hour should keep the time, because the user explicitly
2911        // specified which hour he wants. So trying to maintain the same hour (in
2912        // a new timezone) makes sense. Adding/subtracting hours does not follow
2913        // this rule.
2914        moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);
2915        // moment.fn.month is defined separately
2916        moment.fn.date = makeAccessor('Date', true);
2917        moment.fn.dates = deprecate('dates accessor is deprecated. Use date instead.', makeAccessor('Date', true));
2918        moment.fn.year = makeAccessor('FullYear', true);
2919        moment.fn.years = deprecate('years accessor is deprecated. Use year instead.', makeAccessor('FullYear', true));
2920
2921        // add plural methods
2922        moment.fn.days = moment.fn.day;
2923        moment.fn.months = moment.fn.month;
2924        moment.fn.weeks = moment.fn.week;
2925        moment.fn.isoWeeks = moment.fn.isoWeek;
2926        moment.fn.quarters = moment.fn.quarter;
2927
2928        // add aliased format methods
2929        moment.fn.toJSON = moment.fn.toISOString;
2930
2931        /************************************
2932            Duration Prototype
2933        ************************************/
2934
2935
2936        function daysToYears (days) {
2937            // 400 years have 146097 days (taking into account leap year rules)
2938            return days * 400 / 146097;
2939        }
2940
2941        function yearsToDays (years) {
2942            // years * 365 + absRound(years / 4) -
2943            //     absRound(years / 100) + absRound(years / 400);
2944            return years * 146097 / 400;
2945        }
2946
2947        extend(moment.duration.fn = Duration.prototype, {
2948
2949            _bubble : function () {
2950                var milliseconds = this._milliseconds,
2951                    days = this._days,
2952                    months = this._months,
2953                    data = this._data,
2954                    seconds, minutes, hours, years = 0;
2955
2956                // The following code bubbles up values, see the tests for
2957                // examples of what that means.
2958                data.milliseconds = milliseconds % 1000;
2959
2960                seconds = absRound(milliseconds / 1000);
2961                data.seconds = seconds % 60;
2962
2963                minutes = absRound(seconds / 60);
2964                data.minutes = minutes % 60;
2965
2966                hours = absRound(minutes / 60);
2967                data.hours = hours % 24;
2968
2969                days += absRound(hours / 24);
2970
2971                // Accurately convert days to years, assume start from year 0.
2972                years = absRound(daysToYears(days));
2973                days -= absRound(yearsToDays(years));
2974
2975                // 30 days to a month
2976                // TODO (iskren): Use anchor date (like 1st Jan) to compute this.
2977                months += absRound(days / 30);
2978                days %= 30;
2979
2980                // 12 months -> 1 year
2981                years += absRound(months / 12);
2982                months %= 12;
2983
2984                data.days = days;
2985                data.months = months;
2986                data.years = years;
2987            },
2988
2989            abs : function () {
2990                this._milliseconds = Math.abs(this._milliseconds);
2991                this._days = Math.abs(this._days);
2992                this._months = Math.abs(this._months);
2993
2994                this._data.milliseconds = Math.abs(this._data.milliseconds);
2995                this._data.seconds = Math.abs(this._data.seconds);
2996                this._data.minutes = Math.abs(this._data.minutes);
2997                this._data.hours = Math.abs(this._data.hours);
2998                this._data.months = Math.abs(this._data.months);
2999                this._data.years = Math.abs(this._data.years);
3000
3001                return this;
3002            },
3003
3004            weeks : function () {
3005                return absRound(this.days() / 7);
3006            },
3007
3008            valueOf : function () {
3009                return this._milliseconds +
3010                  this._days * 864e5 +
3011                  (this._months % 12) * 2592e6 +
3012                  toInt(this._months / 12) * 31536e6;
3013            },
3014
3015            humanize : function (withSuffix) {
3016                var output = relativeTime(this, !withSuffix, this.localeData());
3017
3018                if (withSuffix) {
3019                    output = this.localeData().pastFuture(+this, output);
3020                }
3021
3022                return this.localeData().postformat(output);
3023            },
3024
3025            add : function (input, val) {
3026                // supports only 2.0-style add(1, 's') or add(moment)
3027                var dur = moment.duration(input, val);
3028
3029                this._milliseconds += dur._milliseconds;
3030                this._days += dur._days;
3031                this._months += dur._months;
3032
3033                this._bubble();
3034
3035                return this;
3036            },
3037
3038            subtract : function (input, val) {
3039                var dur = moment.duration(input, val);
3040
3041                this._milliseconds -= dur._milliseconds;
3042                this._days -= dur._days;
3043                this._months -= dur._months;
3044
3045                this._bubble();
3046
3047                return this;
3048            },
3049
3050            get : function (units) {
3051                units = normalizeUnits(units);
3052                return this[units.toLowerCase() + 's']();
3053            },
3054
3055            as : function (units) {
3056                var days, months;
3057                units = normalizeUnits(units);
3058
3059                if (units === 'month' || units === 'year') {
3060                    days = this._days + this._milliseconds / 864e5;
3061                    months = this._months + daysToYears(days) * 12;
3062                    return units === 'month' ? months : months / 12;
3063                } else {
3064                    // handle milliseconds separately because of floating point math errors (issue #1867)
3065                    days = this._days + yearsToDays(this._months / 12);
3066                    switch (units) {
3067                        case 'week': return days / 7 + this._milliseconds / 6048e5;
3068                        case 'day': return days + this._milliseconds / 864e5;
3069                        case 'hour': return days * 24 + this._milliseconds / 36e5;
3070                        case 'minute': return days * 24 * 60 + this._milliseconds / 6e4;
3071                        case 'second': return days * 24 * 60 * 60 + this._milliseconds / 1000;
3072                        // Math.floor prevents floating point math errors here
3073                        case 'millisecond': return Math.floor(days * 24 * 60 * 60 * 1000) + this._milliseconds;
3074                        default: throw new Error('Unknown unit ' + units);
3075                    }
3076                }
3077            },
3078
3079            lang : moment.fn.lang,
3080            locale : moment.fn.locale,
3081
3082            toIsoString : deprecate(
3083                'toIsoString() is deprecated. Please use toISOString() instead ' +
3084                '(notice the capitals)',
3085                function () {
3086                    return this.toISOString();
3087                }
3088            ),
3089
3090            toISOString : function () {
3091                // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
3092                var years = Math.abs(this.years()),
3093                    months = Math.abs(this.months()),
3094                    days = Math.abs(this.days()),
3095                    hours = Math.abs(this.hours()),
3096                    minutes = Math.abs(this.minutes()),
3097                    seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
3098
3099                if (!this.asSeconds()) {
3100                    // this is the same as C#'s (Noda) and python (isodate)...
3101                    // but not other JS (goog.date)
3102                    return 'P0D';
3103                }
3104
3105                return (this.asSeconds() < 0 ? '-' : '') +
3106                    'P' +
3107                    (years ? years + 'Y' : '') +
3108                    (months ? months + 'M' : '') +
3109                    (days ? days + 'D' : '') +
3110                    ((hours || minutes || seconds) ? 'T' : '') +
3111                    (hours ? hours + 'H' : '') +
3112                    (minutes ? minutes + 'M' : '') +
3113                    (seconds ? seconds + 'S' : '');
3114            },
3115
3116            localeData : function () {
3117                return this._locale;
3118            }
3119        });
3120
3121        moment.duration.fn.toString = moment.duration.fn.toISOString;
3122
3123        function makeDurationGetter(name) {
3124            moment.duration.fn[name] = function () {
3125                return this._data[name];
3126            };
3127        }
3128
3129        for (i in unitMillisecondFactors) {
3130            if (hasOwnProp(unitMillisecondFactors, i)) {
3131                makeDurationGetter(i.toLowerCase());
3132            }
3133        }
3134
3135        moment.duration.fn.asMilliseconds = function () {
3136            return this.as('ms');
3137        };
3138        moment.duration.fn.asSeconds = function () {
3139            return this.as('s');
3140        };
3141        moment.duration.fn.asMinutes = function () {
3142            return this.as('m');
3143        };
3144        moment.duration.fn.asHours = function () {
3145            return this.as('h');
3146        };
3147        moment.duration.fn.asDays = function () {
3148            return this.as('d');
3149        };
3150        moment.duration.fn.asWeeks = function () {
3151            return this.as('weeks');
3152        };
3153        moment.duration.fn.asMonths = function () {
3154            return this.as('M');
3155        };
3156        moment.duration.fn.asYears = function () {
3157            return this.as('y');
3158        };
3159
3160        /************************************
3161            Default Locale
3162        ************************************/
3163
3164
3165        // Set default locale, other locale will inherit from English.
3166        moment.locale('en', {
3167            ordinal : function (number) {
3168                var b = number % 10,
3169                    output = (toInt(number % 100 / 10) === 1) ? 'th' :
3170                    (b === 1) ? 'st' :
3171                    (b === 2) ? 'nd' :
3172                    (b === 3) ? 'rd' : 'th';
3173                return number + output;
3174            }
3175        });
3176
3177        return moment;
3178
3179    }).call(this);
3180
3181    UI.Utils.moment = moment;
3182
3183    return UI.datepicker;
3184});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.