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

Add NaiveDateTime::checked_(add|sub)_offset #1313

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

pitdicker
Copy link
Collaborator

These methods are const and public so they can be used with #1270.

Because the offset is never more than 24 hours, we can use NaiveDate::pred_opt() and NaiveDate::succ_opt() Instead of NaiveDate::add_days. This gives a nice little performance improvement for many methods on DateTime (benchmarks in #1069 (comment)).

Most of all we can use these methods to avoid out of range panics when converting datetimes from UTC to local or back.

Split out from #1069.

@codecov
Copy link

codecov bot commented Sep 23, 2023

Codecov Report

Merging #1313 (4e441e6) into 0.4.x (a47e0e3) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            0.4.x    #1313      +/-   ##
==========================================
- Coverage   91.24%   91.22%   -0.03%     
==========================================
  Files          38       38              
  Lines       17062    17120      +58     
==========================================
+ Hits        15568    15617      +49     
- Misses       1494     1503       +9     
Files Changed Coverage Δ
src/offset/fixed.rs 73.13% <ø> (-7.58%) ⬇️
src/naive/datetime/mod.rs 97.35% <100.00%> (+0.05%) ⬆️
src/naive/datetime/tests.rs 98.77% <100.00%> (+0.13%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pitdicker
Copy link
Collaborator Author

Thank you, this made my day 😄.

@pitdicker pitdicker merged commit c836a1f into chronotope:0.4.x Sep 25, 2023
37 checks passed
@pitdicker pitdicker deleted the checked_add_offset branch September 25, 2023 11:21
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

Successfully merging this pull request may close these issues.

2 participants