1(function (root, factory) { 2 'use strict'; 3 if (typeof define === 'function' && define.amd) { 4 // AMD. Register as an anonymous module. 5 define(['moment'], factory); 6 } else if (typeof exports === 'object') { 7 // Node. Does not work with strict CommonJS, but 8 // only CommonJS-like environments that support module.exports, 9 // like Node. 10 module.exports = factory(require('moment')); 11 } else { 12 // Browser globals (root is window) 13 root.returnExports = factory(root.moment); 14 } 15}(this, function (moment) { 16 'use strict'; 17 18 if(typeof exports !== 'undefined'){ 19 if (typeof module !== 'undefined' && module.exports) { 20 exports = module.exports = moment; 21 } 22 exports.moment = moment; 23 } 24 25 var iso8601 = /^P(?:(\d+(?:[\.,]\d{0,3})?W)|(\d+(?:[\.,]\d{0,3})?Y)?(\d+(?:[\.,]\d{0,3})?M)?(\d+(?:[\.,]\d{0,3})?D)?(?:T(\d+(?:[\.,]\d{0,3})?H)?(\d+(?:[\.,]\d{0,3})?M)?(\d+(?:[\.,]\d{0,3})?S)?)?)$/; 26 27 function isISODuration(text) { 28 return iso8601.test(text); 29 } 30 31 var durationFn = moment.duration; 32 33 moment.duration = function (text) { 34 if (arguments.length > 1 || typeof text !== 'string') { 35 return durationFn.apply(moment, arguments); 36 } 37 var matches = text.match(iso8601); 38 if (matches === null) { 39 throw '"' + text + '" is an invalid ISO 8601 duration'; 40 } 41 var d = { 42 weeks: parseFloat(matches[1], 10), 43 years: parseFloat(matches[2], 10), 44 months: parseFloat(matches[3], 10), 45 days: parseFloat(matches[4], 10), 46 hours: parseFloat(matches[5], 10), 47 minutes: parseFloat(matches[6], 10), 48 seconds: parseFloat(matches[7], 10), 49 milliseconds: parseFloat(matches[8], 10) 50 }; 51 return moment.duration(d); 52 }; 53 54 moment.duration.fn = durationFn.fn; 55 56 moment.duration.fn.toISOString = function () { 57 function append(number, suffix) { 58 return number > 0 ? (number + '' + suffix) : ''; 59 } 60 61 return 'P' + 62 (this.days() > 0 && this.days() % 7 !== 0 ? '' : append(Math.abs(this.weeks()), 'W')) + 63 append(Math.abs(this.years()), 'Y') + 64 append(Math.abs(this.months()), 'M') + 65 (this.days() > 0 && this.days() % 7 === 0 ? '' : append(Math.abs(this.days()), 'D')) + 66 ((Math.abs(this.hours()) + Math.abs(this.minutes()) + Math.abs(this.seconds()) + Math.abs(this.milliseconds()) > 0) ? 'T' : '') + 67 append(Math.abs(this.hours()), 'H') + 68 append(Math.abs(this.minutes()), 'M') + 69 append(Math.abs(this.seconds())+Math.abs(this.milliseconds())/1000, 'S'); 70 }; 71 72 // http://stackoverflow.com/q/1353684/1206952 73 function isValidDate(d) { 74 if ( Object.prototype.toString.call(d) !== "[object Date]" ){ 75 return false; 76 } 77 return !isNaN(d.getTime()); 78 } 79 80 function IntervalException(message, object) { 81 this.name = "IntervalException"; 82 this.message = message; 83 this.object = object; 84 } 85 IntervalException.prototype = new Error(); 86 IntervalException.prototype.constructor = IntervalException; 87 88 /** 89 * Checks if the specified object is an Interval object. 90 */ 91 moment.isInterval = function (interval) { 92 return typeof interval.start === 'function' && 93 typeof interval.end === 'function' && 94 typeof interval.period === 'function' && 95 moment.isMoment(interval.start()) && 96 moment.isMoment(interval.end()) && 97 moment.isDuration(interval.period()); 98 }; 99 100 /** 101 * Creates an Interval object based on the current Moment instance. 102 * moment().interval(String) 103 * moment().interval(Moment) 104 * moment().interval(Duration) 105 */ 106 moment.fn.interval = function (arg) { 107 if (typeof arg === 'string') { 108 var iso = arg.split('/', 2); 109 110 if (iso[0] === '' && iso[1] === '') { 111 throw new IntervalException('No date or period specified in "' + arg + '"'); 112 } 113 if (iso[0] !== '' && iso[1] !== '') { 114 throw new IntervalException('In order to create an Interval between this Moment instance and another time, either start or end of the specified interval string needs to be blank', arg); 115 } 116 if (iso[0] === '') { 117 iso[0] = this.format(); 118 } 119 else { 120 iso[1] = this.format(); 121 } 122 return moment.interval(iso.join('/')); 123 } 124 else if (moment.isMoment(arg)) { 125 return moment.interval(moment(Math.min(this,arg)), moment(Math.max(this,arg))); 126 } 127 else if (moment.isDuration(arg)) { 128 return moment.interval(arg < 0 ? moment.duration(-arg) : this, arg > 0 ? arg : this); 129 } 130 }; 131 132 /** 133 * Creates an Interval object based on the current Duration instance. 134 * moment().duration().since(Moment) 135 */ 136 moment.duration.fn.since = function (value) { 137 return moment.interval(value, this); 138 }; 139 140 /** 141 * Creates an Interval object based on the current Duration instance. 142 * moment().duration().until(Moment) 143 */ 144 moment.duration.fn.until = function (value) { 145 return moment.interval(this, value); 146 }; 147 148 /** 149 * Creates an Interval object. 150 * moment.interval(String) 151 * moment.interval(Moment, Moment) 152 * moment.interval(Moment, Duration) 153 * moment.interval(Duration, Moment) 154 */ 155 moment.interval = function (arg1, arg2) { 156 var start, end, period; 157 158 // moment.interval(String) 159 if (!arg2 && typeof arg1 === 'string') { 160 var iso = arg1.split('/', 2); 161 162 if (iso[0] === '' && iso[1] === '') { 163 throw new IntervalException('Either start or end can be blank, but not both'); 164 } 165 166 if (isISODuration(iso[0]) && isISODuration(iso[1])) { 167 throw new IntervalException('Either start or end can be a Period string, but not both'); 168 } 169 170 if (isISODuration(iso[0])) { 171 period = moment.duration(iso[0]); 172 } 173 else { 174 start = moment(iso[0] || undefined); 175 } 176 177 if (isISODuration(iso[1])) { 178 period = moment.duration(iso[1]); 179 end = moment(start).add(period); 180 } 181 else { 182 end = moment(iso[1] || undefined); 183 if (start) {
184 period = moment.duration(end.diff(start)); 185 } 186 else { 187 start = moment(end).subtract(period); 188 } 189 } 190 } 191 // moment.interval(Moment|Duration, Moment|Duration) 192 else { 193 if (moment.isDuration(arg1) && moment.isDuration(arg2)) { 194 throw new IntervalException('Either start or end can be a Duration object, but not both'); 195 } 196 197 period = moment.isDuration(arg1)? moment.duration(arg1) : moment.isDuration(arg2)? moment.duration(arg2) : undefined; 198 start = moment.isMoment(arg1)? moment(arg1) : undefined; 199 end = moment.isMoment(arg2)? moment(arg2) : undefined; 200 201 if (period) { 202 start = start || moment(end).subtract(Math.abs(period)); 203 end = end || moment(start).add(Math.abs(period)); 204 } 205 else { 206 period = moment.duration(end.diff(start)); 207 } 208 } 209 210 return { 211 // interval.start([Moment[, keepPeriod]]) 212 start: function (value, keepPeriod) { 213 if (value) { 214 start = moment(value); 215 if (keepPeriod) { 216 end = moment(start).add(Math.abs(period)); 217 } 218 else { 219 period = moment.duration(end.diff(start)); 220 } 221 } 222 return start; 223 }, 224 // interval.end([Moment[, keepPeriod]]) 225 end: function (value, keepPeriod) { 226 if (value) { 227 end = moment(value); 228 if (keepPeriod) { 229 start = moment(end).subtract(Math.abs(period)); 230 } 231 else { 232 period = moment.duration(end.diff(start)); 233 } 234 } 235 return end; 236 }, 237 // interval.period([Duration]) 238 period: function (value) { 239 if (value) { 240 period = moment.duration(value); 241 end = moment(start).add(period); 242 } 243 return period; 244 }, 245 // interval.backward([Duration]) 246 backward: function (duration) { 247 duration = Math.abs(duration || period); 248 start = moment(start).subtract(duration); 249 end = moment(end).subtract(duration); 250 return this; 251 }, 252 // interval.forward(Duration) 253 forward: function (duration) { 254 duration = Math.abs(duration || period); 255 start = moment(start).add(duration); 256 end = moment(end).add(duration); 257 return this; 258 }, 259 // interval.travel(Duration) 260 travel: function (duration) { 261 if (duration.valueOf() < 0) { 262 this.backward(moment.duration(-duration)); 263 } 264 else { 265 this.forward(duration); 266 } 267 return this; 268 } 269 }; 270 }; 271 272 return moment; 273}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.