You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
spdlog uses the function utc_minutes_offset in the z_formatter to format the '%z' part of a format string (UTC-offset) when logging time. The function has three implementations, one of which is chosen at compile time via marcro defines (Windows, SunOS/Solaris, default).
The SunOS/Solaris implementation, however, returns the difference of the given tm and gmtime(now) instead, which can be an arbitrary value. If a unit test for a logging subsystem logs a message at a defined point in time to get identical output in every test run, for instance, the difference could amount to years.
The function returns the correct value only in case tm is at most the fractional part of a second before localtime(now) or roughly a minute after, otherwise the truncation in the return statement will produce wrong values.
This assumes that tm has the same timezone as the local time, which seems like the only reasonable assumption on platforms missing the tm_gmtoff-field.
It also assumes that daylight savings time advances the clock by 1h, which is not universally true, e.g. in parts of Australia.
The text was updated successfully, but these errors were encountered:
…workaround)
Apple platforms have had the tm_gmtoff-field at least since Mac OS X 10.0,
as are POSIX.1-2024 conforming systems, which are also required to support
it.
This has the unfortunate effect to use the SunOS/Solaris fallback, which
doesn't compute the correct value if the passed value of tm isn't the
current system time, i.e. localtime(::time()) (gabime#3351).
spdlog uses the function
utc_minutes_offset
in thez_formatter
to format the '%z' part of a format string (UTC-offset) when logging time. The function has three implementations, one of which is chosen at compile time via marcro defines (Windows, SunOS/Solaris, default).The SunOS/Solaris implementation, however, returns the difference of the given
tm
andgmtime(now)
instead, which can be an arbitrary value. If a unit test for a logging subsystem logs a message at a defined point in time to get identical output in every test run, for instance, the difference could amount to years.The function returns the correct value only in case
tm
is at most the fractional part of a second beforelocaltime(now)
or roughly a minute after, otherwise the truncation in the return statement will produce wrong values.spdlog/include/spdlog/details/os-inl.h
Line 298 in 3335c38
A better solution could look like this:
This assumes that
tm
has the same timezone as the local time, which seems like the only reasonable assumption on platforms missing thetm_gmtoff
-field.It also assumes that daylight savings time advances the clock by 1h, which is not universally true, e.g. in parts of Australia.
The text was updated successfully, but these errors were encountered: