Skip to content

Commit

Permalink
fix(Stats.js): display correct monthly measurements after changing la…
Browse files Browse the repository at this point in the history
…nguage (#886)
  • Loading branch information
Lanius-collaris authored Jan 6, 2024
1 parent 52d1dea commit ad39cbc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions components/landing/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const swrOptions = {
const getLastMonthData = (collection) => {
const cc = collection.filter(d => {
const dt = new Date(Date.parse(d.date))
dt.setUTCMonth(dt.getUTCMonth()+1)
const today = new Date()
return (dt.getUTCFullYear() === today.getUTCFullYear()) && (today.getUTCMonth() - dt.getUTCMonth() === 1)
return (dt.getUTCFullYear() === today.getUTCFullYear()) && (today.getUTCMonth() === dt.getUTCMonth())
})
return cc.length === 0 ? 0 : cc[0]?.value ?? 0
}
Expand All @@ -56,20 +57,15 @@ const CoverageChart = () => {
const intl = useIntl()

if (data) {
const {
countries_by_month: countryCoverage,
networks_by_month: networkCoverage,
measurements_by_month: measurementsByMonth
} = data
countryCoverage.pop()
networkCoverage.pop()
measurementsByMonth.pop()
const countryCoverage = data.countries_by_month.slice(0, -1),
networkCoverage = data.networks_by_month.slice(0, -1),
measurementsByMonth = data.measurements_by_month.slice(0, -1)

// API responses are ordered by date, with most recent month at the end
const lastMonth = {
countryCount: getLastMonthData(countryCoverage),
networkCount: getLastMonthData(networkCoverage),
measurementCount: getLastMonthData(measurementsByMonth)
countryCount: getLastMonthData(data.countries_by_month),
networkCount: getLastMonthData(data.networks_by_month),
measurementCount: getLastMonthData(data.measurements_by_month)
}

// Determine the maximum value for each data set
Expand Down

1 comment on commit ad39cbc

@vercel
Copy link

@vercel vercel bot commented on ad39cbc Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.