-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adding info to the arithmetic section! #12
base: main
Are you sure you want to change the base?
Conversation
src/api/arithmetic.md
Outdated
@@ -1 +1,106 @@ | |||
# Arithmetic | |||
|
|||
Let's suppose you are creating an finance app for people who are above 18 years old. Normally, instead of asking the age itself, you would ask for the birthdate to track the age evolution, rigth? |
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.
Age may not be the best example, as all years are not the same length. Perhaps something occurring every so many days of weeks?
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.
That's a good point. What do you think about calculating the next payment date of a monthly subscription?
We could add an example of adding 30 days in a date, considering different date lengths. We could also consider when the current month is December and the result would be a date in the next year to show how to handle these "corner" cases.
I'm thinking of using Duration to add the amount of days in a Date object with the .add_days()
What are your thoughts on that?
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.
Or maybe calculating the date of arrival of an online purchase 🤔
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.
Arrival for a purchase would work! That's something that wouldn't care about the lengths of months/years.
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.
Great! I'll come up with an example and we can work upon that :)
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.
Just commited the change in the example :)
src/api/arithmetic.md
Outdated
|
||
```rust | ||
|
||
const SECONDS_PER_YEAR: i64 = 365*24*60*60; |
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.
Once changed to days or weeks, constants like this can be avoided by utilizing the time::convert
module. Alternatively, the duration itself can be divided by another duration, such as foo / Duration::WEEK
.
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.
In the last commit, I used let time_to_deliver: Duration = 45*(Duration::DAY)
. That's was what you meant?
Co-authored-by: Jacob Pratt <jacob@jhpratt.dev>
…arrival date of an online purchase to make it clear :)
…arrival date of an online purchase to make it clear :)
I added a simple example for calculating an user's age using the crate in the arithmetic section. Tried to avoid complexity as much as I could. If you have a suggestion we definitely can improve on it :)