feat: remove all instances of moment usage

This commit is contained in:
Sérgio Salgado 2021-11-23 16:09:15 +00:00
parent 7d6fb17158
commit 973040f409
29 changed files with 252 additions and 193 deletions

View file

@ -1,9 +1,9 @@
import * as d3 from 'd3'
import { getTimezoneOffset } from 'date-fns-tz'
import moment from 'moment'
import { add } from 'date-fns'
import React, { useEffect, useRef, useCallback } from 'react'
import { backgroundColor, java, neon } from 'src/styling/variables'
import { formatDate, toUtc } from 'src/utils/timezones'
const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
const svgRef = useRef()
@ -12,7 +12,6 @@ const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
const margin = { top: 25, right: 0, bottom: 25, left: 15 }
const width = 555 - margin.left - margin.right
const height = 150 - margin.top - margin.bottom
const offset = getTimezoneOffset(timezone)
// finds maximum value for the Y axis. Minimum value is 100. If value is multiple of 1000, add 100
// (this is because the Y axis looks best with multiples of 100)
const findMaxY = () => {
@ -31,10 +30,7 @@ const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
case 'Month':
return d3.timeFormat('%b %d')(v)
default:
return moment
.utc(v)
.add(offset, 'minutes')
.format('HH:mm')
return formatDate(v, timezone, 'HH:mm')
}
}
@ -96,16 +92,14 @@ const RefScatterplot = ({ data: realData, timeFrame, timezone }) => {
const x = d3
.scaleTime()
.domain([
moment()
.add(-xAxisSettings.subtractDays, 'day')
.valueOf(),
moment().valueOf()
add(new Date(), { days: -xAxisSettings.subtractDays }).valueOf(),
new Date().valueOf()
])
.range(xAxisSettings.timeRange)
.nice(xAxisSettings.nice)
const timeValue = s => {
const date = moment.utc(s)
const date = toUtc(s)
return x(date.valueOf())
}