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

%j doesn't seem to work with a duration object #3643

Closed
yannou38 opened this issue Sep 18, 2023 · 3 comments · Fixed by #3732
Closed

%j doesn't seem to work with a duration object #3643

yannou38 opened this issue Sep 18, 2023 · 3 comments · Fixed by #3732

Comments

@yannou38
Copy link

here is the snippet : https://godbolt.org/z/jTxGzvEhT

I'm trying to format a duration in days:hours:minutes:seconds.
using %T work wonders for hours:minutes:seconds, however %j does not compile at all, despite the docs saying "If the type being formatted is a specialization of duration, the decimal number of days without padding." which should fill my use case.

here is a snippet of my compilation error:

[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h: In member function 'void DemoWindow::acquisitionFinished()':
[build] C:\Projets\CB110_DATA_LOGGER_SW\UI\demowindow.cpp:124:53:   in 'constexpr' expansion of 'fmt::v10::basic_format_string<char, std::chrono::duration<long long int, std::ratio<1, 1> >&>("{:%j}")'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/core.h:2740:40:   in 'constexpr' expansion of 'fmt::v10::detail::parse_format_string<true, char, format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > > >(((fmt::v10::basic_format_string<char, std::chrono::duration<long long int, std::ratio<1, 1> >&>*)this)->fmt::v10::basic_format_string<char, std::chrono::duration<long long int, std::ratio<1, 1> >&>::str_, fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >(fmt::v10::basic_string_view<char>(((const char*)s))))'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/core.h:2489:44:   in 'constexpr' expansion of 'fmt::v10::detail::parse_replacement_field<char, format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >&>((p + -1), end, (* & handler))'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/core.h:2467:38:   in 'constexpr' expansion of '(& handler)->fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >::on_format_specs(adapter.fmt::v10::detail::parse_replacement_field<char, format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >&>(const char*, const char*, format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >&)::id_adapter::arg_id, (begin + 1), end)'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/core.h:2639:51:   in 'constexpr' expansion of '((fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >*)this)->fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >::parse_funcs_[id](((fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >*)this)->fmt::v10::detail::format_string_checker<char, std::chrono::duration<long long int, std::ratio<1, 1> > >::context_)'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/core.h:2546:53:   in 'constexpr' expansion of 'fmt::v10::formatter<std::chrono::duration<long long int>, char, void>().fmt::v10::formatter<std::chrono::duration<long long int>, char, void>::parse(ctx.fmt::v10::detail::compile_parse_context<char>::<anonymous>)'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:2035:38:   in 'constexpr' expansion of 'fmt::v10::detail::parse_chrono_format<char, chrono_format_checker&>(it, end, checker)'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:723:29:   in 'constexpr' expansion of '((fmt::v10::detail::null_chrono_spec_handler<fmt::v10::detail::chrono_format_checker>*)(& handler))->fmt::v10::detail::null_chrono_spec_handler<fmt::v10::detail::chrono_format_checker>::on_day_of_year()'
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:894:52: error: 'constexpr void fmt::v10::detail::null_chrono_spec_handler<Derived>::unsupported() [with Derived = fmt::v10::detail::chrono_format_checker]' called in a constant expression
[build]   894 |   FMT_CONSTEXPR void on_day_of_year() { unsupported(); }
[build]       |                                         ~~~~~~~~~~~^~
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:875:22: note: 'constexpr void fmt::v10::detail::null_chrono_spec_handler<Derived>::unsupported() [with Derived = fmt::v10::detail::chrono_format_checker]' is not usable as a 'constexpr' function because:
[build]   875 |   FMT_CONSTEXPR void unsupported() {
[build]       |                      ^~~~~~~~~~~
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:876:45: error: call to non-'constexpr' function 'void fmt::v10::detail::chrono_format_checker::unsupported()'
[build]   876 |     static_cast<Derived*>(this)->unsupported();
[build]       |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
[build] C:/Cache/CPM/fmt/01ac001d8da09bd242594dc67d36dccb9854883e/include/fmt/chrono.h:1578:21: note: 'void fmt::v10::detail::chrono_format_checker::unsupported()' declared here
[build]  1578 |   FMT_NORETURN void unsupported() { FMT_THROW(format_error("no date")); }
[build]       |                     ^~~~~~~~~~~

I'm using fmt v10.1.1, and originally tried on fmt 9.1.0.

Please advise me if you need additionnal information !

@vitaut
Copy link
Contributor

vitaut commented Sep 18, 2023

This is not implemented yet but a PR would be welcome.

@intelfx
Copy link
Contributor

intelfx commented Nov 5, 2023

@vitaut I'd be willing do make this happen; any pointers where to start?

@vitaut
Copy link
Contributor

vitaut commented Nov 5, 2023

intelfx added a commit to intelfx/fmt that referenced this issue Dec 1, 2023
This adds support for '%j' presentation type for duration types:

"If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes fmtlib#3643.
intelfx added a commit to intelfx/fmt that referenced this issue Dec 1, 2023
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes fmtlib#3643.
intelfx added a commit to intelfx/fmt that referenced this issue Dec 2, 2023
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes fmtlib#3643.
intelfx added a commit to intelfx/fmt that referenced this issue Dec 2, 2023
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes fmtlib#3643.
intelfx added a commit to intelfx/fmt that referenced this issue Dec 2, 2023
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes fmtlib#3643.
vitaut pushed a commit that referenced this issue Dec 3, 2023
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

Fixes #3643.
happymonkey1 pushed a commit to happymonkey1/fmt that referenced this issue Apr 7, 2024
This adds support for `%j` presentation type for duration types:

> "If the type being formatted is a specialization of duration, the decimal
number of days without padding."

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

Successfully merging a pull request may close this issue.

3 participants