moment-range
Advanced tools
Comparing version
@@ -23,4 +23,6 @@ var DateRange, INTERVALS; | ||
* DateRange instance. | ||
* @param {(Moment|Date)} start Start of interval. | ||
* @param {(Moment|Date)} end End of interval. | ||
* | ||
* @param {(Moment|Date)} start Start of interval | ||
* @param {(Moment|Date)} end End of interval | ||
* | ||
* @constructor | ||
@@ -37,3 +39,5 @@ * | ||
* Determine if the current interval contains a given moment/date/range. | ||
* @param {(Moment|Date|DateRange)} other Date to check. | ||
* | ||
* @param {(Moment|Date|DateRange)} other Date to check | ||
* | ||
* @return {!boolean} | ||
@@ -64,3 +68,3 @@ * | ||
hollaback.call(this, current.clone()); | ||
_results.push(current.add(interval, 1)); | ||
_results.push(current.add(1, interval)); | ||
} | ||
@@ -91,3 +95,5 @@ return _results; | ||
* Determine if the current date range overlaps a given date range. | ||
* @param {!DateRange} range Date range to check. | ||
* | ||
* @param {!DateRange} range Date range to check | ||
* | ||
* @return {!boolean} | ||
@@ -104,3 +110,5 @@ * | ||
* Determine the intersecting periods from one or more date ranges. | ||
* @param {!DateRange} other A date range to intersect with this one. | ||
* | ||
* @param {!DateRange} other A date range to intersect with this one | ||
* | ||
* @return {!DateRange|null} | ||
@@ -128,3 +136,5 @@ * | ||
* Subtract one range from another. | ||
* @param {!DateRange} other A date range to substract from this one. | ||
* | ||
* @param {!DateRange} other A date range to substract from this one | ||
* | ||
* @return {!DateRange[]} | ||
@@ -153,6 +163,8 @@ * | ||
* for each sub-range. | ||
* @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|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 | ||
* | ||
* @return {!boolean} | ||
@@ -174,2 +186,3 @@ * | ||
* Date range in milliseconds. Allows basic coercion math of date ranges. | ||
* | ||
* @return {!number} | ||
@@ -186,3 +199,4 @@ * | ||
* Date range toDate | ||
* @return {!Array} | ||
* | ||
* @return {!Array} | ||
* | ||
@@ -198,3 +212,5 @@ */ | ||
* Determine if this date range is the same as another. | ||
* @param {!DateRange} other Another date range to compare to. | ||
* | ||
* @param {!DateRange} other Another date range to compare to | ||
* | ||
* @return {!boolean} | ||
@@ -210,6 +226,9 @@ * | ||
/** | ||
* 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 | ||
* The difference of the end vs start. | ||
* | ||
* @param {number} unit Unit of difference, if no unit is passed in | ||
* milliseconds are returned. E.g.: `"days"`, | ||
* `"months"`, etc... | ||
* | ||
* @return {!number} | ||
* | ||
@@ -232,5 +251,8 @@ */ | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
@@ -251,5 +273,8 @@ * | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
@@ -266,4 +291,7 @@ * | ||
* Check if the current moment is within a given date range. | ||
* @param {!DateRange} range Date range to check. | ||
* | ||
* @param {!DateRange} range Date range to check | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!boolean} | ||
@@ -270,0 +298,0 @@ * |
@@ -34,4 +34,6 @@ (function(root, factory) { | ||
* DateRange instance. | ||
* @param {(Moment|Date)} start Start of interval. | ||
* @param {(Moment|Date)} end End of interval. | ||
* | ||
* @param {(Moment|Date)} start Start of interval | ||
* @param {(Moment|Date)} end End of interval | ||
* | ||
* @constructor | ||
@@ -48,3 +50,5 @@ * | ||
* Determine if the current interval contains a given moment/date/range. | ||
* @param {(Moment|Date|DateRange)} other Date to check. | ||
* | ||
* @param {(Moment|Date|DateRange)} other Date to check | ||
* | ||
* @return {!boolean} | ||
@@ -75,3 +79,3 @@ * | ||
hollaback.call(this, current.clone()); | ||
_results.push(current.add(interval, 1)); | ||
_results.push(current.add(1, interval)); | ||
} | ||
@@ -102,3 +106,5 @@ return _results; | ||
* Determine if the current date range overlaps a given date range. | ||
* @param {!DateRange} range Date range to check. | ||
* | ||
* @param {!DateRange} range Date range to check | ||
* | ||
* @return {!boolean} | ||
@@ -115,3 +121,5 @@ * | ||
* Determine the intersecting periods from one or more date ranges. | ||
* @param {!DateRange} other A date range to intersect with this one. | ||
* | ||
* @param {!DateRange} other A date range to intersect with this one | ||
* | ||
* @return {!DateRange|null} | ||
@@ -139,3 +147,5 @@ * | ||
* Subtract one range from another. | ||
* @param {!DateRange} other A date range to substract from this one. | ||
* | ||
* @param {!DateRange} other A date range to substract from this one | ||
* | ||
* @return {!DateRange[]} | ||
@@ -164,6 +174,8 @@ * | ||
* for each sub-range. | ||
* @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|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 | ||
* | ||
* @return {!boolean} | ||
@@ -185,2 +197,3 @@ * | ||
* Date range in milliseconds. Allows basic coercion math of date ranges. | ||
* | ||
* @return {!number} | ||
@@ -197,3 +210,4 @@ * | ||
* Date range toDate | ||
* @return {!Array} | ||
* | ||
* @return {!Array} | ||
* | ||
@@ -209,3 +223,5 @@ */ | ||
* Determine if this date range is the same as another. | ||
* @param {!DateRange} other Another date range to compare to. | ||
* | ||
* @param {!DateRange} other Another date range to compare to | ||
* | ||
* @return {!boolean} | ||
@@ -221,6 +237,9 @@ * | ||
/** | ||
* 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 | ||
* The difference of the end vs start. | ||
* | ||
* @param {number} unit Unit of difference, if no unit is passed in | ||
* milliseconds are returned. E.g.: `"days"`, | ||
* `"months"`, etc... | ||
* | ||
* @return {!number} | ||
* | ||
@@ -243,5 +262,8 @@ */ | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
@@ -262,5 +284,8 @@ * | ||
* Build a date range. | ||
* @param {(Moment|Date)} start Start of range. | ||
* @param {(Moment|Date)} end End of range. | ||
* | ||
* @param {(Moment|Date)} start Start of range | ||
* @param {(Moment|Date)} end End of range | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!DateRange} | ||
@@ -277,4 +302,7 @@ * | ||
* Check if the current moment is within a given date range. | ||
* @param {!DateRange} range Date range to check. | ||
* | ||
* @param {!DateRange} range Date range to check | ||
* | ||
* @this {Moment} | ||
* | ||
* @return {!boolean} | ||
@@ -281,0 +309,0 @@ * |
{ | ||
"name": "moment-range", | ||
"description": "Fancy date ranges for Moment.js", | ||
"author": "Gianni Chiappetta <gianni@runlevel6.org> (http://gf3.ca)", | ||
"author": "Gianni Chiappetta <gianni@runlevel6.org> (http://butt.zone)", | ||
"contributors": [ | ||
"Adam Biggs <adam.biggs@lightmaker.com>", | ||
"Matt Patterson <matt@reprocessed.org> (http://reprocessed.org/)", | ||
"Stuart Kelly <stuart.leigh83@gmail.com>", | ||
"Kevin Ross <kevin.ross@alienfast.com> (http://www.alienfast.com)", | ||
"Scott Hovestadt <scott.hovestadt@gmail.com>", | ||
"Nebel <nebel08@gmail.com>", | ||
"Aristide Niyungeko <niyungeko@gmail.com>", | ||
"Tymon Tobolski <i@teamon.eu> (http://teamon.eu)", | ||
"Bradley Ayers <bradley.ayers@gmail.com>", | ||
"Thomas Walpole <twalpole@gmail.com>" | ||
], | ||
"homepage": "https://github.com/gf3/moment-range", | ||
@@ -11,6 +23,10 @@ "bugs": "https://github.com/gf3/moment-range/issues", | ||
}, | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"scripts": { | ||
"build": "grunt coffee umd", | ||
"test": "grunt mochaTest" | ||
}, | ||
"dependencies": { | ||
@@ -17,0 +33,0 @@ "moment": ">= 1" |
@@ -15,5 +15,5 @@ moment-range | ||
``` javascript | ||
var start = new Date(2012, 0, 15) | ||
, end = new Date(2012, 4, 23) | ||
, range = moment().range(start, end); | ||
var start = new Date(2012, 0, 15); | ||
var end = new Date(2012, 4, 23); | ||
var range = moment().range(start, end); | ||
``` | ||
@@ -24,5 +24,5 @@ | ||
``` javascript | ||
var start = moment("2011-04-15", "YYYY-MM-DD") | ||
, end = moment("2011-11-27", "YYYY-MM-DD") | ||
, range = moment().range(start, end); | ||
var start = moment("2011-04-15", "YYYY-MM-DD"); | ||
var end = moment("2011-11-27", "YYYY-MM-DD"); | ||
var range = moment().range(start, end); | ||
``` | ||
@@ -35,8 +35,8 @@ | ||
``` javascript | ||
var start = new Date(2012, 4, 1) | ||
, end = new Date(2012, 4, 23) | ||
, lol = new Date(2012, 4, 15) | ||
, wat = new Date(2012, 2, 27) | ||
, range = moment().range(start, end) | ||
, range2 = moment().range(lol, wat); | ||
var start = new Date(2012, 4, 1); | ||
var end = new Date(2012, 4, 23); | ||
var lol = new Date(2012, 4, 15); | ||
var wat = new Date(2012, 2, 27); | ||
var range = moment().range(start, end); | ||
var range2 = moment().range(lol, wat); | ||
@@ -50,6 +50,6 @@ range.contains(lol); // true | ||
``` javascript | ||
var start = new Date(2012, 4, 1) | ||
, end = new Date(2012, 4, 23) | ||
, when = moment("2012-05-10", "YYYY-MM-DD") | ||
, range = moment().range(start, end); | ||
var start = new Date(2012, 4, 1); | ||
var end = new Date(2012, 4, 23); | ||
var when = moment("2012-05-10", "YYYY-MM-DD"); | ||
var range = moment().range(start, end); | ||
@@ -82,8 +82,8 @@ when.within(range); // true | ||
``` javascript | ||
var start = new Date(2012, 2, 1) | ||
, two = new Date(2012, 2, 2) | ||
, end = new Date(2012, 2, 5) | ||
, range1 = moment().range(start, end) | ||
, range2 = moment().range(start, two) // One day | ||
, acc = []; | ||
var start = new Date(2012, 2, 1); | ||
var two = new Date(2012, 2, 2); | ||
var end = new Date(2012, 2, 5); | ||
var range1 = moment().range(start, end); | ||
var range2 = moment().range(start, two); // One day | ||
var acc = []; | ||
@@ -114,4 +114,4 @@ range1.by('days', function(moment) { | ||
``` javascript | ||
var r_1 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)) | ||
, r_2 = moment().range(new Date(1995, 0, 1), new Date(1995, 12, 25)); | ||
var r_1 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)); | ||
var r_2 = moment().range(new Date(1995, 0, 1), new Date(1995, 12, 25)); | ||
@@ -130,11 +130,40 @@ r_2 > r_1 // true | ||
``` javascript | ||
var r_1 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)) | ||
, r_2 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)) | ||
, r_3 = moment().range(new Date(2011, 3, 5), new Date(2011, 6, 15)); | ||
var r_1 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)); | ||
var r_2 = moment().range(new Date(2011, 2, 5), new Date(2011, 3, 15)); | ||
var r_3 = moment().range(new Date(2011, 3, 5), new Date(2011, 6, 15)); | ||
r_1.isSame(r_2) // true | ||
r_2.isSame(r_3) // false | ||
r_1.isSame(r_2); // true | ||
r_2.isSame(r_3); // false | ||
``` | ||
### Difference | ||
The difference of the entire range given various units. | ||
Any of the units accepted by [moment.js' `add` | ||
method](http://momentjs.com/docs/#/manipulating/add/) may be used. | ||
``` javascript | ||
var start = new Date(2011, 2, 5); | ||
var end = new Date(2011, 5, 5); | ||
var dr = moment.range(start, end); | ||
dr.diff('months'); // 3 | ||
dr.diff('days'); // 92 | ||
dr.diff(); // 7945200000 | ||
``` | ||
### Conversion | ||
#### `toDate` | ||
``` javascript | ||
var start = new Date(2011, 2, 5); | ||
var end = new Date(2011, 5, 5); | ||
var dr = moment.range(start, end); | ||
dr.toDate(); // [new Date(2011, 2, 5), new Date(2011, 5, 5)] | ||
``` | ||
Installation | ||
@@ -192,6 +221,7 @@ ------------ | ||
Do all the things! (including the tests) | ||
Do all the things! | ||
``` bash | ||
$ grunt | ||
npm build | ||
npm test | ||
``` | ||
@@ -198,0 +228,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
41124
10.91%11
10%620
34.49%230
15%