From d56f75eb5caa258e4452dafea1b86a3ca4d51cc6 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:12:32 +0300 Subject: [PATCH] [v11.0.x] Time Zones: Fix relative time when using UTC timezone (#85779) Time Zones: Fix relative time when using UTC timezone (#85637) add UTC case to e2e test + let UTC pass through to moment.tz (cherry picked from commit 4b5b738646455dba714782c153f51ec208f0b9a4) Co-authored-by: Ashley Harrison --- .../dashboard-time-zone.spec.ts | 35 +++++++++++++++++++ .../src/datetime/moment_wrapper.ts | 4 --- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/e2e/dashboards-suite/dashboard-time-zone.spec.ts b/e2e/dashboards-suite/dashboard-time-zone.spec.ts index 00fcc14ad85..3c2844188e3 100644 --- a/e2e/dashboards-suite/dashboard-time-zone.spec.ts +++ b/e2e/dashboards-suite/dashboard-time-zone.spec.ts @@ -112,6 +112,41 @@ describe('Dashboard time zone support', () => { // Need to wait for 2 calls as there's 2 panels cy.wait(['@dataQuery', '@dataQuery']); + e2e.components.Panels.Panel.title('Panel with relative time override') + .should('be.visible') + .within(() => { + cy.contains('[role="row"]', '00:00:00').should('be.visible'); + }); + + e2e.components.Panels.Panel.title('Panel in timezone') + .should('be.visible') + .within(() => { + cy.contains('[role="row"]', '00:00:00').should('be.visible'); + }); + + // Test UTC timezone + e2e.flows.setTimeRange({ + from: 'now-6h', + to: 'now', + zone: 'Coordinated Universal Time', + }); + // Need to wait for 2 calls as there's 2 panels + cy.wait(['@dataQuery', '@dataQuery']); + + e2e.components.Panels.Panel.title('Panel with relative time override') + .should('be.visible') + .within(() => { + cy.contains('[role="row"]', '00:00:00').should('be.visible'); + }); + + // Today so far, still in UTC timezone + e2e.flows.setTimeRange({ + from: 'now/d', + to: 'now', + }); + // Need to wait for 2 calls as there's 2 panels + cy.wait(['@dataQuery', '@dataQuery']); + e2e.components.Panels.Panel.title('Panel with relative time override') .should('be.visible') .within(() => { diff --git a/packages/grafana-data/src/datetime/moment_wrapper.ts b/packages/grafana-data/src/datetime/moment_wrapper.ts index ae0f8d66ec1..0b97de1a3bf 100644 --- a/packages/grafana-data/src/datetime/moment_wrapper.ts +++ b/packages/grafana-data/src/datetime/moment_wrapper.ts @@ -126,10 +126,6 @@ export const dateTimeForTimeZone = ( input?: DateTimeInput, formatInput?: FormatInput ): DateTime => { - if (timezone === 'utc') { - return toUtc(input, formatInput); - } - if (timezone && timezone !== 'browser') { let result: moment.Moment;