Skip to content

Commit 28cc698

Browse files
authored
[Visualization-utils] Fix getTimezone default value (#220658)
## Summary fix #220644 This PR fixes the mentioned issue by defaulting any non-valid IANA timezone to the current browser client timezone. I'm also calling `moment.tz.guess(true)` with the true value because if not moment will cache the first timezone guessed and will not be updated if the customer change it manually. >By default Moment Timezone caches the detected timezone. This means that subsequent calls to moment.tz.guess() will always return the same value. You can call moment.tz.guess() with an optional boolean argument "ignoreCache". If set to true, the cache will be ignored and overwritten with the new value. ## Release note The default timezone is now correctly applied in TSVB if the user changes and resets to the default the Advanced Setting timezone parameter.
1 parent b431638 commit 28cc698

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/platform/packages/shared/kbn-visualization-utils/src/get_timezone.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ describe('getTimeZone', () => {
2828
expect(
2929
getTimeZone({
3030
get: () => 'Browser',
31-
isDefault: () => true,
3231
} as unknown as IUiSettingsClient)
3332
).toEqual('America/New_York');
3433
});
@@ -38,7 +37,6 @@ describe('getTimeZone', () => {
3837
expect(
3938
getTimeZone({
4039
get: () => timezone,
41-
isDefault: () => false,
4240
} as unknown as IUiSettingsClient)
4341
).toEqual(timezone);
4442
});

src/platform/packages/shared/kbn-visualization-utils/src/get_timezone.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import type { IUiSettingsClient } from '@kbn/core/public';
1414
* Get timeZone from uiSettings
1515
*/
1616
export function getTimeZone(uiSettings: IUiSettingsClient) {
17-
if (uiSettings.isDefault('dateFormat:tz')) {
18-
const detectedTimeZone = moment.tz.guess();
19-
return detectedTimeZone || moment().format('Z');
20-
} else {
21-
return uiSettings.get('dateFormat:tz', 'Browser');
22-
}
17+
const timeZone = uiSettings.get('dateFormat:tz');
18+
return moment.tz.zone(timeZone)?.name ?? moment.tz.guess(true);
2319
}

src/platform/plugins/shared/vis_types/timeseries/public/application/components/vis_types/timeseries/vis.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ describe('TimeseriesVisualization', () => {
5353
});
5454

5555
setUISettings({
56-
get: () => ({}),
56+
get: (key) => {
57+
key === 'dateFormat:tz' ? 'Browser' : {};
58+
},
5759
isDefault: () => true,
5860
});
5961

0 commit comments

Comments
 (0)