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:
Haris Rozajac
2025-03-31 07:25:17 -06:00
committed by GitHub
parent 2439301515
commit 39c33d421b
4 changed files with 55 additions and 12 deletions
@@ -32,7 +32,7 @@ describe('dateTimeParse', () => {
const date = dateTimeParse('2025-03-12T07:09:37.253Z', { timeZone: 'browser' });
expect(date.isValid()).toBe(true);
expect(date.format()).toEqual('2025-03-12T02:09:37-05:00');
expect(date.format()).toEqual('2025-03-12T07:09:37Z');
});
it('should be able to parse array formats used by calendar', () => {
+11 -9
View File
@@ -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);