fix: assertion failed no timezone in fmt::chrono (#8344)

* fix: in tr_logGetTimeStr() do not use tz info on platforms that do not have it

* fix: simplify the supports-timezone check

Co-authored-by: Yat Ho <lagoho7@gmail.com>

---------

Co-authored-by: Yat Ho <lagoho7@gmail.com>
This commit is contained in:
Charles Kerr
2026-02-04 07:45:44 -06:00
committed by GitHub
parent 60f8d43d14
commit 142b0af415

View File

@@ -37,6 +37,8 @@ using namespace std::literals;
namespace
{
template<typename T>
inline constexpr bool HasTmGmtoffV = requires(T t) { t.tm_gmtoff; };
class tr_log_state
{
@@ -203,13 +205,9 @@ std::string_view tr_logGetTimeStr(std::chrono::system_clock::time_point const no
auto* walk = buf;
auto const now_time_t = std::chrono::system_clock::to_time_t(now);
auto const now_tm = *std::localtime(&now_time_t);
walk = fmt::format_to_n(
walk,
buflen,
"{0:%FT%R:}{1:%S}" TR_IF_WIN32("", "{0:%z}"),
now_tm,
std::chrono::time_point_cast<std::chrono::milliseconds>(now))
.out;
static bool constexpr HasTmGmtoff = HasTmGmtoffV<std::tm>;
static auto constexpr Fmt = HasTmGmtoff ? "{0:%FT%R:}{1:%S}{0:%z}"sv : "{0:%FT%R:}{1:%S}"sv;
walk = fmt::format_to_n(walk, buflen, Fmt, now_tm, std::chrono::time_point_cast<std::chrono::milliseconds>(now)).out;
#ifdef _WIN32
if (auto tz_info = TIME_ZONE_INFORMATION{}; GetTimeZoneInformation(&tz_info) != TIME_ZONE_ID_INVALID)
{