[release-11.6.0] Dashboards: Fix time range bug when use_browser_locale is enabled (#102396)

Dashboards: Fix time range bug when use_browser_locale is enabled (#102339)

* fix

* update

* fix tests and update

(cherry picked from commit 32756a6c30)

Co-authored-by: Haris Rozajac <58232930+harisrozajac@users.noreply.github.com>
pull/102531/head
grafana-delivery-bot[bot] 3 months ago committed by GitHub
parent 07698ebbaa
commit 08d88bacc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      packages/grafana-data/src/datetime/parser.test.ts
  2. 8
      packages/grafana-data/src/datetime/parser.ts

@ -23,6 +23,18 @@ describe('dateTimeParse', () => {
expect(date.format()).toEqual('2020-08-20T10:30:20Z');
});
it('should be able to parse ISO 8601 date strings when useBrowserLocale is true', () => {
systemDateFormats.update({
fullDate: 'YYYY-MM-DD HH:mm:ss.SSS',
interval: {} as SystemDateFormatsState['interval'],
useBrowserLocale: true,
});
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');
});
it('should be able to parse array formats used by calendar', () => {
const date = dateTimeParse([2020, 5, 10, 10, 30, 20], { timeZone: 'utc' });
expect(date.format()).toEqual('2020-06-10T10:30:20Z');

@ -53,12 +53,12 @@ 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();
}
@ -70,6 +70,12 @@ const parseString = (value: string, options?: DateTimeOptionsWhenParsing): DateT
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);

Loading…
Cancel
Save