rails-uikit-sass 2.27.2

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