mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user