mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Check navigator property exists before accessing it (#38745)
* Check navigator property exists before acecssing it * fix: pass undefined to Intl.DateTimeFormat if no locale can be determined * Update packages/grafana-data/src/datetime/formats.ts replacing ternary by or Co-authored-by: Ashley Harrison <ashharrison90@gmail.com> Co-authored-by: Ashley Harrison <ashharrison90@gmail.com>
This commit is contained in:
parent
a5ce61b539
commit
8c8ccc8b91
@ -92,12 +92,12 @@ export function localTimeFormat(
|
|||||||
return fallback ?? DEFAULT_SYSTEM_DATE_FORMAT;
|
return fallback ?? DEFAULT_SYSTEM_DATE_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!locale) {
|
if (!locale && navigator) {
|
||||||
locale = [...navigator.languages];
|
locale = [...navigator.languages];
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://momentjs.com/docs/#/displaying/format/
|
// https://momentjs.com/docs/#/displaying/format/
|
||||||
const dateTimeFormat = new Intl.DateTimeFormat(locale, options);
|
const dateTimeFormat = new Intl.DateTimeFormat(locale || undefined, options);
|
||||||
const parts = dateTimeFormat.formatToParts(new Date());
|
const parts = dateTimeFormat.formatToParts(new Date());
|
||||||
const hour12 = dateTimeFormat.resolvedOptions().hour12;
|
const hour12 = dateTimeFormat.resolvedOptions().hour12;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user