Themes: Fix issue generating themes due to code in @grafana/data accessing window object during module load (#27441)

This commit is contained in:
Torkel Ödegaard 2020-09-08 12:16:26 +02:00 committed by GitHub
parent f22f0a89a6
commit 6a9bfa19be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import {
dateTimeAsIsoNoDateIfToday,
dateTimeAsUS,
dateTimeAsUSNoDateIfToday,
dateTimeAsLocal,
getDateTimeAsLocalFormat,
dateTimeFromNow,
toClockMilliseconds,
toClockSeconds,
@ -176,7 +176,7 @@ export const getCategories = (): ValueFormatCategory[] => [
{ name: 'Datetime ISO (No date if today)', id: 'dateTimeAsIsoNoDateIfToday', fn: dateTimeAsIsoNoDateIfToday },
{ name: 'Datetime US', id: 'dateTimeAsUS', fn: dateTimeAsUS },
{ name: 'Datetime US (No date if today)', id: 'dateTimeAsUSNoDateIfToday', fn: dateTimeAsUSNoDateIfToday },
{ name: 'Datetime local', id: 'dateTimeAsLocal', fn: dateTimeAsLocal },
{ name: 'Datetime local', id: 'dateTimeAsLocal', fn: getDateTimeAsLocalFormat() },
{ name: 'From Now', id: 'dateTimeFromNow', fn: dateTimeFromNow },
],
},

View File

@ -369,16 +369,19 @@ export const dateTimeAsIso = toDateTimeValueFormatter('YYYY-MM-DD HH:mm:ss');
export const dateTimeAsIsoNoDateIfToday = toDateTimeValueFormatter('YYYY-MM-DD HH:mm:ss', 'HH:mm:ss');
export const dateTimeAsUS = toDateTimeValueFormatter('MM/DD/YYYY h:mm:ss a');
export const dateTimeAsUSNoDateIfToday = toDateTimeValueFormatter('MM/DD/YYYY h:mm:ss a', 'h:mm:ss a');
export const dateTimeAsLocal = toDateTimeValueFormatter(
localTimeFormat({
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
);
export function getDateTimeAsLocalFormat() {
return toDateTimeValueFormatter(
localTimeFormat({
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
);
}
export function dateTimeFromNow(
value: number,