moment-range
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "moment-range", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "./lib/moment-range.js", | ||
@@ -11,3 +11,3 @@ "ignore": [ | ||
"dependencies": { | ||
"momentjs": ">= 1" | ||
"moment": ">= 1" | ||
}, | ||
@@ -14,0 +14,0 @@ "devDependencies": { |
@@ -0,1 +1,13 @@ | ||
var DateRange, INTERVALS; | ||
INTERVALS = { | ||
year: true, | ||
month: true, | ||
week: true, | ||
day: true, | ||
hour: true, | ||
minute: true, | ||
second: true | ||
}; | ||
/** | ||
@@ -7,3 +19,2 @@ * DateRange class to store ranges and query dates. | ||
var DateRange; | ||
@@ -34,3 +45,3 @@ DateRange = (function() { | ||
if (other instanceof DateRange) { | ||
return this.start < other.start && this.end > other.end; | ||
return this.start <= other.start && this.end >= other.end; | ||
} else { | ||
@@ -190,2 +201,18 @@ return (this.start <= other && other <= this.end); | ||
/** | ||
* Return the difference of the end vs start. | ||
* - To get the difference in milliseconds, use range#diff | ||
* - To get the difference in another unit of measurement, pass that measurement as the second argument. | ||
* @return milliseconds if no measure is passed in, otherwise an increment of measure | ||
* | ||
*/ | ||
DateRange.prototype.diff = function(unit) { | ||
if (unit == null) { | ||
unit = void 0; | ||
} | ||
return this.end.diff(this.start, unit); | ||
}; | ||
return DateRange; | ||
@@ -206,3 +233,3 @@ | ||
moment.fn.range = function(start, end) { | ||
if (['year', 'month', 'week', 'day', 'hour', 'minute', 'second'].indexOf(start) > -1) { | ||
if (start in INTERVALS) { | ||
return new DateRange(moment(this).startOf(start), moment(this).endOf(start)); | ||
@@ -215,2 +242,16 @@ } else { | ||
/** | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* @this {Moment} | ||
* @return {!DateRange} | ||
* | ||
*/ | ||
moment.range = function(start, end) { | ||
return new DateRange(start, end); | ||
}; | ||
/** | ||
* Check if the current moment is within a given date range. | ||
@@ -217,0 +258,0 @@ * @param {!DateRange} range Date range to check. |
@@ -12,2 +12,14 @@ (function(root, factory) { | ||
}(this, function(moment) { | ||
var DateRange, INTERVALS; | ||
INTERVALS = { | ||
year: true, | ||
month: true, | ||
week: true, | ||
day: true, | ||
hour: true, | ||
minute: true, | ||
second: true | ||
}; | ||
/** | ||
@@ -19,3 +31,2 @@ * DateRange class to store ranges and query dates. | ||
var DateRange; | ||
@@ -46,3 +57,3 @@ DateRange = (function() { | ||
if (other instanceof DateRange) { | ||
return this.start < other.start && this.end > other.end; | ||
return this.start <= other.start && this.end >= other.end; | ||
} else { | ||
@@ -202,2 +213,18 @@ return (this.start <= other && other <= this.end); | ||
/** | ||
* Return the difference of the end vs start. | ||
* - To get the difference in milliseconds, use range#diff | ||
* - To get the difference in another unit of measurement, pass that measurement as the second argument. | ||
* @return milliseconds if no measure is passed in, otherwise an increment of measure | ||
* | ||
*/ | ||
DateRange.prototype.diff = function(unit) { | ||
if (unit == null) { | ||
unit = void 0; | ||
} | ||
return this.end.diff(this.start, unit); | ||
}; | ||
return DateRange; | ||
@@ -218,3 +245,3 @@ | ||
moment.fn.range = function(start, end) { | ||
if (['year', 'month', 'week', 'day', 'hour', 'minute', 'second'].indexOf(start) > -1) { | ||
if (start in INTERVALS) { | ||
return new DateRange(moment(this).startOf(start), moment(this).endOf(start)); | ||
@@ -227,2 +254,16 @@ } else { | ||
/** | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* @this {Moment} | ||
* @return {!DateRange} | ||
* | ||
*/ | ||
moment.range = function(start, end) { | ||
return new DateRange(start, end); | ||
}; | ||
/** | ||
* Check if the current moment is within a given date range. | ||
@@ -229,0 +270,0 @@ * @param {!DateRange} range Date range to check. |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"engines": { | ||
@@ -14,0 +14,0 @@ "node": "*" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37079
461