From 9c4469d0399164697f6716d0e960daa7fbe259f2 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Fri, 27 Apr 2018 13:27:47 -0700 Subject: [PATCH] Bug 795405 - All Dates in Price Database Off-By-One After 3.0 Upgrade Also Bug 791825 - Accounting Period dates off by 1. The DST start/end dates were reversed *and* the DST offset had the wrong sign in Windows, resulting in the effective timezone always being one to the west off (i.e. PDT was -9 and PST was -8). --- libgnucash/engine/gnc-timezone.cpp | 18 ++++++++++++------ libgnucash/engine/test/gtest-gnc-timezone.cpp | 13 +++++++++++-- po/POTFILES.in | 1 - 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/libgnucash/engine/gnc-timezone.cpp b/libgnucash/engine/gnc-timezone.cpp index 3d6959fb5f..876df2aac5 100644 --- a/libgnucash/engine/gnc-timezone.cpp +++ b/libgnucash/engine/gnc-timezone.cpp @@ -150,9 +150,15 @@ zone_from_regtzi (const RegTZI& regtzi, time_zone_names names) { using ndate = boost::gregorian::nth_day_of_the_week_in_month; using nth_day_rule = boost::local_time::nth_day_of_the_week_in_month_dst_rule; - + /* Note that Windows runs its biases backwards from POSIX and + * boost::date_time: It's the value added to the local time to get + * GMT rather than the value added to GMT to get local time; for + * the same reason the DaylightBias is negative as one generally + * adds an hour less to the local time to get GMT. Biases are in + * minutes. + */ duration std_off (0, regtzi.StandardBias - regtzi.Bias, 0); - duration dlt_off (0, regtzi.DaylightBias, 0); + duration dlt_off (0, -regtzi.DaylightBias, 0); duration start_time (regtzi.StandardDate.wHour, regtzi.StandardDate.wMinute, regtzi.StandardDate.wSecond); duration end_time (regtzi.DaylightDate.wHour, regtzi.DaylightDate.wMinute, @@ -165,10 +171,10 @@ zone_from_regtzi (const RegTZI& regtzi, time_zone_names names) { try { - ndate start (std_week_num, regtzi.StandardDate.wDayOfWeek, - regtzi.StandardDate.wMonth); - ndate end(dlt_week_num, regtzi.DaylightDate.wDayOfWeek, - regtzi.DaylightDate.wMonth); + ndate start (dlt_week_num, regtzi.DaylightDate.wDayOfWeek, + regtzi.DaylightDate.wMonth); + ndate end(std_week_num, regtzi.StandardDate.wDayOfWeek, + regtzi.StandardDate.wMonth); dates.reset(new nth_day_rule (start, end)); } catch (boost::gregorian::bad_month& err) diff --git a/libgnucash/engine/test/gtest-gnc-timezone.cpp b/libgnucash/engine/test/gtest-gnc-timezone.cpp index 963466c32b..a676ff1a94 100644 --- a/libgnucash/engine/test/gtest-gnc-timezone.cpp +++ b/libgnucash/engine/test/gtest-gnc-timezone.cpp @@ -46,17 +46,21 @@ TEST(gnc_timezone_constructors, test_pacific_time_constructor) TimeZoneProvider tzp (timezone); EXPECT_NO_THROW (tzp.get(2012)); TZ_Ptr tz = tzp.get (2012); - EXPECT_FALSE(tz->std_zone_abbrev().empty()); #if PLATFORM(WINDOWS) EXPECT_TRUE(tz->std_zone_abbrev() == timezone); + EXPECT_TRUE(tz->dst_zone_abbrev() == "Pacific Daylight Time"); #else EXPECT_TRUE(tz->std_zone_abbrev() == "PST"); EXPECT_TRUE(tz->dst_zone_abbrev() == "PDT"); #endif EXPECT_EQ(-8, tz->base_utc_offset().hours()); - + auto dst_offset = tz->base_utc_offset() + tz->dst_offset(); + EXPECT_EQ(-7, dst_offset.hours()); EXPECT_EQ(12, tz->dst_local_start_time (2017).date().day()); + EXPECT_EQ(3, tz->dst_local_start_time (2017).date().month()); + EXPECT_EQ(5, tz->dst_local_end_time (2017).date().day()); + EXPECT_EQ(11, tz->dst_local_end_time (2017).date().month()); } #if !PLATFORM(WINDOWS) @@ -284,8 +288,13 @@ TEST(gnc_timezone_constructors, test_IANA_Minsk_tz) TEST(gnc_timezone_constructors, test_bogus_time_constructor) { +#if PLATFORM(WINDOWS) + EXPECT_THROW(TimeZoneProvider tzp ("New York Standard Time"), + std::invalid_argument); +#else TimeZoneProvider tzp ("New York Standard Time"); TimeZoneProvider machine (""); EXPECT_EQ(machine.get(2006)->std_zone_abbrev(), tzp.get(2006)->std_zone_abbrev()); +#endif } diff --git a/po/POTFILES.in b/po/POTFILES.in index dc896a7716..9cdb537304 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -449,7 +449,6 @@ gnucash/report/report-system/html-acct-table.scm gnucash/report/report-system/html-barchart.scm gnucash/report/report-system/html-document.scm gnucash/report/report-system/html-fonts.scm -gnucash/report/report-system/html-jqplot.scm gnucash/report/report-system/html-linechart.scm gnucash/report/report-system/html-piechart.scm gnucash/report/report-system/html-scatter.scm