(floori, offseti, count, field)
| 15628 | const t0 = new Date, t1 = new Date; |
| 15629 | |
| 15630 | function timeInterval(floori, offseti, count, field) { |
| 15631 | |
| 15632 | function interval(date) { |
| 15633 | return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date; |
| 15634 | } |
| 15635 | |
| 15636 | interval.floor = (date) => { |
| 15637 | return floori(date = new Date(+date)), date; |
| 15638 | }; |
| 15639 | |
| 15640 | interval.ceil = (date) => { |
| 15641 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date; |
| 15642 | }; |
| 15643 | |
| 15644 | interval.round = (date) => { |
| 15645 | const d0 = interval(date), d1 = interval.ceil(date); |
| 15646 | return date - d0 < d1 - date ? d0 : d1; |
| 15647 | }; |
| 15648 | |
| 15649 | interval.offset = (date, step) => { |
| 15650 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date; |
| 15651 | }; |
| 15652 | |
| 15653 | interval.range = (start, stop, step) => { |
| 15654 | const range = []; |
| 15655 | start = interval.ceil(start); |
| 15656 | step = step == null ? 1 : Math.floor(step); |
| 15657 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date |
| 15658 | let previous; |
| 15659 | do range.push(previous = new Date(+start)), offseti(start, step), floori(start); |
| 15660 | while (previous < start && start < stop); |
| 15661 | return range; |
| 15662 | }; |
| 15663 | |
| 15664 | interval.filter = (test) => { |
| 15665 | return timeInterval((date) => { |
| 15666 | if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1); |
| 15667 | }, (date, step) => { |
| 15668 | if (date >= date) { |
| 15669 | if (step < 0) while (++step <= 0) { |
| 15670 | while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty |
| 15671 | } else while (--step >= 0) { |
| 15672 | while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty |
| 15673 | } |
| 15674 | } |
| 15675 | }); |
| 15676 | }; |
| 15677 | |
| 15678 | if (count) { |
| 15679 | interval.count = (start, end) => { |
| 15680 | t0.setTime(+start), t1.setTime(+end); |
| 15681 | floori(t0), floori(t1); |
| 15682 | return Math.floor(count(t0, t1)); |
| 15683 | }; |
| 15684 | |
| 15685 | interval.every = (step) => { |
| 15686 | step = Math.floor(step); |
| 15687 | return !isFinite(step) || !(step > 0) ? null |
no test coverage detected