Elasticsearch: Add time zone setting to Date Histogram aggregation (#40882)

* TimeZonePicker: Allow specifying internal timezones to display

* Elasticsearch: Add time zone setting to Date Histogram aggregation

* rename time_zone to timeZone

* Add tests

* fix typo

* Update packages/grafana-data/src/datetime/timezones.ts

Co-authored-by: Chris Cowan <chris@chriscowan.us>

Co-authored-by: Chris Cowan <chris@chriscowan.us>
This commit is contained in:
Giordano Ricci
2021-11-02 16:18:39 +00:00
committed by GitHub
co-authored by Chris Cowan
parent de83e5702c
commit 7b7c193551
10 changed files with 146 additions and 28 deletions
+26 -22
View File
@@ -48,11 +48,13 @@ export const getTimeZoneInfo = (zone: string, timestamp: number): TimeZoneInfo |
return mapToInfo(zone, timestamp);
};
export const getTimeZones = memoize((includeInternal = false): TimeZone[] => {
export const getTimeZones = memoize((includeInternal: boolean | InternalTimeZones[] = false): TimeZone[] => {
const initial: TimeZone[] = [];
if (includeInternal) {
initial.push.apply(initial, [InternalTimeZones.default, InternalTimeZones.localBrowserTime, InternalTimeZones.utc]);
if (includeInternal === true) {
initial.push(InternalTimeZones.default, InternalTimeZones.localBrowserTime, InternalTimeZones.utc);
} else if (includeInternal) {
initial.push(...includeInternal);
}
return moment.tz.names().reduce((zones: TimeZone[], zone: string) => {
@@ -67,32 +69,34 @@ export const getTimeZones = memoize((includeInternal = false): TimeZone[] => {
}, initial);
});
export const getTimeZoneGroups = memoize((includeInternal = false): GroupedTimeZones[] => {
const timeZones = getTimeZones(includeInternal);
export const getTimeZoneGroups = memoize(
(includeInternal: boolean | InternalTimeZones[] = false): GroupedTimeZones[] => {
const timeZones = getTimeZones(includeInternal);
const groups = timeZones.reduce((groups: Record<string, TimeZone[]>, zone: TimeZone) => {
const delimiter = zone.indexOf('/');
const groups = timeZones.reduce((groups: Record<string, TimeZone[]>, zone: TimeZone) => {
const delimiter = zone.indexOf('/');
if (delimiter === -1) {
const group = '';
if (delimiter === -1) {
const group = '';
groups[group] = groups[group] ?? [];
groups[group].push(zone);
return groups;
}
const group = zone.substr(0, delimiter);
groups[group] = groups[group] ?? [];
groups[group].push(zone);
return groups;
}
}, {});
const group = zone.substr(0, delimiter);
groups[group] = groups[group] ?? [];
groups[group].push(zone);
return groups;
}, {});
return Object.keys(groups).map((name) => ({
name,
zones: groups[name],
}));
});
return Object.keys(groups).map((name) => ({
name,
zones: groups[name],
}));
}
);
const mapInternal = (zone: string, timestamp: number): TimeZoneInfo | undefined => {
switch (zone) {