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).
This commit is contained in:
John Ralls 2018-04-27 13:27:47 -07:00
parent 83e993fb80
commit 9c4469d039
3 changed files with 23 additions and 9 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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