[release-12.3.1] Playwright: fix timezone test to work at all times (#113841)
Playwright: fix timezone test to work at all times (#113827)
* fix timezone test to work at all times
* remove unused imports
(cherry picked from commit f5f0c1e6f6)
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
co-authored by
Ashley Harrison
parent
dbf1794c37
commit
826eb83257
@@ -1,4 +1,4 @@
|
||||
import { addDays, addHours, differenceInCalendarDays, differenceInMinutes, isBefore, parseISO, toDate } from 'date-fns';
|
||||
import { differenceInMinutes, parseISO, toDate } from 'date-fns';
|
||||
import { Page } from 'playwright-core';
|
||||
|
||||
import { test, expect, DashboardPage, E2ESelectorGroups } from '@grafana/plugin-e2e';
|
||||
@@ -266,10 +266,7 @@ const isTimeCorrect = (inUtc: string, inTz: string, offset: number): boolean =>
|
||||
}
|
||||
|
||||
const utcDate = toDate(parseISO(inUtc));
|
||||
const utcDateWithOffset = addHours(toDate(parseISO(inUtc)), offset);
|
||||
const dayDifference = differenceInCalendarDays(utcDate, utcDateWithOffset); // if the utcDate +/- offset is the day before/after then we need to adjust reference
|
||||
const dayOffset = isBefore(utcDateWithOffset, utcDate) ? dayDifference * -1 : dayDifference;
|
||||
const tzDate = addDays(toDate(parseISO(inTz)), dayOffset); // adjust tzDate with any dayOffset
|
||||
const tzDate = toDate(parseISO(inTz));
|
||||
const diff = Math.abs(differenceInMinutes(utcDate, tzDate)); // use Math.abs if tzDate is in future
|
||||
|
||||
return diff <= Math.abs(offset * 60);
|
||||
|
||||
Reference in New Issue
Block a user