fix start on stats graph
This commit is contained in:
parent
8e5f83d909
commit
e412907e36
@ -9,7 +9,7 @@ export default class Statistics extends React.Component {
|
||||
super(props, context)
|
||||
const date = new Date()
|
||||
this.state = {
|
||||
start: startOfMonth(subMonths(date, 12)),
|
||||
start: startOfMonth(subMonths(date, 11)),
|
||||
end: endOfMonth(date),
|
||||
duration: 'month',
|
||||
type: 'by_time',
|
||||
|
@ -1,6 +1,7 @@
|
||||
import togeojson from '@mapbox/togeojson'
|
||||
import {
|
||||
addDays, addMonths, addYears, format, parse, startOfWeek
|
||||
addDays, addMonths, addYears, format, parse, startOfMonth, startOfWeek,
|
||||
startOfYear
|
||||
} from 'date-fns'
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
@ -171,6 +172,18 @@ const dateIncrement = (duration, day) => {
|
||||
}
|
||||
}
|
||||
|
||||
const startDate = (duration, day) => {
|
||||
switch (duration) {
|
||||
case 'week':
|
||||
return startOfWeek(day)
|
||||
case 'year':
|
||||
return startOfYear(day)
|
||||
case 'month':
|
||||
default:
|
||||
return startOfMonth(day)
|
||||
}
|
||||
}
|
||||
|
||||
export const formatStats = (
|
||||
stats, sports, params
|
||||
) => {
|
||||
@ -178,7 +191,7 @@ export const formatStats = (
|
||||
const distanceStats = []
|
||||
const durationStats = []
|
||||
|
||||
for (let day = startOfWeek(params.start);
|
||||
for (let day = startDate(params.duration, params.start);
|
||||
day <= params.end;
|
||||
day = dateIncrement(params.duration, day)
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user