From d9bcb7f08676304ba57281d772db54fcee5a270c Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 2 May 2024 23:41:17 -0500 Subject: [PATCH] Date/time formatting fixes --- scwx-qt/source/scwx/qt/main/main_window.cpp | 4 ++-- wxdata/source/scwx/util/time.cpp | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 3cedcf98..a74533f2 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -1142,8 +1142,8 @@ void MainWindowImpl::ConnectOtherSignals() this, [this]() { - timeLabel_->setText(QString("%1 UTC").arg(QString::fromStdString( - util::TimeString(std::chrono::system_clock::now())))); + timeLabel_->setText(QString::fromStdString( + util::TimeString(std::chrono::system_clock::now()))); timeLabel_->setVisible(true); }); clockTimer_.start(1000); diff --git a/wxdata/source/scwx/util/time.cpp b/wxdata/source/scwx/util/time.cpp index cb961649..0149e33a 100644 --- a/wxdata/source/scwx/util/time.cpp +++ b/wxdata/source/scwx/util/time.cpp @@ -55,7 +55,12 @@ std::string TimeString(std::chrono::system_clock::time_point time, { using namespace std::chrono; -#if !defined(_MSC_VER) +#if defined(_MSC_VER) +# define FORMAT_STRING_24_HOUR "{:%Y-%m-%d %H:%M:%S %Z}" +# define FORMAT_STRING_12_HOUR "{:%Y-%m-%d %I:%M:%S %p %Z}" +#else +# define FORMAT_STRING_24_HOUR "%Y-%m-%d %H:%M:%S %Z" +# define FORMAT_STRING_12_HOUR "%Y-%m-%d %I:%M:%S %p %Z" using namespace date; #endif @@ -70,22 +75,22 @@ std::string TimeString(std::chrono::system_clock::time_point time, if (clockFormat == ClockFormat::_24Hour) { - os << format("{:%Y-%m-%d %H:%M:%S %Z}", zt); + os << format(FORMAT_STRING_24_HOUR, zt); } else { - os << format("{:%Y-%m-%d %I:%M:%S %p %Z}", zt); + os << format(FORMAT_STRING_12_HOUR, zt); } } else { if (clockFormat == ClockFormat::_24Hour) { - os << format("{:%Y-%m-%d %H:%M:%S %Z}", timeInSeconds); + os << format(FORMAT_STRING_24_HOUR, timeInSeconds); } else { - os << format("{:%Y-%m-%d %I:%M:%S %p %Z}", timeInSeconds); + os << format(FORMAT_STRING_12_HOUR, timeInSeconds); } } }