-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dashboard-timezone-selection): toggling timezone should update queries timerange to respect timezone selection #19146
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3dbf42f
fix(custom-timerange): fixes UTC selection data mismatch and misalign…
asalem1 0957caa
fix(dashboard-cell): updated dashboard cells to conform to timezone s…
asalem1 0cd3759
chore(timezone-selector): simplified timezone selector to utilize lik…
asalem1 641f3e6
chore(removed-offset-check): removed conditional check for offset sin…
asalem1 c213f7c
chore(CHANGELOG): updated CHANGELOG
asalem1 11d6bb5
feat(test): mocked the offset and added more testing to ensure stability
asalem1 dab43b4
chore(test): fixed breaking test
asalem1 57ce56d
fix(lint): fixed linter errors
asalem1 5dedd66
chore(updated-comments): updated comments on tests and getTimezoneOffset
asalem1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// Funcs | ||
import {mocked} from 'ts-jest/utils' | ||
import { | ||
getTimeRange, | ||
getTimeRangeWithTimezone, | ||
} from 'src/dashboards/selectors/index' | ||
import moment from 'moment' | ||
import {getTimezoneOffset} from 'src/dashboards/utils/getTimezoneOffset' | ||
|
||
jest.mock('src/dashboards/utils/getTimezoneOffset') | ||
|
||
// Types | ||
import {RangeState} from 'src/dashboards/reducers/ranges' | ||
|
@@ -30,22 +33,37 @@ const untypedGetTimeRangeWithTimeZone = getTimeRangeWithTimezone as (a: { | |
}) => TimeRange | ||
|
||
describe('Dashboards.Selector', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
const dashboardIDs = [ | ||
'04c6f3976f4b8001', | ||
'04c6f3976f4b8000', | ||
'04c6f3976f4b8002', | ||
'04c6f3976f4b8003', | ||
'04c6f3976f4b8004', | ||
] | ||
const lower = `2020-05-05T10:00:00${moment().format('Z')}` | ||
const upper = `2020-05-05T11:00:00${moment().format('Z')}` | ||
const customTimeRange = { | ||
lower, | ||
upper, | ||
const customTimeRangePST = { | ||
lower: '2020-05-05T10:00:00-07:00', | ||
upper: '2020-05-05T11:00:00-07:00', | ||
type: 'custom', | ||
} as CustomTimeRange | ||
const customTimeRangeCET = { | ||
lower: '2020-05-05T10:00:00+02:00', | ||
upper: '2020-05-05T11:00:00+02:00', | ||
type: 'custom', | ||
} as CustomTimeRange | ||
const customTimeRangeGMT = { | ||
lower: '2020-05-05T10:00:00+00:00', | ||
upper: '2020-05-05T11:00:00+00:00', | ||
type: 'custom', | ||
} as CustomTimeRange | ||
const ranges: RangeState = { | ||
[dashboardIDs[0]]: pastFifteenMinTimeRange, | ||
[dashboardIDs[1]]: pastHourTimeRange, | ||
[dashboardIDs[2]]: customTimeRange, | ||
[dashboardIDs[2]]: customTimeRangePST, | ||
[dashboardIDs[3]]: customTimeRangeCET, | ||
[dashboardIDs[4]]: customTimeRangeGMT, | ||
} | ||
|
||
it('should return the correct range when a matching dashboard ID is found', () => { | ||
|
@@ -72,7 +90,7 @@ describe('Dashboards.Selector', () => { | |
).toEqual(DEFAULT_TIME_RANGE) | ||
}) | ||
|
||
it('should return the an unmodified version of the timeRange when the timeZone is local', () => { | ||
it('should return an unmodified version of the timeRange when the timeZone is local', () => { | ||
const currentDashboard = {id: dashboardIDs[2]} | ||
const app: AppPresentationState = { | ||
ephemeral: { | ||
|
@@ -91,10 +109,10 @@ describe('Dashboards.Selector', () => { | |
|
||
expect( | ||
untypedGetTimeRangeWithTimeZone({ranges, currentDashboard, app}) | ||
).toEqual(customTimeRange) | ||
).toEqual(customTimeRangePST) | ||
}) | ||
|
||
it('should return the timeRange for the same hour with a UTC timezone when the timeZone is UTC', () => { | ||
it('should return the timeRange for the same hour with a UTC timezone when the timeZone is UTC and the locale is 7 timezones behind UTC', () => { | ||
const currentDashboard = {id: dashboardIDs[2]} | ||
|
||
const app: AppPresentationState = { | ||
|
@@ -117,6 +135,70 @@ describe('Dashboards.Selector', () => { | |
upper: `2020-05-05T11:00:00Z`, | ||
type: 'custom', | ||
} | ||
// Offset for PST | ||
mocked(getTimezoneOffset).mockImplementation(() => 420) | ||
|
||
expect( | ||
untypedGetTimeRangeWithTimeZone({ranges, currentDashboard, app}) | ||
).toEqual(expected) | ||
}) | ||
|
||
it('should return the timeRange for the same hour with a UTC timezone when the timeZone is UTC and the locale is 2 timezones ahead of UTC', () => { | ||
const currentDashboard = {id: dashboardIDs[3]} | ||
|
||
const app: AppPresentationState = { | ||
ephemeral: { | ||
inPresentationMode: false, | ||
hasUpdatedTimeRangeInVEO: false, | ||
}, | ||
persisted: { | ||
autoRefresh: 0, | ||
showTemplateControlBar: false, | ||
navBarState: 'expanded', | ||
notebookMiniMapState: 'expanded', | ||
timeZone: 'UTC' as TimeZone, | ||
theme: 'dark', | ||
}, | ||
} | ||
|
||
const expected = { | ||
lower: `2020-05-05T10:00:00Z`, | ||
upper: `2020-05-05T11:00:00Z`, | ||
type: 'custom', | ||
} | ||
// Offset for CET | ||
mocked(getTimezoneOffset).mockImplementation(() => -120) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here about adding a comment for whichever timezone is +2 utc |
||
|
||
expect( | ||
untypedGetTimeRangeWithTimeZone({ranges, currentDashboard, app}) | ||
).toEqual(expected) | ||
}) | ||
|
||
it('should return the timeRange when the timezone has no offset', () => { | ||
const currentDashboard = {id: dashboardIDs[4]} | ||
|
||
const app: AppPresentationState = { | ||
ephemeral: { | ||
inPresentationMode: false, | ||
hasUpdatedTimeRangeInVEO: false, | ||
}, | ||
persisted: { | ||
autoRefresh: 0, | ||
showTemplateControlBar: false, | ||
navBarState: 'expanded', | ||
notebookMiniMapState: 'expanded', | ||
timeZone: 'UTC' as TimeZone, | ||
theme: 'dark', | ||
}, | ||
} | ||
|
||
const expected = { | ||
lower: `2020-05-05T10:00:00Z`, | ||
upper: `2020-05-05T11:00:00Z`, | ||
type: 'custom', | ||
} | ||
|
||
mocked(getTimezoneOffset).mockImplementation(() => 0) | ||
|
||
expect( | ||
untypedGetTimeRangeWithTimeZone({ranges, currentDashboard, app}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* This files has been created as a way to effectively test | ||
* the getTimeRangeWithTimezone function since current system (circleCI, Jenkins) | ||
* and JS Date limitations prevent us from fully testing out its dependent functions | ||
* | ||
* It should be noted that the native getTimezoneOffset function returns a number | ||
* that represents the number of minutes (not hours) the "local" timezone is offset | ||
* where locations West of UTC are positive (+420) and locations East of UTC are negative (-120): | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset | ||
**/ | ||
|
||
export const getTimezoneOffset = (): number => new Date().getTimezoneOffset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here saying this is the value returned for california in daylight savings time?actually ignore the above, it's subtly wrong. this is the value returned for -7 UTC timezone, which is the timezone california is in during daylight savings time. in the winter time, this will be 360.