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

Fix time_point formatting for durations with certain ratios #3430

Merged
merged 2 commits into from
May 11, 2023

Conversation

patlkli
Copy link
Contributor

@patlkli patlkli commented May 11, 2023

#3261 unfortunately broke formatting for std::chrono::time_points with durations with certain ratios, since std::chrono::seconds is not implicitly convertible to these durations.

This PR fixes this by explicitly duration_cast-ing back to the time_point's Duration.

Repro: The following worked in 9.1.0, but doesn't compile in 10.0.0:

#include <fmt/chrono.h>

int main() {
    fmt::print("{}\n", std::chrono::time_point_cast<std::chrono::minutes>(std::chrono::system_clock::now()));
}

@vitaut
Copy link
Contributor

vitaut commented May 11, 2023

Thanks for the PR. Could you add a test case to chrono-test?

@patlkli
Copy link
Contributor Author

patlkli commented May 11, 2023

Sure, they're in now.

@vitaut vitaut merged commit d7592ad into fmtlib:master May 11, 2023
@vitaut
Copy link
Contributor

vitaut commented May 11, 2023

Thank you!

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