feat: timezone conversion in dashboard graph

This commit is contained in:
Sérgio Salgado 2021-04-29 20:08:23 +01:00 committed by Josh Harvey
parent b2b4fedf42
commit b24c65e8bc
2 changed files with 17 additions and 8 deletions

View file

@ -5,7 +5,7 @@ import React, { useEffect, useRef, useCallback } from 'react'
import { backgroundColor, java, neon } from 'src/styling/variables' import { backgroundColor, java, neon } from 'src/styling/variables'
const RefScatterplot = ({ data: realData, timeFrame }) => { const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
const svgRef = useRef() const svgRef = useRef()
const cashIns = R.filter(R.propEq('txClass', 'cashIn'))(realData) const cashIns = R.filter(R.propEq('txClass', 'cashIn'))(realData)
const cashOuts = R.filter(R.propEq('txClass', 'cashOut'))(realData) const cashOuts = R.filter(R.propEq('txClass', 'cashOut'))(realData)
@ -92,8 +92,11 @@ const RefScatterplot = ({ data: realData, timeFrame }) => {
.domain([ .domain([
moment() moment()
.add(-xAxisSettings.subtractDays, 'day') .add(-xAxisSettings.subtractDays, 'day')
.add(timezone.dstOffset, 'minutes')
.valueOf(), .valueOf(),
moment().valueOf() moment()
.add(timezone.dstOffset, 'minutes')
.valueOf()
]) ])
.range(xAxisSettings.timeRange) .range(xAxisSettings.timeRange)
.nice(xAxisSettings.nice) .nice(xAxisSettings.nice)
@ -168,7 +171,8 @@ const RefScatterplot = ({ data: realData, timeFrame }) => {
.enter() .enter()
.append('circle') .append('circle')
.attr('cx', function(d) { .attr('cx', function(d) {
return x(new Date(d.created)) const date = new Date(d.created)
return x(date.setMinutes(date.getMinutes() + timezone.dstOffset))
}) })
.attr('cy', function(d) { .attr('cy', function(d) {
return y(d.fiat) return y(d.fiat)

View file

@ -76,21 +76,25 @@ const SystemPerformance = () => {
const [selectedRange, setSelectedRange] = useState('Day') const [selectedRange, setSelectedRange] = useState('Day')
const { data, loading } = useQuery(GET_DATA) const { data, loading } = useQuery(GET_DATA)
const fiatLocale = fromNamespace('locale')(data?.config).fiatCurrency const fiatLocale = fromNamespace('locale')(data?.config).fiatCurrency
const timezone = fromNamespace('locale')(data?.config).timezone
const isInRangeAndNoError = getLastTimePeriod => t => { const isInRangeAndNoError = getLastTimePeriod => t => {
if (t.error !== null) return false if (t.error !== null) return false
if (!getLastTimePeriod) { if (!getLastTimePeriod) {
return ( return (
t.error === null && t.error === null &&
moment(t.created).isBetween(ranges[selectedRange].right, moment()) moment
.utc(t.created)
.utcOffset(timezone.dstOffset)
.isBetween(ranges[selectedRange].right, moment())
) )
} }
return ( return (
t.error === null && t.error === null &&
moment(t.created).isBetween( moment
ranges[selectedRange].left, .utc(t.created)
ranges[selectedRange].right .utcOffset(timezone.dstOffset)
) .isBetween(ranges[selectedRange].left, ranges[selectedRange].right)
) )
} }
@ -194,6 +198,7 @@ const SystemPerformance = () => {
<Scatterplot <Scatterplot
timeFrame={selectedRange} timeFrame={selectedRange}
data={transactionsToShow} data={transactionsToShow}
timezone={timezone}
/> />
</Grid> </Grid>
</Grid> </Grid>