mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
@@ -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):
|
||||
|
||||
@@ -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&)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user