Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updates for downloads per day #23

Merged
merged 1 commit into from
Jul 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions libs/live-fns/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ async function download (period, args) {
const isTotal = period === 'total'

if (isTotal) {
const today = new Date()
const now = new Date()
endpoint.push(`/range/2005-01-01:${now.getFullYear() + 1}-01-01`)
} else if (period === 'last-day') {
const beforeTwoDays = Date.now() - 172800000
const dateBefore = new Date(beforeTwoDays)
const [date] = dateBefore.toISOString().split('T')

endpoint.push(`/range/2005-01-01:${today.getFullYear() + 1}-01-01`)
endpoint.push(`/range/${date}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of this line, change it to period = date :D

} else {
endpoint.push(`/point/${period}`)
}
Expand All @@ -71,6 +76,8 @@ async function download (period, args) {
stats.downloads = stats.downloads.reduce((prev, { downloads }) => {
return prev + downloads
}, 0)
} else if (period === 'last-day') {
stats.downloads = stats.downloads[0].downloads
}

return {
Expand Down