Date/time formatting fixes

This commit is contained in:
Dan Paulat 2024-05-02 23:41:17 -05:00
parent 6c482b4ccf
commit d9bcb7f086
2 changed files with 12 additions and 7 deletions

View file

@ -1142,8 +1142,8 @@ void MainWindowImpl::ConnectOtherSignals()
this, this,
[this]() [this]()
{ {
timeLabel_->setText(QString("%1 UTC").arg(QString::fromStdString( timeLabel_->setText(QString::fromStdString(
util::TimeString(std::chrono::system_clock::now())))); util::TimeString(std::chrono::system_clock::now())));
timeLabel_->setVisible(true); timeLabel_->setVisible(true);
}); });
clockTimer_.start(1000); clockTimer_.start(1000);

View file

@ -55,7 +55,12 @@ std::string TimeString(std::chrono::system_clock::time_point time,
{ {
using namespace std::chrono; 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; using namespace date;
#endif #endif
@ -70,22 +75,22 @@ std::string TimeString(std::chrono::system_clock::time_point time,
if (clockFormat == ClockFormat::_24Hour) if (clockFormat == ClockFormat::_24Hour)
{ {
os << format("{:%Y-%m-%d %H:%M:%S %Z}", zt); os << format(FORMAT_STRING_24_HOUR, zt);
} }
else else
{ {
os << format("{:%Y-%m-%d %I:%M:%S %p %Z}", zt); os << format(FORMAT_STRING_12_HOUR, zt);
} }
} }
else else
{ {
if (clockFormat == ClockFormat::_24Hour) if (clockFormat == ClockFormat::_24Hour)
{ {
os << format("{:%Y-%m-%d %H:%M:%S %Z}", timeInSeconds); os << format(FORMAT_STRING_24_HOUR, timeInSeconds);
} }
else else
{ {
os << format("{:%Y-%m-%d %I:%M:%S %p %Z}", timeInSeconds); os << format(FORMAT_STRING_12_HOUR, timeInSeconds);
} }
} }
} }