mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
support future time range
This commit is contained in:
@@ -82,8 +82,9 @@ function formatDate(date) {
|
||||
// now/d
|
||||
// if no to <expr> then to now is assumed
|
||||
export function describeTextRange(expr: any) {
|
||||
let isLast = (expr.indexOf('+') !== 0);
|
||||
if (expr.indexOf('now') === -1) {
|
||||
expr = 'now-' + expr;
|
||||
expr = (isLast ? 'now-' : 'now') + expr;
|
||||
}
|
||||
|
||||
let opt = rangeIndex[expr + ' to now'];
|
||||
@@ -91,15 +92,20 @@ export function describeTextRange(expr: any) {
|
||||
return opt;
|
||||
}
|
||||
|
||||
opt = {from: expr, to: 'now'};
|
||||
if (isLast) {
|
||||
opt = {from: expr, to: 'now'};
|
||||
} else {
|
||||
opt = {from: 'now', to: expr};
|
||||
}
|
||||
|
||||
let parts = /^now-(\d+)(\w)/.exec(expr);
|
||||
let parts = /^now([-+])(\d+)(\w)/.exec(expr);
|
||||
if (parts) {
|
||||
let unit = parts[2];
|
||||
let amount = parseInt(parts[1]);
|
||||
let unit = parts[3];
|
||||
let amount = parseInt(parts[2]);
|
||||
let span = spans[unit];
|
||||
if (span) {
|
||||
opt.display = 'Last ' + amount + ' ' + span.display;
|
||||
opt.display = isLast ? 'Last ' : 'Next ';
|
||||
opt.display += amount + ' ' + span.display;
|
||||
opt.section = span.section;
|
||||
if (amount > 1) {
|
||||
opt.display += 's';
|
||||
|
||||
@@ -31,6 +31,13 @@ describe("rangeUtil", () => {
|
||||
expect(info.from).to.be('now-13h')
|
||||
});
|
||||
|
||||
it('should handle non default future amount', () => {
|
||||
var info = rangeUtil.describeTextRange('+3h');
|
||||
expect(info.display).to.be('Next 3 hours')
|
||||
expect(info.from).to.be('now')
|
||||
expect(info.to).to.be('now+3h')
|
||||
});
|
||||
|
||||
it('should handle now/d', () => {
|
||||
var info = rangeUtil.describeTextRange('now/d');
|
||||
expect(info.display).to.be('Today so far');
|
||||
|
||||
Reference in New Issue
Block a user