-
Notifications
You must be signed in to change notification settings - Fork 542
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
Add a feature and method to override now
#1244
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1244 +/- ##
=======================================
Coverage 91.84% 91.85%
=======================================
Files 38 38
Lines 17518 17526 +8
=======================================
+ Hits 16090 16098 +8
Misses 1428 1428 ☔ View full report in Codecov by Sentry. |
208eaa4
to
5272720
Compare
5272720
to
c4c4aec
Compare
I just wondered: |
c4c4aec
to
7b40a4a
Compare
/// This method is only available behind the `test-override` feature, only works within the | ||
/// current thread, and only in `cfg(test)`. | ||
/// | ||
/// ```no_run |
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.
Codecov correctly says the lines of this doctest are not covered. But I can't help it 😄.
Just a comment from a random bystander: instead of injecting this on a global level, people can opt-in code using a test double such as https://crates.io/crates/mockall_double. It does not "fix" existing code that uses chrono today, but it gives a more clean way to control the test setup. |
7b40a4a
to
465cd1e
Compare
465cd1e
to
481178e
Compare
I'm not going to push for this issue. Others can feel free to pick it up and/or advocate for it though. |
Updated version of #580. A comment in the related issue #105 (comment) has collected 28 thumb ups in three years. This may be our most popular feature request.
The only method added is
Local::override_now(datetime: Option<DateTime<FixedOffset>>)
, and it affectsLocal::now()
andUtc::now()
. I made it a method onLocal
because it takes a datetime and an offset, while forUtc
only a datetime would make sense.The functionality is only available behind the
test-override
feature while running tests.