From 163b7039646a0afdfe33b715e449fe1ea6b6a9db Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 18 Feb 2025 12:28:30 -0600 Subject: [PATCH] Use constexpr instead of #define where possible in time.cpp --- wxdata/source/scwx/util/time.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/wxdata/source/scwx/util/time.cpp b/wxdata/source/scwx/util/time.cpp index 7a706224..20c6121d 100644 --- a/wxdata/source/scwx/util/time.cpp +++ b/wxdata/source/scwx/util/time.cpp @@ -60,15 +60,19 @@ std::string TimeString(std::chrono::system_clock::time_point time, using namespace std::chrono; #if (__cpp_lib_chrono >= 201907L) -# 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}" namespace date = std::chrono; namespace df = std; + + static constexpr std::string_view kFormatString24Hour = + "{:%Y-%m-%d %H:%M:%S %Z}"; + static constexpr std::string_view kFormatString12Hour = + "{:%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; namespace df = date; + +# define kFormatString24Hour "%Y-%m-%d %H:%M:%S %Z" +# define kFormatString12Hour "%Y-%m-%d %I:%M:%S %p %Z" #endif auto timeInSeconds = time_point_cast(time); @@ -84,11 +88,11 @@ std::string TimeString(std::chrono::system_clock::time_point time, if (clockFormat == ClockFormat::_24Hour) { - os << df::format(FORMAT_STRING_24_HOUR, zt); + os << df::format(kFormatString24Hour, zt); } else { - os << df::format(FORMAT_STRING_12_HOUR, zt); + os << df::format(kFormatString12Hour, zt); } } catch (const std::exception& ex) @@ -110,11 +114,11 @@ std::string TimeString(std::chrono::system_clock::time_point time, { if (clockFormat == ClockFormat::_24Hour) { - os << df::format(FORMAT_STRING_24_HOUR, timeInSeconds); + os << df::format(kFormatString24Hour, timeInSeconds); } else { - os << df::format(FORMAT_STRING_12_HOUR, timeInSeconds); + os << df::format(kFormatString12Hour, timeInSeconds); } } }