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

11. As an item, I want my estimated next purchase date to be computed at the time my purchase is recorded in the database so the app can learn how often I buy different items. #10

Open
4 tasks
stacietaylorcima opened this issue Dec 18, 2023 · 0 comments

Comments

@stacietaylorcima
Copy link
Contributor

stacietaylorcima commented Dec 18, 2023

Summary

In order to advise users about when to purchase things, the app needs to be able to calculate that guess and store it a future date.

The calculateEstimate function from the @the-collab-lab/shopping-list-utils module will help us know how many days in the future a purchase should happen. In order to use calculateEstimate, we need to know how many days have passed since the time the item was last purchased.

Acceptance criteria

  • When the user purchases an item, the item’s dateNextPurchased property is calculated using the calculateEstimate function and saved to the Firestore database
    • dateNextPurchased is saved as a date, not a number
  • A getDaysBetweenDates function is exported from utils/dates.js and imported into api/firebase.js
    • This function takes two JavaScript Dates and return the number of days that have passed between them

Notes

Working with Firestore’s dates

Firestore returns dates as special objects called Timestamps. You will need to convert the Timestamp to a JavaScript Date in order to work with it and complete this feature. The Timestamp object has a .toDate() method – see the Firestore docs.

Calculating the time between JavaScript dates

Comparing and manipulating JavaScript Dates is notoriously tricky. Here's a hint: all Date objects have a getTime() method that returns a representation of that date in milliseconds (MDN docs).

Calculating the next purchase date

The @the-collab-lab/shopping-list-utils module should already be installed in your project. This module exports calculateEstimate.

calculateEstimate accepts three arguments. They are, in order:

  • previousEstimate (a number): The last estimated purchase interval.
  • daysSinceLastPurchase (a number): The number of days that have elapsed between the last purchased date and now. You will need to figure out how to calculate this argument!
  • totalPurchases (a number): The total number of purchases made for the item,

Given this information, calculateEstimate returns a whole number indicating the number of days until the user is likely to make their next purchase.

@jeremiahfallin jeremiahfallin changed the title 10. As an item, I want my estimated next purchase date to be computed at the time my purchase is recorded in the database so the app can learn how often I buy different items. 11. As an item, I want my estimated next purchase date to be computed at the time my purchase is recorded in the database so the app can learn how often I buy different items. Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant