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

Missing micros and millis "with" functions since 0.4.23 #1025

Closed
seerwill opened this issue Apr 18, 2023 · 2 comments
Closed

Missing micros and millis "with" functions since 0.4.23 #1025

seerwill opened this issue Apr 18, 2023 · 2 comments

Comments

@seerwill
Copy link

Prior to #827 we could do:

chrono::Utc
    .ymd(year, month, day)
    .and_hms_micro(hour, minute, sec, micros)

The deprecation notice says to replace ymd -> with_ymd_and_hms. This obviously doesn't work directly with_ymd_and_hms has a different return type to ymd.

Also, the deprecation notice for Date::and_hms_micro incorrectly suggests to use Date::and_hms_micro_opt instead, however Date itself is deprecated so this doesn't seem right.

On the other hand there don't seem to be any with_micro or with_milli functions on DateTime, so I have to do:

chrono::Utc
    .with_ymd_and_hms(year, month, day, hour, minute, sec)
    .unwrap()
    .with_nanosecond(micros * 1_000)
    .unwrap()

Is there an "official" way to do this after 0.4.23?

@djc
Copy link
Contributor

djc commented Apr 18, 2023

I think the way we've been suggesting is to build a NaiveDateTime first, then add the timezone to it.

@pitdicker
Copy link
Collaborator

Closing as a duplicate of #873.

@pitdicker pitdicker closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2023
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

No branches or pull requests

3 participants