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)
|
super(props, context)
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
this.state = {
|
this.state = {
|
||||||
start: startOfMonth(subMonths(date, 12)),
|
start: startOfMonth(subMonths(date, 11)),
|
||||||
end: endOfMonth(date),
|
end: endOfMonth(date),
|
||||||
duration: 'month',
|
duration: 'month',
|
||||||
type: 'by_time',
|
type: 'by_time',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import togeojson from '@mapbox/togeojson'
|
import togeojson from '@mapbox/togeojson'
|
||||||
import {
|
import {
|
||||||
addDays, addMonths, addYears, format, parse, startOfWeek
|
addDays, addMonths, addYears, format, parse, startOfMonth, startOfWeek,
|
||||||
|
startOfYear
|
||||||
} from 'date-fns'
|
} from 'date-fns'
|
||||||
import { DateTime } from 'luxon'
|
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 = (
|
export const formatStats = (
|
||||||
stats, sports, params
|
stats, sports, params
|
||||||
) => {
|
) => {
|
||||||
@ -178,7 +191,7 @@ export const formatStats = (
|
|||||||
const distanceStats = []
|
const distanceStats = []
|
||||||
const durationStats = []
|
const durationStats = []
|
||||||
|
|
||||||
for (let day = startOfWeek(params.start);
|
for (let day = startDate(params.duration, params.start);
|
||||||
day <= params.end;
|
day <= params.end;
|
||||||
day = dateIncrement(params.duration, day)
|
day = dateIncrement(params.duration, day)
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user