Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5
Commits
c1dfe5d8
Commit
c1dfe5d8
authored
Apr 21, 2023
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Plain Diff
erp5_core: fix addToDate when removing a month
See merge request
!1768
parents
1b017c2c
34d26a74
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testDateUtils.py
...TemplateItem/portal_components/test.erp5.testDateUtils.py
+19
-0
product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.DateUtils.py
...ntTemplateItem/portal_components/module.erp5.DateUtils.py
+8
-1
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testDateUtils.py
View file @
c1dfe5d8
...
@@ -62,6 +62,17 @@ class TestDateUtils(unittest.TestCase):
...
@@ -62,6 +62,17 @@ class TestDateUtils(unittest.TestCase):
addToDate
(
date
,
month
=
90
).
toZone
(
'UTC'
).
ISO
())
addToDate
(
date
,
month
=
90
).
toZone
(
'UTC'
).
ISO
())
self
.
assertEqual
(
DateTime
(
'2090/01/01 %s'
%
self
.
timezone
).
toZone
(
'UTC'
).
ISO
(),
self
.
assertEqual
(
DateTime
(
'2090/01/01 %s'
%
self
.
timezone
).
toZone
(
'UTC'
).
ISO
(),
addToDate
(
date
,
year
=
90
).
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
):
def
test_negative_add_to_date
(
self
):
date
=
DateTime
(
'2000/01/01 %s'
%
self
.
timezone
)
date
=
DateTime
(
'2000/01/01 %s'
%
self
.
timezone
)
...
@@ -77,6 +88,14 @@ class TestDateUtils(unittest.TestCase):
...
@@ -77,6 +88,14 @@ class TestDateUtils(unittest.TestCase):
addToDate
(
date
,
month
=-
1
).
toZone
(
'UTC'
).
ISO
())
addToDate
(
date
,
month
=-
1
).
toZone
(
'UTC'
).
ISO
())
self
.
assertEqual
(
DateTime
(
'1999/01/01 %s'
%
self
.
timezone
).
toZone
(
'UTC'
).
ISO
(),
self
.
assertEqual
(
DateTime
(
'1999/01/01 %s'
%
self
.
timezone
).
toZone
(
'UTC'
).
ISO
(),
addToDate
(
date
,
year
=-
1
).
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
):
def
test_float_add_to_date
(
self
):
date
=
DateTime
(
'2000/01/01 %s'
%
self
.
timezone
)
date
=
DateTime
(
'2000/01/01 %s'
%
self
.
timezone
)
...
...
product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.DateUtils.py
View file @
c1dfe5d8
...
@@ -110,6 +110,8 @@ def addToDate(date, to_add=None, **kw):
...
@@ -110,6 +110,8 @@ def addToDate(date, to_add=None, **kw):
return_value
[
larger_key_dict
[
key
]]
=
return_value
[
larger_key_dict
[
key
]]
+
1
return_value
[
larger_key_dict
[
key
]]
=
return_value
[
larger_key_dict
[
key
]]
+
1
for
key
in
key_list
:
for
key
in
key_list
:
if
key
==
'day'
:
continue
if
to_add
.
get
(
key
,
None
)
is
not
None
:
if
to_add
.
get
(
key
,
None
)
is
not
None
:
return_value
[
key
]
=
return_value
[
key
]
+
to_add
[
key
]
return_value
[
key
]
=
return_value
[
key
]
+
to_add
[
key
]
del
to_add
[
key
]
del
to_add
[
key
]
...
@@ -125,7 +127,12 @@ def addToDate(date, to_add=None, **kw):
...
@@ -125,7 +127,12 @@ def addToDate(date, to_add=None, **kw):
if
local_key
not
in
(
'day'
,
'year'
):
if
local_key
not
in
(
'day'
,
'year'
):
treatPositiveValues
(
return_value
,
local_key
)
treatPositiveValues
(
return_value
,
local_key
)
day_to_add
=
return_value
[
'day'
]
-
1
day_to_add
=
min
(
return_value
[
'day'
],
getNumberOfDayInMonth
(
DateTime
(
return_value
[
'year'
],
int
(
return_value
[
'month'
]),
1
)
)
)
-
1
if
to_add
.
get
(
'day'
,
None
)
is
not
None
:
if
to_add
.
get
(
'day'
,
None
)
is
not
None
:
day_to_add
+=
to_add
[
'day'
]
day_to_add
+=
to_add
[
'day'
]
return_value
[
'day'
]
=
1
return_value
[
'day'
]
=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment