Windows utc_minutes_offset(): Fix historical DST accuracy and improve offset calculation speed (~2.5x) (#3508)

* New utc offset impl for windows and unit tests

* Update utc_minutes_offset()

* Fix warning

* Fix warning

* Fix timezone tests

* Fix timezone tests

* Update tests/test_pattern_formatter.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update tests/CMakeLists.txt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Updated utc_minutes_offset() impl

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Gabi Melman
2026-01-04 18:01:55 +02:00
committed by GitHub
parent 2670f47d02
commit b656d1ceec
4 changed files with 176 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
#include "includes.h"
#include "test_sink.h"
#include <regex>
#include <chrono>
using spdlog::memory_buf_t;
@@ -77,18 +77,20 @@ TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") {
oss.str());
}
TEST_CASE("GMT offset ", "[pattern_formatter]") {
// see test_timezone.cpp for actual UTC offset calculation tests
TEST_CASE("UTC offset", "[pattern_formatter]") {
using namespace std::chrono_literals;
const auto now = std::chrono::system_clock::now();
const auto yesterday = now - 24h;
std::string result =
log_to_str_with_time(now, "Some message", "%z", spdlog::pattern_time_type::local, "\n");
#ifndef SPDLOG_NO_TZ_OFFSET
const std::string expected_result = "+00:00\n";
// Match format: +HH:MM or -HH:MM
std::regex re(R"([+-]\d{2}:[0-5]\d\n)");
REQUIRE(std::regex_match(result, re));
#else
const std::string expected_result = "+??:??\n";
REQUIRE(result == "+??:??\n");
#endif
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc,
"\n") == expected_result);
}
TEST_CASE("color range test1", "[pattern_formatter]") {