-
Notifications
You must be signed in to change notification settings - Fork 1
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
Issue 11 Estimate next purchase date #29
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,9 @@ const ONE_DAY_IN_MILLISECONDS = 86400000; | |
export function getFutureDate(offset) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also reconsider making this function name more specific |
||
return new Date(Date.now() + offset * ONE_DAY_IN_MILLISECONDS); | ||
} | ||
export function getDaysBetweenDates(previousPurchaseDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would consider what to name this function - if i wanted to get the days between dates, i would expect this function to accept two values, date1 and date 2. Since you are only passing in one date and compare it to today, i would name this function something to reflect that. This is so when this util function is needed for something else in the future it's easy to tell what it can do. |
||
const pastDate = previousPurchaseDate.toDate(); | ||
const presentDate = new Date(); | ||
const diffInMilliseconds = presentDate.getTime() - pastDate.getTime(); | ||
return Math.round(diffInMilliseconds / ONE_DAY_IN_MILLISECONDS); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your logic makes sense here, however it is a little bit hard to follow (in nature due to the calculation itself being tricky. I would consider adding comments to each line to make sure it is clear what each line is doing.
This also feels like quite a big block of code. I would consider trying to separate out anything that is not the purpose of the
updateItem
function (to update the database with the item's updated data), and seeing where else I could put this calculating dates logic - maybe in the list component itself, or another util function? You will then need to change the arguments for this function. This way we can keep this main function less noisy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jenny,
Thank you for your feedback! I appreciate your suggestion about adding comments to clarify the code. I’ve added comments to each line to explain what’s happening. This should make the logic more transparent.