From 1049ac9a0b4af16e82d7f39f24a75a6660bce709 Mon Sep 17 00:00:00 2001 From: Siavash Askari Nasr Date: Tue, 20 Feb 2024 11:29:39 +0000 Subject: [PATCH] label: Use local time for $TIME variable (#17) Before this change, system's time zone was not used to return the time --- src/renderer/widgets/IWidget.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 417ceb0..0b9b366 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -36,9 +36,11 @@ static void replaceAll(std::string& str, const std::string& from, const std::str } static std::string getTime() { - const auto HHMMSS = std::chrono::hh_mm_ss{std::chrono::system_clock::now() - std::chrono::floor(std::chrono::system_clock::now())}; - const auto HRS = HHMMSS.hours().count(); - const auto MINS = HHMMSS.minutes().count(); + 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(); return (HRS < 10 ? "0" : "") + std::to_string(HRS) + ":" + (MINS < 10 ? "0" : "") + std::to_string(MINS); }