diff --git a/packages/scenes/src/core/SceneTimeRange.test.tsx b/packages/scenes/src/core/SceneTimeRange.test.tsx index 31fbaea98..68077ebc5 100644 --- a/packages/scenes/src/core/SceneTimeRange.test.tsx +++ b/packages/scenes/src/core/SceneTimeRange.test.tsx @@ -7,10 +7,6 @@ import { EmbeddedScene } from '../components/EmbeddedScene'; import { SceneReactObject } from '../components/SceneReactObject'; import { defaultTimeZone as browserTimeZone } from '@grafana/schema'; -jest.mock('@grafana/data', () => ({ - ...jest.requireActual('@grafana/data'), -})); - function simulateDelay(newDateString: string, scene: EmbeddedScene) { jest.setSystemTime(new Date(newDateString)); scene.activate(); diff --git a/packages/scenes/src/variables/interpolation/sceneInterpolator.test.ts b/packages/scenes/src/variables/interpolation/sceneInterpolator.test.ts index 603d7cb42..896c6d3bc 100644 --- a/packages/scenes/src/variables/interpolation/sceneInterpolator.test.ts +++ b/packages/scenes/src/variables/interpolation/sceneInterpolator.test.ts @@ -221,14 +221,26 @@ describe('sceneInterpolator', () => { expect(sceneInterpolator(scene, '$__all_variables', {}, VariableFormatID.PercentEncode)).toBe('var-cluster=A'); }); - it('Can use use $__url_time_range with browser timezone', () => { + it('Can use use $__url_time_range with explicit browser timezone', () => { + const scene = new TestScene({ + $timeRange: new SceneTimeRange({ from: 'now-5m', to: 'now', timeZone: 'browser' }), + }); + + // Browser timezone should be preserved as "browser", not resolved to actual timezone + expect(sceneInterpolator(scene, '$__url_time_range')).toBe('from=now-5m&to=now&timezone=browser'); + }); + + it('Can use use $__url_time_range when timezone is undefined', () => { const scene = new TestScene({ $timeRange: new SceneTimeRange({ from: 'now-5m', to: 'now' }), }); - expect(sceneInterpolator(scene, '$__url_time_range')).toBe( - `from=now-5m&to=now&timezone=${encodeURIComponent(Intl.DateTimeFormat().resolvedOptions().timeZone)}` - ); + // When timezone is undefined, getUrlState() will use getTimeZone() which resolves to browser default + // This should include the resolved timezone in the URL + const result = sceneInterpolator(scene, '$__url_time_range'); + expect(result).toContain('from=now-5m'); + expect(result).toContain('to=now'); + expect(result).toContain('timezone='); }); it('Can use use $__url_time_range with custom timezone', () => { diff --git a/packages/scenes/src/variables/macros/timeMacros.test.ts b/packages/scenes/src/variables/macros/timeMacros.test.ts index be3f61c9c..95a57aa20 100644 --- a/packages/scenes/src/variables/macros/timeMacros.test.ts +++ b/packages/scenes/src/variables/macros/timeMacros.test.ts @@ -8,14 +8,22 @@ import { LoadingState } from '@grafana/schema'; import { DataQueryRequest, getDefaultTimeRange } from '@grafana/data'; describe('timeMacros', () => { - it('Can use use $__url_time_range with browser timeZone', () => { + it('Can use use $__url_time_range with explicit browser timeZone', () => { const scene = new TestScene({ - $timeRange: new SceneTimeRange({ from: 'now-5m', to: 'now' }), + $timeRange: new SceneTimeRange({ from: 'now-5m', to: 'now', timeZone: 'browser' }), }); - expect(sceneInterpolator(scene, '$__url_time_range')).toBe( - `from=now-5m&to=now&timezone=${encodeURIComponent(Intl.DateTimeFormat().resolvedOptions().timeZone)}` - ); + // Browser timezone should be preserved as "browser", not resolved to actual timezone + expect(sceneInterpolator(scene, '$__url_time_range')).toBe('from=now-5m&to=now&timezone=browser'); + }); + + it('Can use use $__url_time_range when timezone is undefined', () => { + const scene = new TestScene({ + $timeRange: new SceneTimeRange({ from: 'now-5m', to: 'now', timeZone: 'browser' }), + }); + + // Browser timezone should be preserved as "browser", not resolved to actual timezone + expect(sceneInterpolator(scene, '$__url_time_range')).toBe('from=now-5m&to=now&timezone=browser'); }); it('Can use use $__url_time_range with custom timeZone', () => { diff --git a/packages/scenes/src/variables/macros/timeMacros.ts b/packages/scenes/src/variables/macros/timeMacros.ts index 8c43a1787..529890058 100644 --- a/packages/scenes/src/variables/macros/timeMacros.ts +++ b/packages/scenes/src/variables/macros/timeMacros.ts @@ -20,9 +20,6 @@ export class UrlTimeRangeMacro implements FormatVariable { public getValue(): SkipFormattingValue { const timeRange = getTimeRange(this._sceneObject); const urlState = timeRange.urlSync?.getUrlState(); - if (urlState?.timezone === 'browser') { - urlState.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; - } return new SkipFormattingValue(urlUtil.toUrlParams(urlState)); }