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

c++20. clock chrono API. STL + format #2659

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

LukashonakV
Copy link
Contributor

@LukashonakV LukashonakV commented Nov 10, 2023

Hi @Alexays ,
This PR is created in order to fully switch clock module to use standard chrono library + format library in c++20. date library by @HowardHinnant has been taken into standard in C++20. STL format library supports chrono now.
So clock module under C++20 now no more using fmt library and construct necessary information using STL.
One more major change: clock module is fully rewritten and as a base is using TZ(zoned time). It should minimize time conversion between local and zoned time.
Structure of the helper include/util/date.hpp now provides compile time switching between
"date/tz.h" + "fmt/chrono.h" <-> <chrono> + <format>
timezoned_time_list placeholder now is renamed to tz_list . This change is attracted in man page too.
+ it should solve any issues during compilation when compiler gets ambiguous errors of the date/format functions


This PR is also a prerequisite to start digging into different calendar implementation (what is raised in #2260)

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
@LukashonakV
Copy link
Contributor Author

Even clang CI has failed (due to timeout reason) in my branch it looks OK
c++20. clock chrono API. STL + format #239

@Alexays Alexays merged commit a51dd8f into Alexays:master Nov 12, 2023
7 of 8 checks passed
@Artturin
Copy link
Contributor

We got a failure in nixpkgs-wayland

In file included from ../include/modules/clock.hpp:4,
                 from ../src/modules/clock.cpp:1:
../include/util/date.hpp:34:26: warning: literal operator suffixes not preceded by '_' are reserved for future standardization [-Wliteral-suffix]
   34 | constexpr decltype(auto) operator""d(unsigned long long d) noexcept {
      |                          ^~~~~~~~
../src/modules/clock.cpp: In member function 'const std::string waybar::modules::Clock::get_calendar(const date::year_month_day&, const date::year_month_day&, const date::time_zone*)':
../src/modules/clock.cpp:323:43: error: cannot bind non-const lvalue reference of type 'date::zoned_time<std::chrono::duration<long int> >&' to an rvalue of type 'date::zoned_seconds' {aka 'date::zoned_time<std::chrono::duration<long int> >'}
  323 |                               (line == 2) ? zoned_seconds{tz, local_days{ymTmp / 1}}
      |                               ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  324 |                                           : zoned_seconds{tz, local_days{cldGetWeekForLine(
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325 |                                                                   ymTmp, firstdow, line)}}))
      |                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/format.h:49,
                 from ../include/util/date.hpp:9:
/nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/core.h:1824:35: note:   initializing argument 1 of 'constexpr fmt::v10::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<T>::type>::type ...> fmt::v10::make_format_args(T& ...) [with Context = basic_format_context<appender, char>; T = {date::zoned_time<std::chrono::duration<long int, std::ratio<1, 1> >, const date::time_zone*>}]'
 1824 | constexpr auto make_format_args(T&... args)
      |                                 ~~^~~~~~~~
../src/modules/clock.cpp:345:43: error: cannot bind non-const lvalue reference of type 'date::zoned_time<std::chrono::duration<long int> >&' to an rvalue of type 'date::zoned_seconds' {aka 'date::zoned_time<std::chrono::duration<long int> >'}
  345 |                               (line == 2) ? zoned_seconds{tz, local_days{ymTmp / 1}}
      |                               ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  346 |                                           : zoned_seconds{tz, local_days{cldGetWeekForLine(
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  347 |                                                                   ymTmp, firstdow, line)}}));
      |                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/core.h:1824:35: note:   initializing argument 1 of 'constexpr fmt::v10::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<T>::type>::type ...> fmt::v10::make_format_args(T& ...) [with Context = basic_format_context<appender, char>; T = {date::zoned_time<std::chrono::duration<long int, std::ratio<1, 1> >, const date::time_zone*>}]'
 1824 | constexpr auto make_format_args(T&... args)
      |                                 ~~^~~~~~~~
../src/modules/clock.cpp:356:89: error: cannot bind non-const lvalue reference of type 'std::__cxx11::basic_string<char>&' to an rvalue of type 'std::__cxx11::basic_ostringstream<char>::__string_type' {aka 'std::__cxx11::basic_string<char>'}
  356 |         tmp << fmt_lib::vformat(locale_, fmtMap_[line], fmt_lib::make_format_args(os.str()));
      |                                                                                   ~~~~~~^~
/nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/core.h:1824:35: note:   initializing argument 1 of 'constexpr fmt::v10::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<T>::type>::type ...> fmt::v10::make_format_args(T& ...) [with Context = basic_format_context<appender, char>; T = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]'
 1824 | constexpr auto make_format_args(T&... args)
      |                                 ~~^~~~~~~~
../src/modules/clock.cpp:367:78: error: cannot bind non-const lvalue reference of type 'std::__cxx11::basic_string<char>&' to an rvalue of type 'std::__cxx11::basic_ostringstream<char>::__string_type' {aka 'std::__cxx11::basic_string<char>'}
  367 |       fmt_lib::vformat(locale_, fmtMap_[2], fmt_lib::make_format_args(tmp.str())),
      |                                                                       ~~~~~~~^~
/nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/core.h:1824:35: note:   initializing argument 1 of 'constexpr fmt::v10::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<T>::type>::type ...> fmt::v10::make_format_args(T& ...) [with Context = basic_format_context<appender, char>; T = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]'
 1824 | constexpr auto make_format_args(T&... args)
      |                                 ~~^~~~~~~~
../src/modules/clock.cpp:369:83: error: cannot bind non-const lvalue reference of type 'std::__cxx11::basic_string<char>&' to an rvalue of type 'std::__cxx11::basic_string<char>'
  369 |       fmt_lib::vformat(locale_, fmtMap_[3], fmt_lib::make_format_args(date::format("{:L%e}", d))));
      |                                                                       ~~~~~~~~~~~~^~~~~~~~~~~~~
/nix/store/frlcc137wnrld52w9xdrdcs09chkprlr-fmt-10.1.1-dev/include/fmt/core.h:1824:35: note:   initializing argument 1 of 'constexpr fmt::v10::format_arg_store<Context, typename std::remove_cv<typename std::remove_reference<T>::type>::type ...> fmt::v10::make_format_args(T& ...) [with Context = basic_format_context<appender, char>; T = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >}]'
 1824 | constexpr auto make_format_args(T&... args)
      |                                 ~~^~~~~~~~
[194/196] Compiling C++ object test/waybar_test.p/date.cpp.o
In file included from ../test/date.cpp:1:
../include/util/date.hpp:34:26: warning: literal operator suffixes not preceded by '_' are reserved for future standardization [-Wliteral-suffix]
   34 | constexpr decltype(auto) operator""d(unsigned long long d) noexcept {
      |                          ^~~~~~~~
ninja: build stopped: subcommand failed.

@LukashonakV
Copy link
Contributor Author

I'll check soon

@LukashonakV
Copy link
Contributor Author

Hi @Artturin , can you check again please. See #2668

@apiraino
Copy link

apiraino commented May 4, 2024

Commit 86a3898 broke the parsing of {timezoned_time_list} that was introduced in #1333 and replaced that with {tz_list}.

Not a big deal, but it would be nice to mention breaking changes somewhere in the changelog. I have updated the wiki page about the clock.

cc: @Alexays

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.

4 participants