Commit 0efb457d authored by Xiaowu Zhang's avatar Xiaowu Zhang

Revert "erp5_core: fix addToDate when removing a month"

This reverts commit 34d26a74.

from DateTime import DateTime
from erp5.component.module.DateUtils import addToDate

return addToDate(DateTime('2019/02/25'), second=6048000)

2019/02/28
parent f650b6be
......@@ -62,17 +62,6 @@ class TestDateUtils(unittest.TestCase):
addToDate(date, month=90).toZone('UTC').ISO())
self.assertEqual(DateTime('2090/01/01 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(date, year=90).toZone('UTC').ISO())
april_1 = DateTime('2001/04/01 %s' % self.timezone)
self.assertEqual(DateTime('2001/05/01 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(april_1, month=1).toZone('UTC').ISO())
december_1 = DateTime('2001/12/01 %s' % self.timezone)
self.assertEqual(DateTime('2002/01/01 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(december_1, month=1).toZone('UTC').ISO())
march_31 = DateTime('2001/03/31 %s' % self.timezone)
self.assertEqual(DateTime('2001/04/30 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(march_31, month=1).toZone('UTC').ISO())
self.assertEqual(DateTime('2001/05/1 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(march_31, month=1, day=1).toZone('UTC').ISO())
def test_negative_add_to_date(self):
date = DateTime('2000/01/01 %s' % self.timezone)
......@@ -88,14 +77,6 @@ class TestDateUtils(unittest.TestCase):
addToDate(date, month=-1).toZone('UTC').ISO())
self.assertEqual(DateTime('1999/01/01 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(date, year=-1).toZone('UTC').ISO())
march_31 = DateTime('2001/03/31 %s' % self.timezone)
self.assertEqual(DateTime('2001/02/28 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(march_31, month=-1).toZone('UTC').ISO())
self.assertEqual(DateTime('2001/02/27 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(march_31, month=-1, day=-1).toZone('UTC').ISO())
may_31 = DateTime('2000/05/31 %s' % self.timezone)
self.assertEqual(DateTime('2000/04/30 %s' % self.timezone).toZone('UTC').ISO(),
addToDate(may_31, month=-1).toZone('UTC').ISO())
def test_float_add_to_date(self):
date = DateTime('2000/01/01 %s' % self.timezone)
......
......@@ -110,8 +110,6 @@ def addToDate(date, to_add=None, **kw):
return_value[larger_key_dict[key]] = return_value[larger_key_dict[key]] + 1
for key in key_list:
if key == 'day':
continue
if to_add.get(key, None) is not None:
return_value[key] = return_value[key] + to_add[key]
del to_add[key]
......@@ -127,12 +125,7 @@ def addToDate(date, to_add=None, **kw):
if local_key not in ('day', 'year'):
treatPositiveValues(return_value, local_key)
day_to_add = min(
return_value['day'],
getNumberOfDayInMonth(
DateTime(return_value['year'], int(return_value['month']), 1)
)
) - 1
day_to_add = return_value['day'] - 1
if to_add.get('day', None) is not None:
day_to_add += to_add['day']
return_value['day'] = 1
......
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