From dcb7a8c24265b2160648abc8d59ff9a7e8ffb7e7 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 4 Sep 2025 15:21:32 -0700 Subject: [PATCH] Fix GncDateTime tests on Windows. --- libgnucash/engine/gnc-datetime.cpp | 2 +- libgnucash/engine/test/gtest-gnc-datetime.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp index 2396d8721c..a31d33f850 100644 --- a/libgnucash/engine/gnc-datetime.cpp +++ b/libgnucash/engine/gnc-datetime.cpp @@ -585,7 +585,7 @@ std::string GncDateTimeImpl::format_zulu(const char* format) const { #ifdef __MINGW32__ - auto tz = m_time.zone(); + auto tz = utc_zone; auto tm = static_cast(*this); auto sformat = win_format_tz_abbrev(format, tz, tm.tm_isdst); sformat = win_format_tz_name(sformat, tz, tm.tm_isdst); diff --git a/libgnucash/engine/test/gtest-gnc-datetime.cpp b/libgnucash/engine/test/gtest-gnc-datetime.cpp index aa538050df..7c4a2b7e7c 100644 --- a/libgnucash/engine/test/gtest-gnc-datetime.cpp +++ b/libgnucash/engine/test/gtest-gnc-datetime.cpp @@ -451,7 +451,17 @@ TEST(gnc_datetime_constructors, test_DST_start_transition_time) _reset_tzp(); _set_tzp(tzp_can); for (auto hours = 0; hours < 23; ++hours) + { +#ifdef __MINGW32__ +/* Windows thinks 02:59:00 is still DST; of course on the transition + * day there is no 02:59, local time goes from 01:59:59 to 03:00:00 so + * it's an artifact anyway. + */ + if (hours == 2) + continue; +#endif EXPECT_TRUE(test_offset(1601737140, hours, 36000, 39600, "Canberra")); + } _reset_tzp(); } @@ -474,13 +484,13 @@ TEST(gnc_datetime_constructors, test_DST_end_transition_time) _reset_tzp(); } +#ifndef __MINGW32__ +/* MSWindows doesn't provide historical timezone information. Brazil + * doesn't use DST since 2019 so these tests don't work. + */ TEST(gnc_datetime_constructors, test_create_in_transition) { -#ifdef __MINGW32__ - TimeZoneProvider tzp_br{"E. South America Standard Time"}; -#else TimeZoneProvider tzp_br("America/Sao_Paulo"); -#endif _set_tzp(tzp_br); /* Test Daylight Savings start: When Sao Paolo had daylight * savings time it ended at 23:59:59 and the next second was @@ -519,6 +529,7 @@ TEST(gnc_datetime_constructors, test_create_in_transition) EXPECT_EQ(gncdt3.format_zulu("%Y-%m-%d %H:%M:%S %Z"), "2019-11-01 03:00:00 UTC"); EXPECT_EQ(gncdt3.format("%Y-%m-%d %H:%M:%S %Z"), "2019-11-01 00:00:00 -03"); } +#endif TEST(gnc_datetime_constructors, test_gncdate_neutral_constructor) {