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 DateTime::with_time() #1510

Merged
merged 1 commit into from
Mar 13, 2024
Merged

Conversation

pitdicker
Copy link
Collaborator

@pitdicker pitdicker commented Mar 12, 2024

Reopening #1027.

We have now had three issues on how to create a DateTime for today at a specific time: #1022, #1447 and #1508.
We could add a today_at method to Local (and may still want to do so), but DateTime::with_time() is a more generic solution.

A second reason to want this method is it gives a way to deal with the one remaining panic case from #1047 that I don't have a workaround for: If users write dt.timezone().from_local_datetime(&dt.date().and_time(time)) it may panic when the NaiveDateTime in UTC is at the edge of the representable range, and the local NaiveDate is out of range. We can internally use overflowing_naive_local() and return a result if that is in range.

Renamed from set_time to with_time to match the other with_* methods.

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.81%. Comparing base (920e73b) to head (221e640).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1510   +/-   ##
=======================================
  Coverage   91.80%   91.81%           
=======================================
  Files          40       40           
  Lines       18337    18351   +14     
=======================================
+ Hits        16835    16849   +14     
  Misses       1502     1502           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pitdicker pitdicker merged commit 236b7ad into chronotope:main Mar 13, 2024
35 checks passed
@pitdicker pitdicker deleted the datetime_set_time branch March 13, 2024 13:42
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