Explore: parse time range fix (#28467)

* Explore: parse time range fix

* Remove commented out code

* Fix cases for string epoch and ISO strings

Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
This commit is contained in:
Zoltán Bedi
2020-10-22 14:37:07 +02:00
committed by GitHub
parent 48e753d888
commit ce1f7908c8
2 changed files with 53 additions and 2 deletions

View File

@@ -23,6 +23,8 @@ import {
urlUtil,
ExploreUrlState,
rangeUtil,
DateTime,
isDateTime,
} from '@grafana/data';
import store from 'app/core/store';
import { v4 as uuidv4 } from 'uuid';
@@ -355,11 +357,15 @@ export const getTimeRange = (timeZone: TimeZone, rawRange: RawTimeRange): TimeRa
};
};
const parseRawTime = (value: any): TimeFragment | null => {
const parseRawTime = (value: string | DateTime): TimeFragment | null => {
if (value === null) {
return null;
}
if (isDateTime(value)) {
return value;
}
if (value.indexOf('now') !== -1) {
return value;
}
@@ -374,11 +380,18 @@ const parseRawTime = (value: any): TimeFragment | null => {
return toUtc(value, 'YYYY-MM-DD HH:mm:ss');
}
if (!isNaN(value)) {
// This should handle cases where value is an epoch time as string
if (value.match(/^\d+$/)) {
const epoch = parseInt(value, 10);
return toUtc(epoch);
}
// This should handle ISO strings
const time = toUtc(value);
if (time.isValid()) {
return time;
}
return null;
};