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

fmt chrono fails for clock minimum value #3282

Closed
m5k8 opened this issue Jan 21, 2023 · 4 comments
Closed

fmt chrono fails for clock minimum value #3282

m5k8 opened this issue Jan 21, 2023 · 4 comments

Comments

@m5k8
Copy link

m5k8 commented Jan 21, 2023

https://godbolt.org/z/GbbvMb3bE

    #include <iostream>
    #include <chrono>
    #include <fmt/format.h>
    #include <fmt/chrono.h>
    
    int main(void)
    {
        // OK:
        // auto t = std::chrono::system_clock::time_point::max();
        // failure:
        auto t = std::chrono::system_clock::time_point::min();
        fmt::print("{}\n", t);
        return 0;
    }

Result:

    terminate called after throwing an instance of 'fmt::v9::format_error'
      what():  duration is too small

Code in chrono.h:2113 explicitly checks for one second above min() and fails for value= min(). For max(), works OK. Until recently, it worked fine for min(). This commit: 240b728 added the offending code. I'm not sure about the intent of this test. I discovered the issue, because one of my tests started to fail. min() value seems to be legal value, albeit used not too often.

@vitaut
Copy link
Contributor

vitaut commented Jan 21, 2023

This is essentially the same issue as discussed in #3261 (comment) except that UB has been replaced with a runtime error. A PR to allow time point values close to min would be welcome. cc @ShawnZhong

@zyxidra
Copy link

zyxidra commented Nov 9, 2023

Hi, is this issue still open? I want to take it as my first contribution :)

@vitaut
Copy link
Contributor

vitaut commented Nov 9, 2023

It is still open and contributions are welcome!

@vitaut
Copy link
Contributor

vitaut commented Feb 11, 2024

Formatting min value works as of 8e42eef. Note that it is not particularly meaningful, we format whatever gmtime returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants