-
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
feat(custom-timerange-tz): timeZone dropdown is now integrated in setting custom time ranges for queries #17992
Changes from 8 commits
30f98f3
e4043a8
0502df5
7b3b52c
7f3240e
5325509
2f501dc
08d5fff
66012ab
13f38e0
810128e
0cdabe7
144be47
ab2e6ce
5e49da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import {get} from 'lodash' | ||
|
||
import {AppState, View, Check, ViewType, TimeRange} from 'src/types' | ||
import moment from 'moment' | ||
import {AppState, View, Check, ViewType, TimeRange, TimeZone} from 'src/types' | ||
import {currentContext} from 'src/shared/selectors/currentContext' | ||
|
||
// Constants | ||
|
@@ -15,6 +15,47 @@ export const getTimeRange = (state: AppState): TimeRange => { | |
return state.ranges[contextID] || DEFAULT_TIME_RANGE | ||
} | ||
|
||
export const getTimeRangeWithTimezone = (state: AppState): TimeRange => { | ||
const timeRange = getTimeRange(state) | ||
const timeZone = getTimeZone(state) | ||
// create a copy of the timeRange so as not to mutate the original timeRange | ||
const newTimeRange = Object.assign({}, timeRange) | ||
asalem1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (timeRange.type === 'custom' && timeZone === 'UTC') { | ||
// check to see if the timeRange has an offset | ||
asalem1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
newTimeRange.lower = setTimeToUTC(newTimeRange.lower) | ||
newTimeRange.upper = setTimeToUTC(newTimeRange.upper) | ||
} | ||
return newTimeRange | ||
} | ||
|
||
export const setTimeToUTC = (date: string): string => { | ||
asalem1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const offset = new Date(date).getTimezoneOffset() | ||
// check if date has offset | ||
if (offset === 0) { | ||
return date | ||
} | ||
let offsetDate = date | ||
if (offset > 0) { | ||
// subtract tz minute difference | ||
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. OH! is that what the 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. ;) |
||
offsetDate = moment | ||
.utc(date) | ||
.subtract(offset, 'minutes') | ||
.format() | ||
} | ||
if (offset < 0) { | ||
// add tz minute difference | ||
offsetDate = moment | ||
.utc(date) | ||
.add(offset, 'minutes') | ||
.format() | ||
} | ||
return offsetDate | ||
} | ||
asalem1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const getTimeZone = (state: AppState): TimeZone => { | ||
return state.app.persisted.timeZone || 'Local' | ||
} | ||
|
||
export const getCheckForView = ( | ||
state: AppState, | ||
view: View | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import { | |
getFillColumnsSelection, | ||
getSymbolColumnsSelection, | ||
} from 'src/timeMachine/selectors' | ||
import {getTimeRange} from 'src/dashboards/selectors' | ||
import {getTimeRange, getTimeZone} from 'src/dashboards/selectors' | ||
|
||
// Types | ||
import { | ||
|
@@ -164,7 +164,7 @@ const mstp = (state: AppState): StateProps => { | |
const fillColumns = getFillColumnsSelection(state) | ||
const symbolColumns = getSymbolColumnsSelection(state) | ||
|
||
const timeZone = state.app.persisted.timeZone | ||
const timeZone = getTimeZone(state) | ||
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. so the line this is replacing wouldn't set the timeZone to 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. I also noticed that. It's weird because we set |
||
|
||
return { | ||
loading, | ||
|
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.
these tests look fine, and are wise in that they don't reference like
today
ornow
but instead solid dates in the past.but having said that, a career of having tests around checking date/times that fail randomly has made me extremely wary and gunshy of them. just keep an eye on tests that involve dates and time. they can fail and blow up in weird and unexpected and painful ways.