mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(clock): support chrono Time Zone extensions.
Use chrono Calendars and Time Zones (P0355R7, P1466R3) when available instead of the `date` library. Verified with a patched build of a recent GCC 13 snapshot.
This commit is contained in:
parent
6225db0a48
commit
93e340a081
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#ifdef HAVE_LIBDATE
|
#if defined(HAVE_CHRONO_TIMEZONES) || defined(HAVE_LIBDATE)
|
||||||
#include "modules/clock.hpp"
|
#include "modules/clock.hpp"
|
||||||
#else
|
#else
|
||||||
#include "modules/simpleclock.hpp"
|
#include "modules/simpleclock.hpp"
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <date/tz.h>
|
|
||||||
|
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
|
#include "util/date.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
@ -1,8 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <date/tz.h>
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#if HAVE_CHRONO_TIMEZONES
|
||||||
|
#include <chrono>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
/* Compatibility layer for <date/tz.h> on top of C++20 <chrono> */
|
||||||
|
namespace date {
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
namespace literals {
|
||||||
|
using std::chrono::last;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto format(const std::string& spec, const auto& ztime) {
|
||||||
|
return spec.empty() ? "" : std::vformat("{:L" + spec + "}", std::make_format_args(ztime));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto format(const std::locale& loc, const std::string& spec, const auto& ztime) {
|
||||||
|
return spec.empty() ? "" : std::vformat(loc, "{:L" + spec + "}", std::make_format_args(ztime));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace date
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <date/tz.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename Duration, typename TimeZonePtr>
|
template <typename Duration, typename TimeZonePtr>
|
||||||
struct fmt::formatter<date::zoned_time<Duration, TimeZonePtr>> {
|
struct fmt::formatter<date::zoned_time<Duration, TimeZonePtr>> {
|
||||||
std::string_view specs;
|
std::string_view specs;
|
||||||
|
22
meson.build
22
meson.build
@ -123,11 +123,18 @@ gtk_layer_shell = dependency('gtk-layer-shell-0',
|
|||||||
required: get_option('gtk-layer-shell'),
|
required: get_option('gtk-layer-shell'),
|
||||||
fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep'])
|
fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep'])
|
||||||
systemd = dependency('systemd', required: get_option('systemd'))
|
systemd = dependency('systemd', required: get_option('systemd'))
|
||||||
tz_dep = dependency('date',
|
|
||||||
required: false,
|
cpp_lib_chrono = compiler.compute_int('__cpp_lib_chrono', prefix : '#include <chrono>')
|
||||||
default_options : [ 'use_system_tzdb=true' ],
|
have_chrono_timezones = cpp_lib_chrono >= 201907
|
||||||
modules : [ 'date::date', 'date::date-tz' ],
|
if have_chrono_timezones
|
||||||
fallback: [ 'date', 'tz_dep' ])
|
tz_dep = declare_dependency()
|
||||||
|
else
|
||||||
|
tz_dep = dependency('date',
|
||||||
|
required: false,
|
||||||
|
default_options : [ 'use_system_tzdb=true' ],
|
||||||
|
modules : [ 'date::date', 'date::date-tz' ],
|
||||||
|
fallback: [ 'date', 'tz_dep' ])
|
||||||
|
endif
|
||||||
|
|
||||||
prefix = get_option('prefix')
|
prefix = get_option('prefix')
|
||||||
sysconfdir = get_option('sysconfdir')
|
sysconfdir = get_option('sysconfdir')
|
||||||
@ -312,7 +319,10 @@ if get_option('rfkill').enabled() and is_linux
|
|||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if tz_dep.found()
|
if have_chrono_timezones
|
||||||
|
add_project_arguments('-DHAVE_CHRONO_TIMEZONES', language: 'cpp')
|
||||||
|
src_files += 'src/modules/clock.cpp'
|
||||||
|
elif tz_dep.found()
|
||||||
add_project_arguments('-DHAVE_LIBDATE', language: 'cpp')
|
add_project_arguments('-DHAVE_LIBDATE', language: 'cpp')
|
||||||
src_files += 'src/modules/clock.cpp'
|
src_files += 'src/modules/clock.cpp'
|
||||||
else
|
else
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "util/date.hpp"
|
|
||||||
#include "util/ustring_clen.hpp"
|
#include "util/ustring_clen.hpp"
|
||||||
#ifdef HAVE_LANGINFO_1STDAY
|
#ifdef HAVE_LANGINFO_1STDAY
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user