mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix fencepost error in calculating the week_num for POSIX timezone rules.
Fixes CI failure caused by US starting DST in 2021, a year in which March began on a Monday.
This commit is contained in:
@@ -109,6 +109,8 @@
|
||||
PyDateTime_IMPORT;
|
||||
struct tm t;
|
||||
gnc_localtime_r(&$1, &t);
|
||||
printf("\nConverting %d hours and %d minutes in zone %ld %s to python local time\n",
|
||||
t.tm_hour, t.tm_min, t.tm_gmtoff/3600, t.tm_isdst ? "DST" : "STD");
|
||||
$result = PyDateTime_FromDateAndTime(t.tm_year + 1900, t.tm_mon + 1,
|
||||
t.tm_mday, t.tm_hour, t.tm_min,
|
||||
t.tm_sec, 0);
|
||||
|
||||
@@ -500,7 +500,7 @@ namespace DSTRule
|
||||
|
||||
Transition::Transition(gregorian_date date) :
|
||||
month(date.month()), dow(date.day_of_week()),
|
||||
week(static_cast<week_num>((7 + date.day() - date.day_of_week()) / 7))
|
||||
week(static_cast<week_num>((6 + date.day() - date.day_of_week()) / 7))
|
||||
{}
|
||||
|
||||
bool
|
||||
|
||||
@@ -518,15 +518,34 @@ TEST(gnc_datetime_functions, test_date)
|
||||
EXPECT_EQ(ymd.day - (12 + atime.offset() / 3600) / 24, 13);
|
||||
}
|
||||
/* This test works only in the America/LosAngeles time zone and
|
||||
* there's no way at present to make it more flexible.
|
||||
TEST(gnc_datetime_functions, test_timezone_offset)
|
||||
{
|
||||
* there's no straightforward wat to make it more flexible. It ensures
|
||||
* that DST in that timezone transitions correctly for each day of the
|
||||
* week in which March begines.
|
||||
|
||||
TEST(gnc_datetime_functions, test_timezone_offset)
|
||||
{
|
||||
struct Timepair
|
||||
{
|
||||
time64 before;
|
||||
time64 after;
|
||||
};
|
||||
std::array<Timepair, 7> years{
|
||||
Timepair{1615633140, 1615719540}, //2021, Monday
|
||||
Timepair{1457780340, 1457866740}, //2016, Tuesday
|
||||
Timepair{1489229940, 1489316340}, //2017, Wednesday
|
||||
Timepair{1520679540, 1520765940}, //2018, Thursday
|
||||
Timepair{1552129140, 1552215540}, //2019, Friday
|
||||
Timepair{1741431540, 1741517940}, //2025, Saturday
|
||||
Timepair{1583578740, 1583665140} //2020, Sunday
|
||||
};
|
||||
for (auto year : years)
|
||||
{
|
||||
GncDateTime before{year.before};
|
||||
GncDateTime after{year.after};
|
||||
// std::cerr << before.format_iso8601() << std::endl;
|
||||
EXPECT_EQ(-28800, before.offset());
|
||||
EXPECT_EQ(-25200, after.offset());
|
||||
}
|
||||
|
||||
GncDateTime gncdt1(1488797940); //6 Mar 2017
|
||||
EXPECT_EQ(-28800, gncdt1.offset());
|
||||
GncDateTime gncdt2(1489661940); //16 Mar 2017 10:59 Z
|
||||
EXPECT_EQ(-25200, gncdt2.offset());
|
||||
GncDateTime gncdt3(1490525940); //26 Mar 2017
|
||||
EXPECT_EQ(-25200, gncdt3.offset());
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user