DashboardScenes: Fix issue where timezone was not considered in relative time override (#99316)

* Fix issue where timezone was not considered in relative time override

* fix
pull/99332/head
Victor Marin 4 months ago committed by GitHub
parent 5532d7007c
commit eaca8e501f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      public/app/features/dashboard-scene/scene/PanelTimeRange.test.tsx
  2. 5
      public/app/features/dashboard-scene/scene/PanelTimeRange.tsx

@ -97,6 +97,20 @@ describe('PanelTimeRange', () => {
expect(panelTime.state.from).toBe('now-12h');
expect(panelTime.state.to).toBe('now-2h');
});
it('should properly apply timeZone', () => {
const panelTime = new PanelTimeRange({ timeFrom: '2h' });
const panel = new SceneCanvasText({ text: 'Hello', $timeRange: panelTime });
const scene = new SceneFlexLayout({
$timeRange: new SceneTimeRange({ from: 'now-6h', to: 'now', timeZone: 'utc' }),
children: [new SceneFlexItem({ body: panel })],
});
activateFullSceneTree(scene);
expect(panelTime.state.value.from.format('Z')).toBe('+00:00'); // UTC
expect(panelTime.state.value.to.format('Z')).toBe('+00:00'); // UTC
});
});
function buildAndActivateSceneFor(panelTime: PanelTimeRange) {

@ -81,10 +81,11 @@ export class PanelTimeRange extends SceneTimeRangeTransformerBase<PanelTimeRange
// Only evaluate if the timeFrom if parent time is relative
if (rangeUtil.isRelativeTimeRange(parentTimeRange.raw)) {
const timeZone = this.getTimeZone();
newTimeData.timeInfo = timeFromInfo.display;
newTimeData.timeRange = {
from: dateMath.parse(timeFromInfo.from)!,
to: dateMath.parse(timeFromInfo.to)!,
from: dateMath.parse(timeFromInfo.from, undefined, timeZone)!,
to: dateMath.parse(timeFromInfo.to, undefined, timeZone)!,
raw: { from: timeFromInfo.from, to: timeFromInfo.to },
};
}

Loading…
Cancel
Save