Closed 0xSiO closed 4 years ago
Hi @lucis-fluxum , this is indeed a good catch and make the crate more flexible. Am wondering what is the better example for this(want to put on README to show use cases), currently in my thought is
let christmas = Utc.ymd(2020, 12, 25).and_hms(0, 0, 0);
let two_weeks_before_christmas = 2.weeks().before(christmas);
What do you think?
Hey @jk-gan, thanks for your feedback. I updated the main example and the code on the README to reflect the new API and avoid any redundant examples. To cut down on noise, I didn't include calls to println
in the README. Let me know if everything looks okay.
Looks good to me. I will merge it. Thanks for the idea.
The
days_later
anddays_ago
tests were failing since there is a small execution delay between the evaluation of each side of the equality assertion. We could just calculate the difference between the two values and then assert that it is small enough to consider the two sides equal, but a better solution is to implement abefore
and anafter
method to modify a givenDateTime
. Then theago
andfrom_now
methods can be automatically implemented usingbefore
andafter
.This also gives us a more expressive way to write more complex
DateTime
s, like10.weeks().before(20.minutes().ago())
.Other changes:
later
method since it's equivalent tofrom_now