Skip to content

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

Merged
pitdicker merged 3 commits into
chronotope:0.4.xfrom
pitdicker:checked_add_offset
Sep 25, 2023
Merged

Add NaiveDateTime::checked_(add|sub)_offset#1313
pitdicker merged 3 commits into
chronotope:0.4.xfrom
pitdicker:checked_add_offset

Conversation

@pitdicker
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Collaborator Author

Thank you, this made my day 😄.

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