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 a set_time method to DateTime #1027

Closed
wants to merge 1 commit into from

Conversation

pitdicker
Copy link
Collaborator

Example of where this would be useful: #1022.

Workarounds such as substracting the current time would not be correct.
You have to extract the current date as NaiveDate, add the desired time to get a NaiveDateTime, extract the original timezone, and construct a new DateTime.

Because it is definitely non-trivial to figure out, I propose to add this method.

@pitdicker
Copy link
Collaborator Author

Thinking about this a day later, it feels a bit like a hack. Or at least, incomplete.
When I think about DateTime, I see it as a combination of NaiveDate, NaiveTime, and something implementing TimeZone . It is already possible to swap out the timezone with with_timezone. This PR would add the ability to replace the time part. With a set_date method the set would be complete.

But I am starting to learn that with chrono you should have the mindset: when you want to do something non-obvious with DateTime, just drop down to its components such as NaiveDate and TimeZone, change what is needed, and recombine them.

Feel free to close this PR if you agree.

@djc
Copy link
Contributor

djc commented Apr 19, 2023

Yeah, I think that makes more sense.

@djc djc closed this Apr 19, 2023
@pitdicker pitdicker deleted the datetime_set_time branch April 19, 2023 16:38
@pitdicker pitdicker restored the datetime_set_time branch July 2, 2023 20:07
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.

None yet

2 participants