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
Łukasz Nowak
erp5
Commits
1a80a583
Commit
1a80a583
authored
Oct 11, 2011
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
in getClosestDate(), if date is not passed, timezone of target_date should be respected.
parent
eff3f56d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
product/ERP5Type/DateUtils.py
product/ERP5Type/DateUtils.py
+3
-2
product/ERP5Type/tests/testDateUtils.py
product/ERP5Type/tests/testDateUtils.py
+15
-1
No files found.
product/ERP5Type/DateUtils.py
View file @
1a80a583
...
...
@@ -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
...
...
product/ERP5Type/tests/testDateUtils.py
View file @
1a80a583
...
...
@@ -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
))
...
...
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