Fix test failure for timezones west of the prime meridian.

The previous fix didn't calculate the comparison time correctly and
ended up in the wrong day because the GMT time is before the local time.

In the course of checking the corner-case timezones (Midway and
Kiritimati) I found an error in the GncDateTime calculation of the
neutral time, so fixed that too.
This commit is contained in:
John Ralls
2020-05-02 15:29:02 -07:00
parent ca9d58b278
commit 6a3fabc30d
2 changed files with 11 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
from unittest import main
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
from gnucash import Account, \
ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, ACCT_TYPE_BANK, \
@@ -56,8 +56,15 @@ class TestBusiness(BusinessSession):
self.assertEqual( NAME, self.employee.GetUsername() )
def test_post(self):
self.assertEqual(datetime.now(timezone.utc).replace(hour=10, minute=59, second=0, microsecond=0).astimezone(),
self.invoice.GetDatePosted().astimezone())
utc_offset = datetime.now().astimezone().utcoffset()
now = datetime.now().astimezone()
neutral_time = (now + utc_offset).astimezone(timezone.utc).replace(hour=10, minute=59, second=0, microsecond=0)
if utc_offset > timedelta(hours=13):
neutral_time -= utc_offset - timedelta(hours=13);
if utc_offset < timedelta(hours=-10):
neutral_time += timedelta(hours=-10) - utc_offset
self.assertEqual(neutral_time,
self.invoice.GetDatePosted().astimezone(timezone.utc))
self.assertTrue( self.invoice.IsPosted() )
def test_owner(self):

View File

@@ -314,7 +314,7 @@ GncDateTimeImpl::GncDateTimeImpl(const GncDateImpl& date, DayPart part) :
if (offset < hours(-10))
m_time -= hours(offset.hours() + 10);
if (offset > hours(13))
m_time -= hours(offset.hours() - 11);
m_time += hours(13 - offset.hours());
}
catch(boost::gregorian::bad_year&)
{