Dashboards: Fix time range bug when use_browser_locale is enabled 2 (#102750)
* revert * make it work on initial load * add integration test; cleanup * fix test * fix
This commit is contained in:
@@ -53,29 +53,31 @@ export const dateTimeParse: DateTimeParser<DateTimeOptionsWhenParsing> = (value,
|
||||
};
|
||||
|
||||
const parseString = (value: string, options?: DateTimeOptionsWhenParsing): DateTime => {
|
||||
const parsed = parse(value, options?.roundUp, options?.timeZone, options?.fiscalYearStartMonth);
|
||||
if (value.indexOf('now') !== -1) {
|
||||
if (!isValid(value)) {
|
||||
return dateTime();
|
||||
}
|
||||
|
||||
const parsed = parse(value, options?.roundUp, options?.timeZone, options?.fiscalYearStartMonth);
|
||||
return parsed || dateTime();
|
||||
}
|
||||
|
||||
const timeZone = getTimeZone(options);
|
||||
let timeZone = getTimeZone(options);
|
||||
let format = options?.format ?? systemDateFormats.fullDate;
|
||||
if (value.endsWith('Z')) {
|
||||
// This is a special case when we have an ISO date string
|
||||
// In this case we want to force the format to be ISO and the timeZone to be UTC
|
||||
// This logic is needed for initial load when parsing the URL params
|
||||
format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
||||
timeZone = 'utc';
|
||||
}
|
||||
|
||||
const zone = moment.tz.zone(timeZone);
|
||||
const format = options?.format ?? systemDateFormats.fullDate;
|
||||
|
||||
if (zone && zone.name) {
|
||||
return dateTimeForTimeZone(zone.name, value, format);
|
||||
}
|
||||
|
||||
if (format === systemDateFormats.fullDate) {
|
||||
// We use parsed here to handle case when `use_browser_locale` is true
|
||||
// We need to pass the parsed value to handle case when value is an ISO 8601 date string
|
||||
return dateTime(parsed, format);
|
||||
}
|
||||
|
||||
switch (lowerCase(timeZone)) {
|
||||
case 'utc':
|
||||
return toUtc(value, format);
|
||||
|
||||
Reference in New Issue
Block a user