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

Modifier for timezone offset result in compile error #3220

Closed
dgnthr opened this issue Dec 8, 2022 · 5 comments · Fixed by #3222
Closed

Modifier for timezone offset result in compile error #3220

dgnthr opened this issue Dec 8, 2022 · 5 comments · Fixed by #3222

Comments

@dgnthr
Copy link

dgnthr commented Dec 8, 2022

Hi,

I'm currently trying to print ISO8601 compatible time strings.

As per the specification I can print the timezone offset to UTC with the "%z" conversion specifier. This should for example print "+0100". Using the modifier E or O as in "%Ez" should print "+01:00". If I use either modifier I get a compile time exception FMT_THROW(format_error("invalid format"));

The example code I use is

#include <chrono>
#include <fmt/chrono.h>

int main() {
    auto time = std::time(0);
    auto LocalTime = std::localtime(&time);
    fmt::print("{:%z}\n", *LocalTime);
    fmt::print("{:%Oz}\n", *LocalTime);

    return 0;
}

Also see the example on compiler explorer https://godbolt.org/z/9cEvzKPn9

Am I doing something wrong? Thank you for your time!

@dgnthr
Copy link
Author

dgnthr commented Dec 8, 2022

I just checked the source code and saw that the modifiers (E, O) are not implemented for %z. I'll just use it without the colon.

@phprus
Copy link
Contributor

phprus commented Dec 9, 2022

Modifiers (E, O) are not defined for %z format:
https://en.cppreference.com/w/cpp/chrono/c/strftime

@dgnthr
Copy link
Author

dgnthr commented Dec 9, 2022

I was referencing this https://en.cppreference.com/w/cpp/chrono/duration/formatter (close to the bottom).

The modified commands %Ez and %Oz insert a : between the hours and minutes (e.g., -04:30).

@phprus
Copy link
Contributor

phprus commented Dec 9, 2022

@dgnthr
PR: #3222

@dgnthr
Copy link
Author

dgnthr commented Dec 9, 2022

Wow! Amazingly fast. Thank you so much!

@dgnthr dgnthr closed this as completed Dec 9, 2022
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 a pull request may close this issue.

2 participants