Skip to content

Commit

Permalink
Refactor the daily counts
Browse files Browse the repository at this point in the history
Calculation of the daily counts is a bit hard to follow. This might help clarify it.
  • Loading branch information
eatyourgreens committed Sep 7, 2021
1 parent 5fbe0f8 commit 4761e36
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ function DailyClassificationsChartContainer({
thisWeek = []
}) {
const TODAY = new Date()
const stats = thisWeek.map(stat => {
const day = new Date(stat.period)
const locale = counterpart.getLocale()
const count = (day.getUTCDay() === TODAY.getDay()) ? counts.today : stat.count
const locale = counterpart.getLocale()
const stats = thisWeek.map(({ count: statsCount, period }) => {
const day = new Date(period)
const isToday = day.getUTCDay() === TODAY.getDay()
const count = isToday ? counts.today : statsCount
const longLabel = day.toLocaleDateString(locale, { timeZone: 'UTC', weekday: 'long' })
const alt = `${longLabel}: ${count}`
const label = day.toLocaleDateString(locale, { timeZone: 'UTC', weekday: 'narrow' })
return Object.assign({}, stat, { alt, count, label, longLabel })
return { alt, count, label, longLabel, period }
})
return (
<DailyClassificationsChart
Expand Down

0 comments on commit 4761e36

Please sign in to comment.