From 2964a003d8b6670795771850e794bb1aa270a753 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 22 Sep 2021 15:09:14 +1200 Subject: [PATCH] Use and update the default grafana date formats so revert my hacks! --- conf/defaults.ini | 19 +++++++++++++------ .../grafana-data/src/datetime/rangeutil.ts | 5 ++--- .../DateTimePickers/TimeRangePicker.tsx | 7 +++---- public/app/features/metric/metricApi.ts | 3 +++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 2edd67ae9280..091b2c0b92d2 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -992,14 +992,21 @@ enable = # For information on what formatting patterns that are supported https://momentjs.com/docs/#/displaying/ # Default system date format used in time range picker and other places where full time is displayed -full_date = YYYY-MM-DD HH:mm:ss +# full_date = YYYY-MM-DD HH:mm:ss +full_date = ddd DD MMM YYYY h:mm a # Used by graph and other places where we only show small intervals -interval_second = HH:mm:ss -interval_minute = HH:mm -interval_hour = MM/DD HH:mm -interval_day = MM/DD -interval_month = YYYY-MM +# interval_second = HH:mm:ss +interval_second = H:mm:ss a +# interval_minute = HH:mm +interval_minute = h:mm a +# interval_hour = MM/DD HH:mm +interval_hour = D MMM h:mm a +# interval_day = MM/DD +interval_day = ddd D MMM +# interval_month = YYYY-MM +interval_month = MMM YYYY +# interval_year = YYYY interval_year = YYYY # Experimental feature diff --git a/packages/grafana-data/src/datetime/rangeutil.ts b/packages/grafana-data/src/datetime/rangeutil.ts index 17b5b8e5b781..15b52d443cbd 100644 --- a/packages/grafana-data/src/datetime/rangeutil.ts +++ b/packages/grafana-data/src/datetime/rangeutil.ts @@ -142,17 +142,16 @@ export function describeTextRange(expr: any) { * ``` * @category TimeUtils * @param range - a time range (usually specified by the TimePicker) - * @param format - time format * @alpha */ -export function describeTimeRange(range: RawTimeRange, timeZone?: TimeZone, format?: string): string { +export function describeTimeRange(range: RawTimeRange, timeZone?: TimeZone): string { const option = rangeIndex[range.from.toString() + ' to ' + range.to.toString()]; if (option) { return option.display; } - const options = { timeZone, format }; + const options = { timeZone }; if (isDateTime(range.from) && isDateTime(range.to)) { return dateTimeFormat(range.from, options) + ' to ' + dateTimeFormat(range.to, options); diff --git a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.tsx b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.tsx index 8771f0d2458a..0137df6d5587 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.tsx @@ -158,13 +158,12 @@ const ZoomOutTooltip = () => ( const TimePickerTooltip = ({ timeRange, timeZone }: { timeRange: TimeRange; timeZone?: TimeZone }) => { const theme = useTheme(); const styles = getLabelStyles(theme); - // TODO make configurable... . - const format = 'ddd, DD-MMM-YYYY hh:mm:ss a'; + return ( <> - {dateTimeFormat(timeRange.from, { timeZone, format })} + {dateTimeFormat(timeRange.from, { timeZone })}
to
- {dateTimeFormat(timeRange.to, { timeZone, format })} + {dateTimeFormat(timeRange.to, { timeZone })}
{timeZoneFormatUserFriendly(timeZone)}
diff --git a/public/app/features/metric/metricApi.ts b/public/app/features/metric/metricApi.ts index 8f229171b5e7..4f13e0749764 100644 --- a/public/app/features/metric/metricApi.ts +++ b/public/app/features/metric/metricApi.ts @@ -12,6 +12,9 @@ export function saveMetric(metric: Metric) { if (!metric.category) { metric.category = 'grafana'; } + if (!metric.source) { + metric.source = 'grafana'; + } if (!metric.values) { metric.values = {}; }