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:
Friedrich Mäckle 2021-09-02 12:47:25 +02:00 committed by GitHub
parent a5ce61b539
commit 8c8ccc8b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,12 +92,12 @@ export function localTimeFormat(
return fallback ?? DEFAULT_SYSTEM_DATE_FORMAT;
}
if (!locale) {
if (!locale && navigator) {
locale = [...navigator.languages];
}
// 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 hour12 = dateTimeFormat.resolvedOptions().hour12;