moment-range
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -37,2 +37,13 @@ var DateRange, INTERVALS; | ||
/** | ||
* Deep clone range | ||
* @return {!DateRange} | ||
* | ||
*/ | ||
DateRange.prototype.clone = function() { | ||
return moment().range(this.start, this.end); | ||
}; | ||
/** | ||
* Determine if the current interval contains a given moment/date/range. | ||
@@ -121,5 +132,5 @@ * | ||
return new DateRange(this.start, other.end); | ||
} else if (((other.start < (_ref5 = this.start) && _ref5 < (_ref4 = this.end)) && _ref4 < other.end)) { | ||
} else if (((other.start < (_ref5 = this.start) && _ref5 <= (_ref4 = this.end)) && _ref4 < other.end)) { | ||
return this; | ||
} else if (((this.start <= (_ref7 = other.start) && _ref7 < (_ref6 = other.end)) && _ref6 <= this.end)) { | ||
} else if (((this.start <= (_ref7 = other.start) && _ref7 <= (_ref6 = other.end)) && _ref6 <= this.end)) { | ||
return other; | ||
@@ -209,2 +220,15 @@ } else { | ||
/** | ||
* Center date of the range. | ||
* @return {!Moment} | ||
* | ||
*/ | ||
DateRange.prototype.center = function() { | ||
var center; | ||
center = this.start + this.diff() / 2; | ||
return moment(center); | ||
}; | ||
/** | ||
* Date range toDate | ||
@@ -271,3 +295,3 @@ * | ||
moment.fn.range = function(start, end) { | ||
moment.range = function(start, end) { | ||
if (start in INTERVALS) { | ||
@@ -281,10 +305,3 @@ return new DateRange(moment(this).startOf(start), moment(this).endOf(start)); | ||
/** | ||
* Build a date range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
* Expose constructor | ||
* | ||
@@ -294,7 +311,13 @@ */ | ||
moment.range = function(start, end) { | ||
return new DateRange(start, end); | ||
}; | ||
moment.range.constructor = DateRange; | ||
/** | ||
* @deprecated | ||
* | ||
*/ | ||
moment.fn.range = moment.range; | ||
/** | ||
* Check if the current moment is within a given date range. | ||
@@ -301,0 +324,0 @@ * |
@@ -1,1 +0,1 @@ | ||
var DateRange,INTERVALS;INTERVALS={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0},DateRange=function(){function a(a,b){this.start=moment(a),this.end=moment(b)}return a.prototype.contains=function(b){return b instanceof a?this.start<=b.start&&this.end>=b.end:this.start<=b&&b<=this.end},a.prototype._by_string=function(a,b){var c,d;for(c=moment(this.start),d=[];this.contains(c);)b.call(this,c.clone()),d.push(c.add(1,a));return d},a.prototype._by_range=function(a,b){var c,d,e,f;if(d=Math.floor(this/a),1/0===d)return this;for(f=[],c=e=0;d>=0?d>=e:e>=d;c=d>=0?++e:--e)f.push(b.call(this,moment(this.start.valueOf()+a.valueOf()*c)));return f},a.prototype.overlaps=function(a){return null!==this.intersect(a)},a.prototype.intersect=function(b){var c,d,e,f,g,h,i,j;return this.start<=(d=b.start)&&d<(c=this.end)&&c<b.end?new a(b.start,this.end):b.start<(f=this.start)&&f<(e=b.end)&&e<=this.end?new a(this.start,b.end):b.start<(h=this.start)&&h<(g=this.end)&&g<b.end?this:this.start<=(j=b.start)&&j<(i=b.end)&&i<=this.end?b:null},a.prototype.add=function(b){return this.overlaps(b)?new a(moment.min(this.start,b.start),moment.max(this.end,b.end)):null},a.prototype.subtract=function(b){var c,d,e,f,g,h,i,j;return null===this.intersect(b)?[this]:b.start<=(d=this.start)&&d<(c=this.end)&&c<=b.end?[]:b.start<=(f=this.start)&&f<(e=b.end)&&e<this.end?[new a(b.end,this.end)]:this.start<(h=b.start)&&h<(g=this.end)&&g<=b.end?[new a(this.start,b.start)]:this.start<(j=b.start)&&j<(i=b.end)&&i<this.end?[new a(this.start,b.start),new a(b.end,this.end)]:void 0},a.prototype.by=function(a,b){return"string"==typeof a?this._by_string(a,b):this._by_range(a,b),this},a.prototype.valueOf=function(){return this.end-this.start},a.prototype.toDate=function(){return[this.start.toDate(),this.end.toDate()]},a.prototype.isSame=function(a){return this.start.isSame(a.start)&&this.end.isSame(a.end)},a.prototype.diff=function(a){return null==a&&(a=void 0),this.end.diff(this.start,a)},a}(),moment.fn.range=function(a,b){return a in INTERVALS?new DateRange(moment(this).startOf(a),moment(this).endOf(a)):new DateRange(a,b)},moment.range=function(a,b){return new DateRange(a,b)},moment.fn.within=function(a){return a.contains(this._d)}; | ||
var DateRange,INTERVALS;INTERVALS={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0},DateRange=function(){function a(a,b){this.start=moment(a),this.end=moment(b)}return a.prototype.clone=function(){return moment().range(this.start,this.end)},a.prototype.contains=function(b){return b instanceof a?this.start<=b.start&&this.end>=b.end:this.start<=b&&b<=this.end},a.prototype._by_string=function(a,b){var c,d;for(c=moment(this.start),d=[];this.contains(c);)b.call(this,c.clone()),d.push(c.add(1,a));return d},a.prototype._by_range=function(a,b){var c,d,e,f;if(d=Math.floor(this/a),1/0===d)return this;for(f=[],c=e=0;d>=0?d>=e:e>=d;c=d>=0?++e:--e)f.push(b.call(this,moment(this.start.valueOf()+a.valueOf()*c)));return f},a.prototype.overlaps=function(a){return null!==this.intersect(a)},a.prototype.intersect=function(b){var c,d,e,f,g,h,i,j;return this.start<=(d=b.start)&&d<(c=this.end)&&c<b.end?new a(b.start,this.end):b.start<(f=this.start)&&f<(e=b.end)&&e<=this.end?new a(this.start,b.end):b.start<(h=this.start)&&h<=(g=this.end)&&g<b.end?this:this.start<=(j=b.start)&&j<=(i=b.end)&&i<=this.end?b:null},a.prototype.add=function(b){return this.overlaps(b)?new a(moment.min(this.start,b.start),moment.max(this.end,b.end)):null},a.prototype.subtract=function(b){var c,d,e,f,g,h,i,j;return null===this.intersect(b)?[this]:b.start<=(d=this.start)&&d<(c=this.end)&&c<=b.end?[]:b.start<=(f=this.start)&&f<(e=b.end)&&e<this.end?[new a(b.end,this.end)]:this.start<(h=b.start)&&h<(g=this.end)&&g<=b.end?[new a(this.start,b.start)]:this.start<(j=b.start)&&j<(i=b.end)&&i<this.end?[new a(this.start,b.start),new a(b.end,this.end)]:void 0},a.prototype.by=function(a,b){return"string"==typeof a?this._by_string(a,b):this._by_range(a,b),this},a.prototype.valueOf=function(){return this.end-this.start},a.prototype.center=function(){var a;return a=this.start+this.diff()/2,moment(a)},a.prototype.toDate=function(){return[this.start.toDate(),this.end.toDate()]},a.prototype.isSame=function(a){return this.start.isSame(a.start)&&this.end.isSame(a.end)},a.prototype.diff=function(a){return null==a&&(a=void 0),this.end.diff(this.start,a)},a}(),moment.range=function(a,b){return a in INTERVALS?new DateRange(moment(this).startOf(a),moment(this).endOf(a)):new DateRange(a,b)},moment.range.constructor=DateRange,moment.fn.range=moment.range,moment.fn.within=function(a){return a.contains(this._d)}; |
@@ -48,2 +48,13 @@ (function(root, factory) { | ||
/** | ||
* Deep clone range | ||
* @return {!DateRange} | ||
* | ||
*/ | ||
DateRange.prototype.clone = function() { | ||
return moment().range(this.start, this.end); | ||
}; | ||
/** | ||
* Determine if the current interval contains a given moment/date/range. | ||
@@ -132,5 +143,5 @@ * | ||
return new DateRange(this.start, other.end); | ||
} else if (((other.start < (_ref5 = this.start) && _ref5 < (_ref4 = this.end)) && _ref4 < other.end)) { | ||
} else if (((other.start < (_ref5 = this.start) && _ref5 <= (_ref4 = this.end)) && _ref4 < other.end)) { | ||
return this; | ||
} else if (((this.start <= (_ref7 = other.start) && _ref7 < (_ref6 = other.end)) && _ref6 <= this.end)) { | ||
} else if (((this.start <= (_ref7 = other.start) && _ref7 <= (_ref6 = other.end)) && _ref6 <= this.end)) { | ||
return other; | ||
@@ -220,2 +231,15 @@ } else { | ||
/** | ||
* Center date of the range. | ||
* @return {!Moment} | ||
* | ||
*/ | ||
DateRange.prototype.center = function() { | ||
var center; | ||
center = this.start + this.diff() / 2; | ||
return moment(center); | ||
}; | ||
/** | ||
* Date range toDate | ||
@@ -282,3 +306,3 @@ * | ||
moment.fn.range = function(start, end) { | ||
moment.range = function(start, end) { | ||
if (start in INTERVALS) { | ||
@@ -292,10 +316,3 @@ return new DateRange(moment(this).startOf(start), moment(this).endOf(start)); | ||
/** | ||
* Build a date range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
* Expose constructor | ||
* | ||
@@ -305,7 +322,13 @@ */ | ||
moment.range = function(start, end) { | ||
return new DateRange(start, end); | ||
}; | ||
moment.range.constructor = DateRange; | ||
/** | ||
* @deprecated | ||
* | ||
*/ | ||
moment.fn.range = moment.range; | ||
/** | ||
* Check if the current moment is within a given date range. | ||
@@ -312,0 +335,0 @@ * |
@@ -1,1 +0,1 @@ | ||
!function(a,b){"object"==typeof exports?module.exports=b(require("moment")):"function"==typeof define&&define.amd?define(["moment"],b):a.moment=b(a.moment)}(this,function(a){var b,c;return c={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0},b=function(){function b(b,c){this.start=a(b),this.end=a(c)}return b.prototype.contains=function(a){return a instanceof b?this.start<=a.start&&this.end>=a.end:this.start<=a&&a<=this.end},b.prototype._by_string=function(b,c){var d,e;for(d=a(this.start),e=[];this.contains(d);)c.call(this,d.clone()),e.push(d.add(1,b));return e},b.prototype._by_range=function(b,c){var d,e,f,g;if(e=Math.floor(this/b),1/0===e)return this;for(g=[],d=f=0;e>=0?e>=f:f>=e;d=e>=0?++f:--f)g.push(c.call(this,a(this.start.valueOf()+b.valueOf()*d)));return g},b.prototype.overlaps=function(a){return null!==this.intersect(a)},b.prototype.intersect=function(a){var c,d,e,f,g,h,i,j;return this.start<=(d=a.start)&&d<(c=this.end)&&c<a.end?new b(a.start,this.end):a.start<(f=this.start)&&f<(e=a.end)&&e<=this.end?new b(this.start,a.end):a.start<(h=this.start)&&h<(g=this.end)&&g<a.end?this:this.start<=(j=a.start)&&j<(i=a.end)&&i<=this.end?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,d,e,f,g,h,i,j;return null===this.intersect(a)?[this]:a.start<=(d=this.start)&&d<(c=this.end)&&c<=a.end?[]:a.start<=(f=this.start)&&f<(e=a.end)&&e<this.end?[new b(a.end,this.end)]:this.start<(h=a.start)&&h<(g=this.end)&&g<=a.end?[new b(this.start,a.start)]:this.start<(j=a.start)&&j<(i=a.end)&&i<this.end?[new b(this.start,a.start),new b(a.end,this.end)]:void 0},b.prototype.by=function(a,b){return"string"==typeof a?this._by_string(a,b):this._by_range(a,b),this},b.prototype.valueOf=function(){return this.end-this.start},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 null==a&&(a=void 0),this.end.diff(this.start,a)},b}(),a.fn.range=function(d,e){return d in c?new b(a(this).startOf(d),a(this).endOf(d)):new b(d,e)},a.range=function(a,c){return new b(a,c)},a.fn.within=function(a){return a.contains(this._d)},a}); | ||
!function(a,b){"object"==typeof exports?module.exports=b(require("moment")):"function"==typeof define&&define.amd?define(["moment"],b):a.moment=b(a.moment)}(this,function(a){var b,c;return c={year:!0,month:!0,week:!0,day:!0,hour:!0,minute:!0,second:!0},b=function(){function b(b,c){this.start=a(b),this.end=a(c)}return b.prototype.clone=function(){return a().range(this.start,this.end)},b.prototype.contains=function(a){return a instanceof b?this.start<=a.start&&this.end>=a.end:this.start<=a&&a<=this.end},b.prototype._by_string=function(b,c){var d,e;for(d=a(this.start),e=[];this.contains(d);)c.call(this,d.clone()),e.push(d.add(1,b));return e},b.prototype._by_range=function(b,c){var d,e,f,g;if(e=Math.floor(this/b),1/0===e)return this;for(g=[],d=f=0;e>=0?e>=f:f>=e;d=e>=0?++f:--f)g.push(c.call(this,a(this.start.valueOf()+b.valueOf()*d)));return g},b.prototype.overlaps=function(a){return null!==this.intersect(a)},b.prototype.intersect=function(a){var c,d,e,f,g,h,i,j;return this.start<=(d=a.start)&&d<(c=this.end)&&c<a.end?new b(a.start,this.end):a.start<(f=this.start)&&f<(e=a.end)&&e<=this.end?new b(this.start,a.end):a.start<(h=this.start)&&h<=(g=this.end)&&g<a.end?this:this.start<=(j=a.start)&&j<=(i=a.end)&&i<=this.end?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,d,e,f,g,h,i,j;return null===this.intersect(a)?[this]:a.start<=(d=this.start)&&d<(c=this.end)&&c<=a.end?[]:a.start<=(f=this.start)&&f<(e=a.end)&&e<this.end?[new b(a.end,this.end)]:this.start<(h=a.start)&&h<(g=this.end)&&g<=a.end?[new b(this.start,a.start)]:this.start<(j=a.start)&&j<(i=a.end)&&i<this.end?[new b(this.start,a.start),new b(a.end,this.end)]:void 0},b.prototype.by=function(a,b){return"string"==typeof a?this._by_string(a,b):this._by_range(a,b),this},b.prototype.valueOf=function(){return this.end-this.start},b.prototype.center=function(){var b;return b=this.start+this.diff()/2,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 null==a&&(a=void 0),this.end.diff(this.start,a)},b}(),a.range=function(d,e){return d in c?new b(a(this).startOf(d),a(this).endOf(d)):new b(d,e)},a.range.constructor=b,a.fn.range=a.range,a.fn.within=function(a){return a.contains(this._d)},a}); |
@@ -24,3 +24,3 @@ { | ||
}, | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"engines": { | ||
@@ -44,3 +44,3 @@ "node": "*" | ||
"mocha": "^2.1.0", | ||
"should": "^4.6.5" | ||
"should": "^5.0.1" | ||
}, | ||
@@ -47,0 +47,0 @@ "repository": { |
@@ -170,3 +170,30 @@ moment-range | ||
### Center | ||
Calculate the center of a range | ||
``` javascript | ||
var start = new Date(2011, 2, 5); | ||
var end = new Date(2011, 3, 5); | ||
var dr = moment.range(start, end); | ||
dr.center(); // 1300622400000 | ||
``` | ||
### Clone | ||
Deep clone a range | ||
``` javascript | ||
var start = new Date(2011, 2, 5); | ||
var end = new Date(2011, 3, 5); | ||
var dr = moment.range(start, end); | ||
var dr2 = dr.clone(); | ||
dr2.start.add(2, 'days'); | ||
dr2.start.toDate() === dr.start.toDate() // false | ||
``` | ||
Installation | ||
@@ -173,0 +200,0 @@ ------------ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
52775
678
270