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'
const RefScatterplot = ({ data: realData, timeFrame }) => {
const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
const svgRef = useRef()
const cashIns = R.filter(R.propEq('txClass', 'cashIn'))(realData)
const cashOuts = R.filter(R.propEq('txClass', 'cashOut'))(realData)
@ -92,8 +92,11 @@ const RefScatterplot = ({ data: realData, timeFrame }) => {
.domain([
moment()
.add(-xAxisSettings.subtractDays, 'day')
.add(timezone.dstOffset, 'minutes')
.valueOf(),
moment().valueOf()
moment()
.add(timezone.dstOffset, 'minutes')
.valueOf()
])
.range(xAxisSettings.timeRange)
.nice(xAxisSettings.nice)
@ -168,7 +171,8 @@ const RefScatterplot = ({ data: realData, timeFrame }) => {
.enter()
.append('circle')
.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) {
return y(d.fiat)

View file

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