| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = newInterval;
|
|---|
| 7 | var t0 = new Date(),
|
|---|
| 8 | t1 = new Date();
|
|---|
| 9 | function newInterval(floori, offseti, count, field) {
|
|---|
| 10 | function interval(date) {
|
|---|
| 11 | return floori(date = arguments.length === 0 ? new Date() : new Date(+date)), date;
|
|---|
| 12 | }
|
|---|
| 13 | interval.floor = function (date) {
|
|---|
| 14 | return floori(date = new Date(+date)), date;
|
|---|
| 15 | };
|
|---|
| 16 | interval.ceil = function (date) {
|
|---|
| 17 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
|---|
| 18 | };
|
|---|
| 19 | interval.round = function (date) {
|
|---|
| 20 | var d0 = interval(date),
|
|---|
| 21 | d1 = interval.ceil(date);
|
|---|
| 22 | return date - d0 < d1 - date ? d0 : d1;
|
|---|
| 23 | };
|
|---|
| 24 | interval.offset = function (date, step) {
|
|---|
| 25 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
|---|
| 26 | };
|
|---|
| 27 | interval.range = function (start, stop, step) {
|
|---|
| 28 | var range = [],
|
|---|
| 29 | previous;
|
|---|
| 30 | start = interval.ceil(start);
|
|---|
| 31 | step = step == null ? 1 : Math.floor(step);
|
|---|
| 32 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
|---|
| 33 | do range.push(previous = new Date(+start)), offseti(start, step), floori(start); while (previous < start && start < stop);
|
|---|
| 34 | return range;
|
|---|
| 35 | };
|
|---|
| 36 | interval.filter = function (test) {
|
|---|
| 37 | return newInterval(function (date) {
|
|---|
| 38 | if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
|
|---|
| 39 | }, function (date, step) {
|
|---|
| 40 | if (date >= date) {
|
|---|
| 41 | if (step < 0) while (++step <= 0) {
|
|---|
| 42 | while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
|
|---|
| 43 | } else while (--step >= 0) {
|
|---|
| 44 | while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | });
|
|---|
| 48 | };
|
|---|
| 49 | if (count) {
|
|---|
| 50 | interval.count = function (start, end) {
|
|---|
| 51 | t0.setTime(+start), t1.setTime(+end);
|
|---|
| 52 | floori(t0), floori(t1);
|
|---|
| 53 | return Math.floor(count(t0, t1));
|
|---|
| 54 | };
|
|---|
| 55 | interval.every = function (step) {
|
|---|
| 56 | step = Math.floor(step);
|
|---|
| 57 | return !isFinite(step) || !(step > 0) ? null : !(step > 1) ? interval : interval.filter(field ? function (d) {
|
|---|
| 58 | return field(d) % step === 0;
|
|---|
| 59 | } : function (d) {
|
|---|
| 60 | return interval.count(0, d) % step === 0;
|
|---|
| 61 | });
|
|---|
| 62 | };
|
|---|
| 63 | }
|
|---|
| 64 | return interval;
|
|---|
| 65 | } |
|---|