moment-range
Advanced tools
Comparing version 2.0.2 to 2.0.3
{ | ||
"name": "moment-range", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"main": "./dist/moment-range.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -41,16 +41,14 @@ (function (root, factory) { | ||
* | ||
* @class DateRange | ||
* @constructor | ||
* @param {(Moment|Date)} start Start of interval | ||
* @param {(Moment|Date)} end End of interval | ||
*/ | ||
/** | ||
*//** | ||
* DateRange class to store ranges and query dates. | ||
* | ||
* @class DateRange^1 | ||
* @constructor | ||
* @param {!Array} range Array containing start and end dates. | ||
*/ | ||
/** | ||
*//** | ||
* DateRange class to store ranges and query dates. | ||
* | ||
* @class DateRange^2 | ||
* @constructor | ||
* @param {!String} range String formatted as an IS0 8601 time interval | ||
@@ -82,3 +80,3 @@ */ | ||
* | ||
* @return {Function} | ||
* @type {DateRange} | ||
*/ | ||
@@ -132,3 +130,4 @@ DateRange.prototype.constructor = DateRange; | ||
* | ||
* @return {DateRange} | ||
* @return {DateRange} Returns the intersecting date or `null` if the ranges do | ||
* not intersect | ||
*/ | ||
@@ -160,3 +159,4 @@ DateRange.prototype.intersect = function(other) { | ||
* | ||
* @return {DateRange} | ||
* @return {DateRange} Returns the new `DateRange` or `null` if they do not | ||
* overlap | ||
*/ | ||
@@ -197,2 +197,5 @@ DateRange.prototype.add = function(other) { | ||
} | ||
else if ((start < other.start) && (other.start < end) && (other.end < end)) { | ||
return [new DateRange(start, other.start), new DateRange(other.start, end)]; | ||
} | ||
}; | ||
@@ -207,3 +210,3 @@ | ||
* http://momentjs.com/docs/#/manipulating/add/) | ||
* @param {!function(Moment)} hollaback Function to execute for each sub-range | ||
* @param {!DateRange~by} hollaback Callback | ||
* @param {!boolean} exclusive Indicate that the end of the range should not | ||
@@ -224,3 +227,12 @@ * be included in the iter. | ||
/** | ||
* Callback executed for each sub-range. | ||
* | ||
* @callback DateRange~by | ||
* | ||
* @param {!Moment} current Current moment object for iteration | ||
*/ | ||
/** | ||
* @private | ||
@@ -227,0 +239,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
!function(a,b){"function"==typeof define&&define.amd?define(["moment"],function(c){return a.DateRange=b(c)}):"object"==typeof exports?module.exports=b(require("moment")):a.DateRange=b(moment)}(this,function(a){function b(b,c){var d,e=b,f=c;(1===arguments.length||void 0===c)&&("object"==typeof b&&2===b.length?(e=b[0],f=b[1]):"string"==typeof b&&(d=b.split("/"),e=d[0],f=d[1])),this.start=a(e),this.end=a(f)}function c(b,c,d){for(var e=a(this.start);this.contains(e,d);)c.call(this,e.clone()),e.add(1,b)}function d(b,c,d){var e=this/b,f=Math.floor(e);if(f!==1/0){f===e&&d&&f--;for(var g=0;f>=g;g++)c.call(this,a(this.start.valueOf()+b.valueOf()*g))}}var e={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0};return b.prototype.constructor=b,b.prototype.clone=function(){return a().range(this.start,this.end)},b.prototype.contains=function(a,c){var d=this.start,e=this.end;return a instanceof b?d<=a.start&&(e>a.end||e.isSame(a.end)&&!c):a>=d&&(e>a||e.isSame(a)&&!c)},b.prototype.overlaps=function(a){return null!==this.intersect(a)},b.prototype.intersect=function(a){var c=this.start,d=this.end;return c<=a.start&&a.start<d&&d<a.end?new b(a.start,d):a.start<c&&c<a.end&&a.end<=d?new b(c,a.end):a.start<c&&d>=c&&d<a.end?this:c<=a.start&&a.start<=a.end&&a.end<=d?a:null},b.prototype.add=function(c){return this.overlaps(c)?new b(a.min(this.start,c.start),a.max(this.end,c.end)):null},b.prototype.subtract=function(a){var c=this.start,d=this.end;return null===this.intersect(a)?[this]:a.start<=c&&d>c&&d<=a.end?[]:a.start<=c&&c<a.end&&a.end<d?[new b(a.end,d)]:c<a.start&&a.start<d&&d<=a.end?[new b(c,a.start)]:c<a.start&&a.start<a.end&&a.end<d?[new b(c,a.start),new b(a.end,d)]:void 0},b.prototype.by=function(a,b,e){return"string"==typeof a?c.call(this,a,b,e):d.call(this,a,b,e),this},b.prototype.toString=function(){return this.start.format()+"/"+this.end.format()},b.prototype.valueOf=function(){return this.end-this.start},b.prototype.center=function(){var b=this.start+this.diff()/2;return a(b)},b.prototype.toDate=function(){return[this.start.toDate(),this.end.toDate()]},b.prototype.isSame=function(a){return this.start.isSame(a.start)&&this.end.isSame(a.end)},b.prototype.diff=function(a){return this.end.diff(this.start,a)},a.range=function(c,d){return c in e?new b(a(this).startOf(c),a(this).endOf(c)):new b(c,d)},a.range.constructor=b,a.fn.range=a.range,a.fn.within=function(a){return a.contains(this._d)},b}); | ||
!function(a,b){"function"==typeof define&&define.amd?define(["moment"],function(c){return a.DateRange=b(c)}):"object"==typeof exports?module.exports=b(require("moment")):a.DateRange=b(moment)}(this,function(a){function b(b,c){var d,e=b,f=c;(1===arguments.length||void 0===c)&&("object"==typeof b&&2===b.length?(e=b[0],f=b[1]):"string"==typeof b&&(d=b.split("/"),e=d[0],f=d[1])),this.start=a(e),this.end=a(f)}function c(b,c,d){for(var e=a(this.start);this.contains(e,d);)c.call(this,e.clone()),e.add(1,b)}function d(b,c,d){var e=this/b,f=Math.floor(e);if(f!==1/0){f===e&&d&&f--;for(var g=0;f>=g;g++)c.call(this,a(this.start.valueOf()+b.valueOf()*g))}}var e={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0};return b.prototype.constructor=b,b.prototype.clone=function(){return a().range(this.start,this.end)},b.prototype.contains=function(a,c){var d=this.start,e=this.end;return a instanceof b?d<=a.start&&(e>a.end||e.isSame(a.end)&&!c):a>=d&&(e>a||e.isSame(a)&&!c)},b.prototype.overlaps=function(a){return null!==this.intersect(a)},b.prototype.intersect=function(a){var c=this.start,d=this.end;return c<=a.start&&a.start<d&&d<a.end?new b(a.start,d):a.start<c&&c<a.end&&a.end<=d?new b(c,a.end):a.start<c&&d>=c&&d<a.end?this:c<=a.start&&a.start<=a.end&&a.end<=d?a:null},b.prototype.add=function(c){return this.overlaps(c)?new b(a.min(this.start,c.start),a.max(this.end,c.end)):null},b.prototype.subtract=function(a){var c=this.start,d=this.end;return null===this.intersect(a)?[this]:a.start<=c&&d>c&&d<=a.end?[]:a.start<=c&&c<a.end&&a.end<d?[new b(a.end,d)]:c<a.start&&a.start<d&&d<=a.end?[new b(c,a.start)]:c<a.start&&a.start<a.end&&a.end<d?[new b(c,a.start),new b(a.end,d)]:c<a.start&&a.start<d&&a.end<d?[new b(c,a.start),new b(a.start,d)]:void 0},b.prototype.by=function(a,b,e){return"string"==typeof a?c.call(this,a,b,e):d.call(this,a,b,e),this},b.prototype.toString=function(){return this.start.format()+"/"+this.end.format()},b.prototype.valueOf=function(){return this.end-this.start},b.prototype.center=function(){var b=this.start+this.diff()/2;return a(b)},b.prototype.toDate=function(){return[this.start.toDate(),this.end.toDate()]},b.prototype.isSame=function(a){return this.start.isSame(a.start)&&this.end.isSame(a.end)},b.prototype.diff=function(a){return this.end.diff(this.start,a)},a.range=function(c,d){return c in e?new b(a(this).startOf(c),a(this).endOf(c)):new b(c,d)},a.range.constructor=b,a.fn.range=a.range,a.fn.within=function(a){return a.contains(this._d)},b}); |
@@ -112,3 +112,4 @@ //----------------------------------------------------------------------------- | ||
* | ||
* @return {DateRange} | ||
* @return {DateRange} Returns the intersecting date or `null` if the ranges do | ||
* not intersect | ||
*/ | ||
@@ -140,3 +141,4 @@ DateRange.prototype.intersect = function(other) { | ||
* | ||
* @return {DateRange} | ||
* @return {DateRange} Returns the new `DateRange` or `null` if they do not | ||
* overlap | ||
*/ | ||
@@ -177,2 +179,5 @@ DateRange.prototype.add = function(other) { | ||
} | ||
else if ((start < other.start) && (other.start < end) && (other.end < end)) { | ||
return [new DateRange(start, other.start), new DateRange(other.start, end)]; | ||
} | ||
}; | ||
@@ -179,0 +184,0 @@ |
@@ -24,3 +24,3 @@ { | ||
}, | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"engines": { | ||
@@ -27,0 +27,0 @@ "node": "*" |
@@ -5,2 +5,4 @@ # moment-range | ||
Detailed API documentation can be found at: http://gf3.github.io/moment-range/DateRange.html | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
@@ -7,0 +9,0 @@ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
@@ -569,3 +569,3 @@ /* jshint node: true, maxlen: 200, -W030 */ | ||
it('should turn [--{==}--] into (--) (--) where (a=[], b={})', function() { | ||
it('should turn [--{==}--] into (--) (--) where (a=[], b={})', function() { | ||
var dr1 = moment.range(d5, d8); | ||
@@ -632,2 +632,8 @@ var dr2 = moment.range(d6, d7); | ||
}); | ||
it('should turn [--{==}--] into (--) where (a=[], b={})', function() { | ||
var o = moment.range('2015-04-07T00:00:00+00:00/2015-04-08T00:00:00+00:00'); | ||
var s = moment.range('2015-04-07T17:12:18+00:00/2015-04-07T17:12:18+00:00'); | ||
o.subtract(s).should.eql([moment.range('2015-04-07T00:00:00+00:00/2015-04-07T17:12:18+00:00'), moment.range('2015-04-07T17:12:18+00:00/2015-04-08T00:00:00+00:00')]); | ||
}); | ||
}); | ||
@@ -634,0 +640,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56281
1270
359