mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Allow negative offsets in TSVB * Fix linting issue
This commit is contained in:
parent
475c3bf84c
commit
12cac055c3
2 changed files with 34 additions and 3 deletions
|
@ -39,5 +39,36 @@ describe('offsetTime(req, by)', () => {
|
|||
.isSame(to)).to.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
it('should return a moment object for to and from offset by -2 minute', () => {
|
||||
const req = {
|
||||
payload: {
|
||||
timerange: {
|
||||
min: '2017-01-10T01:00:00Z',
|
||||
max: '2017-01-10T02:00:00Z'
|
||||
}
|
||||
}
|
||||
};
|
||||
const { from, to } = offsetTime(req, '-2m');
|
||||
expect(moment.isMoment(from)).to.equal(true);
|
||||
expect(moment.isMoment(to)).to.equal(true);
|
||||
expect(moment.utc('2017-01-10T01:02:00Z').isSame(from)).to.equal(true);
|
||||
expect(moment.utc('2017-01-10T02:02:00Z').isSame(to)).to.equal(true);
|
||||
});
|
||||
|
||||
it('should work when prefixing positive offsets with the plus sign', () => {
|
||||
const req = {
|
||||
payload: {
|
||||
timerange: {
|
||||
min: '2017-01-10T01:00:00Z',
|
||||
max: '2017-01-10T02:00:00Z'
|
||||
}
|
||||
}
|
||||
};
|
||||
const { from: fromSigned, to: toSigned } = offsetTime(req, '+1m');
|
||||
const { from, to } = offsetTime(req, '1m');
|
||||
|
||||
expect(fromSigned.isSame(from)).to.equal(true);
|
||||
expect(toSigned.isSame(to)).to.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import getTimerange from './helpers/get_timerange';
|
||||
export default function offsetTime(req, by) {
|
||||
const { from, to } = getTimerange(req);
|
||||
if (!/^([\d]+)([shmdwMy]|ms)$/.test(by)) return { from, to };
|
||||
const matches = by.match(/^([\d]+)([shmdwMy]|ms)$/);
|
||||
if (!/^[+-]?([\d]+)([shmdwMy]|ms)$/.test(by)) return { from, to };
|
||||
const matches = by.match(/^([+-]?[\d]+)([shmdwMy]|ms)$/);
|
||||
const offsetValue = Number(matches[1]);
|
||||
const offsetUnit = matches[2];
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue