Introduce timeRange query helpers

pull/10616/head
Andrew Watkins 2017-11-03 16:53:16 -07:00
parent 7ba2d00a1d
commit 1301a0f2ee
3 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import {timeRangeType, shiftTimeRange} from 'shared/query/helpers'
import {ABSOLUTE} from 'shared/constants/timeRange'
const format = 'influxql'
describe.only('Shared.Query.Helpers', () => {
describe('timeRangeTypes', () => {
it('return invlalid if no upper and lower', () => {
const upper = null
const lower = null
const timeRange = {lower, upper}
expect(timeRangeType(timeRange)).to.equal(ABSOLUTE)
})
it('it can detect absolute type', () => {
const tenMinutes = 600000
const upper = Date.now()
const lower = upper - tenMinutes
const timeRange = {lower, upper, format}
expect(timeRangeType(timeRange)).to.equal(ABSOLUTE)
})
})
})

View File

@ -0,0 +1,2 @@
export const ABSOLUTE = 'absolute'
export const INVALID = 'invalid'

View File

@ -0,0 +1,24 @@
import moment from 'moment'
import {ABSOLUTE} from 'shared/constants/timeRange'
// calc time range type
export const timeRangeType = ({upper, lower, type}) => {
if (!upper && !lower) {
return 'invalid'
}
if (!type || type === 'influxql') {
const mUpper = moment(upper)
const mLower = moment(lower)
const isUpperValid = mUpper.isValid()
const isLowerValid = mLower.isValid()
if (isUpperValid && isLowerValid) {
return ABSOLUTE
}
}
return 'none'
}
// based on time range type, calc the time shifted dates