Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/scenes/src/core/SceneTimeRange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
18 changes: 13 additions & 5 deletions packages/scenes/src/variables/macros/timeMacros.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/scenes/src/variables/macros/timeMacros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down