mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Include IANA timezone canonical name in TimeZoneInfo (#27591)
This commit is contained in:
parent
0e34474099
commit
7db050d9a4
@ -1,3 +1,5 @@
|
|||||||
|
process.env.TZ = 'UTC';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
verbose: false,
|
verbose: false,
|
||||||
transform: {
|
transform: {
|
||||||
|
31
packages/grafana-data/src/datetime/timezones.test.ts
Normal file
31
packages/grafana-data/src/datetime/timezones.test.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { getTimeZoneInfo } from './timezones';
|
||||||
|
import { setTimeZoneResolver } from './common';
|
||||||
|
|
||||||
|
describe('getTimeZoneInfo', () => {
|
||||||
|
// global timezone is set to UTC, see jest-config.js file
|
||||||
|
|
||||||
|
describe('IANA canonical name of the timezone', () => {
|
||||||
|
it('should resolve for default timezone', () => {
|
||||||
|
setTimeZoneResolver(() => 'browser');
|
||||||
|
const result = getTimeZoneInfo('', Date.now());
|
||||||
|
expect(result?.ianaName).toBe('Africa/Abidjan');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve for browser timezone', () => {
|
||||||
|
// global timezone is set to UTC
|
||||||
|
const result = getTimeZoneInfo('browser', Date.now());
|
||||||
|
expect(result?.ianaName).toBe('Africa/Abidjan');
|
||||||
|
});
|
||||||
|
it('should resolve for utc timezone', () => {
|
||||||
|
// global timezone is set to UTC
|
||||||
|
const result = getTimeZoneInfo('utc', Date.now());
|
||||||
|
expect(result?.ianaName).toBe('UTC');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve for given timezone', () => {
|
||||||
|
// global timezone is set to UTC
|
||||||
|
const result = getTimeZoneInfo('Europe/Warsaw', Date.now());
|
||||||
|
expect(result?.ianaName).toBe('Europe/Warsaw');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -30,6 +30,7 @@ export interface TimeZoneInfo {
|
|||||||
countries: TimeZoneCountry[];
|
countries: TimeZoneCountry[];
|
||||||
abbreviation: string;
|
abbreviation: string;
|
||||||
offsetInMins: number;
|
offsetInMins: number;
|
||||||
|
ianaName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupedTimeZones {
|
export interface GroupedTimeZones {
|
||||||
@ -98,6 +99,7 @@ const mapInternal = (zone: string, timestamp: number): TimeZoneInfo | undefined
|
|||||||
case InternalTimeZones.utc: {
|
case InternalTimeZones.utc: {
|
||||||
return {
|
return {
|
||||||
name: 'Coordinated Universal Time',
|
name: 'Coordinated Universal Time',
|
||||||
|
ianaName: 'UTC',
|
||||||
zone,
|
zone,
|
||||||
countries: [],
|
countries: [],
|
||||||
abbreviation: 'UTC, GMT',
|
abbreviation: 'UTC, GMT',
|
||||||
@ -115,6 +117,7 @@ const mapInternal = (zone: string, timestamp: number): TimeZoneInfo | undefined
|
|||||||
abbreviation: '',
|
abbreviation: '',
|
||||||
offsetInMins: 0,
|
offsetInMins: 0,
|
||||||
...info,
|
...info,
|
||||||
|
ianaName: (info as TimeZoneInfo).ianaName,
|
||||||
name: 'Default',
|
name: 'Default',
|
||||||
zone,
|
zone,
|
||||||
};
|
};
|
||||||
@ -130,6 +133,7 @@ const mapInternal = (zone: string, timestamp: number): TimeZoneInfo | undefined
|
|||||||
offsetInMins: new Date().getTimezoneOffset(),
|
offsetInMins: new Date().getTimezoneOffset(),
|
||||||
...info,
|
...info,
|
||||||
name: 'Browser Time',
|
name: 'Browser Time',
|
||||||
|
ianaName: (info as TimeZoneInfo).ianaName,
|
||||||
zone,
|
zone,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -148,13 +152,13 @@ const abbrevationWithoutOffset = (abbrevation: string): string => {
|
|||||||
|
|
||||||
const mapToInfo = (timeZone: TimeZone, timestamp: number): TimeZoneInfo | undefined => {
|
const mapToInfo = (timeZone: TimeZone, timestamp: number): TimeZoneInfo | undefined => {
|
||||||
const momentTz = moment.tz.zone(timeZone);
|
const momentTz = moment.tz.zone(timeZone);
|
||||||
|
|
||||||
if (!momentTz) {
|
if (!momentTz) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: timeZone,
|
name: timeZone,
|
||||||
|
ianaName: momentTz.name,
|
||||||
zone: timeZone,
|
zone: timeZone,
|
||||||
countries: countriesByTimeZone[timeZone] ?? [],
|
countries: countriesByTimeZone[timeZone] ?? [],
|
||||||
abbreviation: abbrevationWithoutOffset(momentTz.abbr(timestamp)),
|
abbreviation: abbrevationWithoutOffset(momentTz.abbr(timestamp)),
|
||||||
|
Loading…
Reference in New Issue
Block a user