Moment Range Split
A library to split and join moment ranges.
Installation
npm install moment-range-split --save
Usage
This library can be used to split ranges and join ranges.
Split
To split a range into multiple sub-ranges, specify the range and the interval on which to split:
const split = ; const range = moment;const ranges = ;console; // =>// [ { [Number: 60000]// start: moment("2017-10-11T19:01:00.000"),// end: moment("2017-10-11T19:02:00.000") },// { [Number: 60000]// start: moment("2017-10-11T19:02:00.000"),// end: moment("2017-10-11T19:03:00.000") },// { [Number: 60000]// start: moment("2017-10-11T19:03:00.000"),// end: moment("2017-10-11T19:04:00.000") },// { [Number: 60000]// start: moment("2017-10-11T19:04:00.000"),// end: moment("2017-10-11T19:05:00.000") } ]
Supported intervals are:
- minutely or minutes
- hourly or hours
- daily or days
- weekly or weeks
- monthly or months
- yearly or years
Join
To join an array of ranges, specify the array. The join()
function will merge adjacent or overlapping ranges.
const join = ; const range1 = moment;const range2 = moment;const range3 = moment; const ranges = ;console // =>// [ { [Number: 240000]// start: moment("2017-10-11T19:01:00.000"),// end: moment("2017-10-11T19:05:00.000") },// { [Number: 120000]// start: moment("2017-10-11T19:06:00.000"),// end: moment("2017-10-11T19:08:00.000") } ]