diff --git a/bower.json b/bower.json index fedb591..3326058 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "moment-range", - "version": "2.0.2", + "version": "2.0.3", "main": "./dist/moment-range.js", "ignore": [ "**/.*", diff --git a/dist/moment-range.js b/dist/moment-range.js index 507c423..ae05754 100644 --- a/dist/moment-range.js +++ b/dist/moment-range.js @@ -38,20 +38,18 @@ var INTERVALS = { /** * DateRange class to store ranges and query dates. * - * @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 */ function DateRange(start, end) { @@ -78,7 +76,7 @@ function DateRange(start, end) { /** * Constructor for prototype. * - * @return {Function} + * @type {DateRange} */ DateRange.prototype.constructor = DateRange; @@ -127,7 +125,8 @@ DateRange.prototype.overlaps = function(range) { * * @param {!DateRange} other A date range to intersect with this one * - * @return {DateRange} + * @return {DateRange} Returns the intersecting date or `null` if the ranges do + * not intersect */ DateRange.prototype.intersect = function(other) { var start = this.start; @@ -154,7 +153,8 @@ DateRange.prototype.intersect = function(other) { * * @param {!DateRange} other A date range to add to this one * - * @return {DateRange} + * @return {DateRange} Returns the new `DateRange` or `null` if they do not + * overlap */ DateRange.prototype.add = function(other) { if (this.overlaps(other)) { @@ -190,6 +190,9 @@ DateRange.prototype.subtract = function(other) { else if ((start < other.start) && (other.start < other.end) && (other.end < end)) { return [new DateRange(start, other.start), new DateRange(other.end, end)]; } + else if ((start < other.start) && (other.start < end) && (other.end < end)) { + return [new DateRange(start, other.start), new DateRange(other.start, end)]; + } }; /** @@ -199,7 +202,7 @@ DateRange.prototype.subtract = function(other) { * @param {(!DateRange|String)} range Date range to be used for iteration or * shorthand string (shorthands: * 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 * be included in the iter. * @@ -215,6 +218,15 @@ DateRange.prototype.by = function(range, hollaback, exclusive) { return this; }; + +/** + * Callback executed for each sub-range. + * + * @callback DateRange~by + * + * @param {!Moment} current Current moment object for iteration + */ + /** * @private */ diff --git a/dist/moment-range.min.js b/dist/moment-range.min.js index 6d43824..cf83525 100644 --- a/dist/moment-range.min.js +++ b/dist/moment-range.min.js @@ -1 +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=c&&dc&&d<=a.end?[]:a.start<=c&&c=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=c&&dc&&d<=a.end?[]:a.start<=c&&c