mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #14285 from grafana/14280_fix_time_region
Fix time regions using zero hours
This commit is contained in:
commit
336fb4180f
@ -130,6 +130,33 @@ describe('TimeRegionManager', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
plotOptionsScenario('for time from/to region', ctx => {
|
||||||
|
const regions = [{ from: '00:00', to: '05:00', fill: true, colorMode: 'red' }];
|
||||||
|
const from = moment('2018-12-01T00:00+01:00');
|
||||||
|
const to = moment('2018-12-03T23:59+01:00');
|
||||||
|
ctx.setup(regions, from, to);
|
||||||
|
|
||||||
|
it('should add 3 markings', () => {
|
||||||
|
expect(ctx.options.grid.markings.length).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add one fill between 00:00 and 05:00 each day', () => {
|
||||||
|
const markings = ctx.options.grid.markings;
|
||||||
|
|
||||||
|
expect(moment(markings[0].xaxis.from).format()).toBe(moment('2018-12-01T01:00:00+01:00').format());
|
||||||
|
expect(moment(markings[0].xaxis.to).format()).toBe(moment('2018-12-01T06:00:00+01:00').format());
|
||||||
|
expect(markings[0].color).toBe(colorModes.red.color.fill);
|
||||||
|
|
||||||
|
expect(moment(markings[1].xaxis.from).format()).toBe(moment('2018-12-02T01:00:00+01:00').format());
|
||||||
|
expect(moment(markings[1].xaxis.to).format()).toBe(moment('2018-12-02T06:00:00+01:00').format());
|
||||||
|
expect(markings[1].color).toBe(colorModes.red.color.fill);
|
||||||
|
|
||||||
|
expect(moment(markings[2].xaxis.from).format()).toBe(moment('2018-12-03T01:00:00+01:00').format());
|
||||||
|
expect(moment(markings[2].xaxis.to).format()).toBe(moment('2018-12-03T06:00:00+01:00').format());
|
||||||
|
expect(markings[2].color).toBe(colorModes.red.color.fill);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
plotOptionsScenario('for day of week from/to region', ctx => {
|
plotOptionsScenario('for day of week from/to region', ctx => {
|
||||||
const regions = [{ fromDayOfWeek: 7, toDayOfWeek: 7, fill: true, colorMode: 'red' }];
|
const regions = [{ fromDayOfWeek: 7, toDayOfWeek: 7, fill: true, colorMode: 'red' }];
|
||||||
const from = moment('2018-01-01T18:45:05+01:00');
|
const from = moment('2018-01-01T18:45:05+01:00');
|
||||||
|
@ -87,6 +87,14 @@ export class TimeRegionManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timeRegion.from && !timeRegion.to) {
|
||||||
|
timeRegion.to = timeRegion.from;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timeRegion.from && timeRegion.to) {
|
||||||
|
timeRegion.from = timeRegion.to;
|
||||||
|
}
|
||||||
|
|
||||||
hRange = {
|
hRange = {
|
||||||
from: this.parseTimeRange(timeRegion.from),
|
from: this.parseTimeRange(timeRegion.from),
|
||||||
to: this.parseTimeRange(timeRegion.to),
|
to: this.parseTimeRange(timeRegion.to),
|
||||||
@ -108,21 +116,13 @@ export class TimeRegionManager {
|
|||||||
hRange.to.dayOfWeek = Number(timeRegion.toDayOfWeek);
|
hRange.to.dayOfWeek = Number(timeRegion.toDayOfWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hRange.from.h && hRange.to.h) {
|
if (hRange.from.dayOfWeek && hRange.from.h === null && hRange.from.m === null) {
|
||||||
hRange.from = hRange.to;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hRange.from.h && !hRange.to.h) {
|
|
||||||
hRange.to = hRange.from;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hRange.from.dayOfWeek && !hRange.from.h && !hRange.from.m) {
|
|
||||||
hRange.from.h = 0;
|
hRange.from.h = 0;
|
||||||
hRange.from.m = 0;
|
hRange.from.m = 0;
|
||||||
hRange.from.s = 0;
|
hRange.from.s = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hRange.to.dayOfWeek && !hRange.to.h && !hRange.to.m) {
|
if (hRange.to.dayOfWeek && hRange.to.h === null && hRange.to.m === null) {
|
||||||
hRange.to.h = 23;
|
hRange.to.h = 23;
|
||||||
hRange.to.m = 59;
|
hRange.to.m = 59;
|
||||||
hRange.to.s = 59;
|
hRange.to.s = 59;
|
||||||
|
Loading…
Reference in New Issue
Block a user