Commit 1a80a583 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

in getClosestDate(), if date is not passed, timezone of target_date should be respected.

parent eff3f56d
......@@ -160,10 +160,11 @@ def getClosestDate(date=None, target_date=None,
-> return DateTime('2004/02/14')
"""
if date is None:
date = DateTime('2000/01/01')
if target_date is None:
target_date = DateTime()
if date is None:
date = DateTime('2000/01/01')
date._tz = target_date._tz
earlier_target_date = target_date - millis
......
......@@ -54,7 +54,9 @@ ZopeTestCase.installProduct('ERP5Type')
from DateTime import DateTime
from Products.ERP5Type.DateUtils import addToDate, getIntervalListBetweenDates, atTheEndOfPeriod
from Products.ERP5Type.DateUtils import addToDate, getIntervalListBetweenDates, \
atTheEndOfPeriod, getClosestDate
class TestDateUtils(unittest.TestCase):
"""
......@@ -186,6 +188,18 @@ class TestDateUtils(unittest.TestCase):
self.assertEqual('Nov. 1, 2008 12:00 am US/Eastern',
atTheEndOfPeriod(DateTime('2008/10/01 US/Eastern'), 'month').pCommonZ())
def test_getClosestDate(self):
target_date = DateTime('2008/08/15 00:00:00 GMT+2')
self.assertEqual('Aug. 1, 2008 12:00 am GMT+2',
getClosestDate(target_date=target_date, precision='month', before=True).pCommonZ())
self.assertEqual('Sep. 1, 2008 12:00 am GMT+2',
getClosestDate(target_date=target_date, precision='month', before=False).pCommonZ())
date = DateTime('2008/01/10 00:00:00 GMT-2')
self.assertEqual('Aug. 10, 2008 12:00 am GMT-2',
getClosestDate(date=date, target_date=target_date, precision='month', before=True).pCommonZ())
self.assertEqual('Sep. 10, 2008 12:00 am GMT-2',
getClosestDate(date=date, target_date=target_date, precision='month', before=False).pCommonZ())
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDateUtils))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment