Timepicker step forward/backward should not overlap (#11131)

* Timepicker step forward/backward should not overlap
This PR fixes the step forward/backward buttons in the timepicker so that the ranges do not overlap. Prior to this PR, if you stepped forward/backward, the new range would include one millisecond of time in both ranges, which could result in documents being visible in both time ranges.

* Add unit for add/subtract methods
This commit is contained in:
Lukas Olson 2017-04-11 12:52:08 -07:00 committed by GitHub
parent 2fed5d3f22
commit 6752dfe168
2 changed files with 12 additions and 12 deletions

View file

@ -14,15 +14,15 @@ describe('timeNavigation', () => {
it('should step forward by the amount of the duration', () => {
const { from, to, mode } = timeNavigation.stepForward(bounds);
expect(from).to.be('2016-01-01T00:15:00.000Z');
expect(to).to.be('2016-01-01T00:30:00.000Z');
expect(from).to.be('2016-01-01T00:15:00.001Z');
expect(to).to.be('2016-01-01T00:30:00.001Z');
expect(mode).to.be('absolute');
});
it('should step backward by the amount of the duration', () => {
const { from, to, mode } = timeNavigation.stepBackward(bounds);
expect(from).to.be('2015-12-31T23:45:00.000Z');
expect(to).to.be('2016-01-01T00:00:00.000Z');
expect(from).to.be('2015-12-31T23:44:59.999Z');
expect(to).to.be('2015-12-31T23:59:59.999Z');
expect(mode).to.be('absolute');
});

View file

@ -5,8 +5,8 @@ export default {
stepForward({ min, max }) {
const diff = max.diff(min);
return {
from: max.toISOString(),
to: moment(max).add(diff).toISOString(),
from: moment(max).add(1, 'ms').toISOString(),
to: moment(max).add(diff + 1, 'ms').toISOString(),
mode: 'absolute'
};
},
@ -15,8 +15,8 @@ export default {
stepBackward({ min, max }) {
const diff = max.diff(min);
return {
from: moment(min).subtract(diff).toISOString(),
to: min.toISOString(),
from: moment(min).subtract(diff + 1, 'ms').toISOString(),
to: moment(min).subtract(1, 'ms').toISOString(),
mode: 'absolute'
};
},
@ -25,8 +25,8 @@ export default {
zoomOut({ min, max }) {
const diff = max.diff(min);
return {
from: moment(min).subtract(diff / 2).toISOString(),
to: moment(max).add(diff / 2).toISOString(),
from: moment(min).subtract(diff / 2, 'ms').toISOString(),
to: moment(max).add(diff / 2, 'ms').toISOString(),
mode: 'absolute'
};
},
@ -35,8 +35,8 @@ export default {
zoomIn({ min, max }) {
const diff = max.diff(min);
return {
from: moment(min).add(diff / 4).toISOString(),
to: moment(max).subtract(diff / 4).toISOString(),
from: moment(min).add(diff / 4, 'ms').toISOString(),
to: moment(max).subtract(diff / 4, 'ms').toISOString(),
mode: 'absolute'
};
}