From adfd39e5fd6895d9fa1f2e79d76305fcc1b5fa5a Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 8 Nov 2021 09:36:10 -0700 Subject: [PATCH] Chore: Fixed failing e2e due to day light saving time. (#41417) (#41422) (cherry picked from commit dce851e396672f3c3f7e4916fb383c7665ce42ce) Co-authored-by: Marcus Andersson --- e2e/suite1/specs/dashboard-time-zone.spec.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/e2e/suite1/specs/dashboard-time-zone.spec.ts b/e2e/suite1/specs/dashboard-time-zone.spec.ts index e0be47065e0..144601c302d 100644 --- a/e2e/suite1/specs/dashboard-time-zone.spec.ts +++ b/e2e/suite1/specs/dashboard-time-zone.spec.ts @@ -10,9 +10,9 @@ e2e.scenario({ scenario: () => { e2e.flows.openDashboard({ uid: '5SdHCasdf' }); - const fromTimeZone = 'Coordinated Universal Time'; + const fromTimeZone = 'UTC'; const toTimeZone = 'America/Chicago'; - const offset = -5; + const offset = offsetBetweenTimeZones(toTimeZone, fromTimeZone); const panelsToCheck = [ 'Random walk series', @@ -44,8 +44,7 @@ e2e.scenario({ e2e.components.TimeZonePicker.container() .should('be.visible') .within(() => { - e2e.components.Select.singleValue().should('be.visible').should('have.text', fromTimeZone); - + e2e.components.Select.singleValue().should('be.visible').should('have.text', 'Coordinated Universal Time'); e2e.components.Select.input().should('be.visible').click(); }); @@ -90,3 +89,16 @@ const isTimeCorrect = (inUtc: string, inTz: string, offset: number): boolean => return diff <= Math.abs(offset * 60); }; + +const offsetBetweenTimeZones = (timeZone1: string, timeZone2: string, when: Date = new Date()): number => { + const t1 = convertDateToAnotherTimeZone(when, timeZone1); + const t2 = convertDateToAnotherTimeZone(when, timeZone2); + return (t1.getTime() - t2.getTime()) / (1000 * 60 * 60); +}; + +const convertDateToAnotherTimeZone = (date: Date, timeZone: string): Date => { + const dateString = date.toLocaleString('en-US', { + timeZone: timeZone, + }); + return new Date(dateString); +};