diff --git a/src/helpers/Log.hpp b/src/helpers/Log.hpp index 863512e..ebf8c4d 100644 --- a/src/helpers/Log.hpp +++ b/src/helpers/Log.hpp @@ -18,7 +18,6 @@ enum eLogLevel { Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \ std::format(reason, ##__VA_ARGS__), __LINE__, \ ([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \ - printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \ std::abort(); \ } diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 21a49f2..452316c 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -100,21 +100,44 @@ static void replaceAllLayout(std::string& str) { } } +static bool logMissingTzOnce = true; static std::string getTime() { - const auto current_zone = std::chrono::current_zone(); - const auto HHMMSS = std::chrono::hh_mm_ss{current_zone->to_local(std::chrono::system_clock::now()) - - std::chrono::floor(current_zone->to_local(std::chrono::system_clock::now()))}; - const auto HRS = HHMMSS.hours().count(); - const auto MINS = HHMMSS.minutes().count(); + const auto PCURRENTTZ = (true) ? nullptr : std::chrono::current_zone(); + const auto TPNOW = std::chrono::system_clock::now(); + + // + std::chrono::hh_mm_ss hhmmss; + if (!PCURRENTTZ) { + if (logMissingTzOnce) { + Debug::log(WARN, "Current timezone unknown for $TIME. Falling back to UTC!"); + logMissingTzOnce = false; + } + hhmmss = std::chrono::hh_mm_ss{TPNOW - std::chrono::floor(TPNOW)}; + } else + hhmmss = std::chrono::hh_mm_ss{PCURRENTTZ->to_local(TPNOW) - std::chrono::floor(PCURRENTTZ->to_local(TPNOW))}; + + const auto HRS = hhmmss.hours().count(); + const auto MINS = hhmmss.minutes().count(); return (HRS < 10 ? "0" : "") + std::to_string(HRS) + ":" + (MINS < 10 ? "0" : "") + std::to_string(MINS); } static std::string getTime12h() { - const auto current_zone = std::chrono::current_zone(); - const auto HHMMSS = std::chrono::hh_mm_ss{current_zone->to_local(std::chrono::system_clock::now()) - - std::chrono::floor(current_zone->to_local(std::chrono::system_clock::now()))}; - const auto HRS = HHMMSS.hours().count(); - const auto MINS = HHMMSS.minutes().count(); + const auto PCURRENTTZ = std::chrono::current_zone(); + const auto TPNOW = std::chrono::system_clock::now(); + + // + std::chrono::hh_mm_ss hhmmss; + if (!PCURRENTTZ) { + if (logMissingTzOnce) { + Debug::log(WARN, "Current timezone unknown for $TIME12. Falling back to UTC!"); + logMissingTzOnce = false; + } + hhmmss = std::chrono::hh_mm_ss{TPNOW - std::chrono::floor(TPNOW)}; + } else + hhmmss = std::chrono::hh_mm_ss{PCURRENTTZ->to_local(TPNOW) - std::chrono::floor(PCURRENTTZ->to_local(TPNOW))}; + + const auto HRS = hhmmss.hours().count(); + const auto MINS = hhmmss.minutes().count(); return (HRS % 12 < 10 ? "0" : "") + std::to_string(HRS % 12) + ":" + (MINS < 10 ? "0" : "") + std::to_string(MINS) + (HRS < 12 ? " AM" : " PM"); }