diff --git a/src/components/charts/MonthChart/formatMonthData.ts b/src/components/charts/MonthChart/formatMonthData.ts index b0a98ac4..9ccf5545 100644 --- a/src/components/charts/MonthChart/formatMonthData.ts +++ b/src/components/charts/MonthChart/formatMonthData.ts @@ -1,4 +1,11 @@ -import { addWeeks, getDaysInMonth, getWeeksInMonth, isSameWeek, startOfMonth } from 'date-fns'; +import { + addWeeks, + getDay, + getDaysInMonth, + getWeeksInMonth, + isSameWeek, + startOfMonth +} from 'date-fns'; import TrackerEntry from '../../../models/TrackerEntry'; import { getAggregatedCompletions } from '../../../store/trackers/utils'; import { DataType } from './types'; @@ -9,10 +16,14 @@ const formatData = (monthDate: Date, entries: TrackerEntry[]): DataType[] => { const startDay = startOfMonth(monthDate); for (let i = 0; i < nbOfWeeks; i += 1) { const week = addWeeks(startDay, i); + const weekBeginDayNumber = i === 0 ? 1 : i * 7 + 1; + const weekEndDayNumber = Math.min(i * 7 + 7, getDaysInMonth(startDay)); const weekData: DataType = { - name: (i === 0 ? 1 : i * 7 + 1) + '-' + Math.min(i * 7 + 8, getDaysInMonth(startDay)) + name: weekBeginDayNumber + '-' + weekEndDayNumber }; - const weekEntries = entries.filter((e) => isSameWeek(new Date(e.date), week)); + const weekEntries = entries.filter((e) => isSameWeek(new Date(e.date), week), { + weekStartsOn: getDay(new Date(week)) + }); const aggCompletions = getAggregatedCompletions(weekEntries); aggCompletions.forEach((c) => { weekData[c.unit] = c.quantity;