Skip to content

Commit 9c1c200

Browse files
[9.0] [Visualization-utils] Fix getTimezone default value (#220658) (#221171)
# Backport This will backport the following commits from `main` to `9.0`: - [[Visualization-utils] Fix getTimezone default value (#220658)](#220658) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Marco Vettorello","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-21T18:12:13Z","message":"[Visualization-utils] Fix getTimezone default value (#220658)\n\n## Summary\n\nfix https://github.com/elastic/kibana/issues/220644\n\nThis PR fixes the mentioned issue by defaulting any non-valid IANA\ntimezone to the current browser client timezone.\n\nI'm also calling `moment.tz.guess(true)` with the true value because if\nnot moment will cache the first timezone guessed and will not be updated\nif the customer change it manually.\n>By default Moment Timezone caches the detected timezone. This means\nthat subsequent calls to moment.tz.guess() will always return the same\nvalue.\nYou can call moment.tz.guess() with an optional boolean argument\n\"ignoreCache\". If set to true, the cache will be ignored and overwritten\nwith the new value.\n\n\n## Release note \n\nThe default timezone is now correctly applied in TSVB if the user\nchanges and resets to the default the Advanced Setting timezone\nparameter.","sha":"28cc698f043df75265632fa0def65e1121fa0c04","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:Visualizations","backport:prev-minor","backport:prev-major","v9.1.0"],"title":"[Visualization-utils] Fix getTimezone default value","number":220658,"url":"https://github.com/elastic/kibana/pull/220658","mergeCommit":{"message":"[Visualization-utils] Fix getTimezone default value (#220658)\n\n## Summary\n\nfix https://github.com/elastic/kibana/issues/220644\n\nThis PR fixes the mentioned issue by defaulting any non-valid IANA\ntimezone to the current browser client timezone.\n\nI'm also calling `moment.tz.guess(true)` with the true value because if\nnot moment will cache the first timezone guessed and will not be updated\nif the customer change it manually.\n>By default Moment Timezone caches the detected timezone. This means\nthat subsequent calls to moment.tz.guess() will always return the same\nvalue.\nYou can call moment.tz.guess() with an optional boolean argument\n\"ignoreCache\". If set to true, the cache will be ignored and overwritten\nwith the new value.\n\n\n## Release note \n\nThe default timezone is now correctly applied in TSVB if the user\nchanges and resets to the default the Advanced Setting timezone\nparameter.","sha":"28cc698f043df75265632fa0def65e1121fa0c04"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220658","number":220658,"mergeCommit":{"message":"[Visualization-utils] Fix getTimezone default value (#220658)\n\n## Summary\n\nfix https://github.com/elastic/kibana/issues/220644\n\nThis PR fixes the mentioned issue by defaulting any non-valid IANA\ntimezone to the current browser client timezone.\n\nI'm also calling `moment.tz.guess(true)` with the true value because if\nnot moment will cache the first timezone guessed and will not be updated\nif the customer change it manually.\n>By default Moment Timezone caches the detected timezone. This means\nthat subsequent calls to moment.tz.guess() will always return the same\nvalue.\nYou can call moment.tz.guess() with an optional boolean argument\n\"ignoreCache\". If set to true, the cache will be ignored and overwritten\nwith the new value.\n\n\n## Release note \n\nThe default timezone is now correctly applied in TSVB if the user\nchanges and resets to the default the Advanced Setting timezone\nparameter.","sha":"28cc698f043df75265632fa0def65e1121fa0c04"}}]}] BACKPORT--> Co-authored-by: Marco Vettorello <[email protected]>
1 parent 7e77ae8 commit 9c1c200

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)