Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
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
Kirill Smelkov
topydo
Commits
25dd79b5
Commit
25dd79b5
authored
Feb 21, 2016
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #115 from mruwek/business_days
Add recurrence and postponing by business days
parents
314b21a1
c02e997f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
3 deletions
+43
-3
test/test_relative_date.py
test/test_relative_date.py
+21
-1
topydo/lib/RelativeDate.py
topydo/lib/RelativeDate.py
+22
-2
No files found.
test/test_relative_date.py
View file @
25dd79b5
...
...
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
unittest
from
datetime
import
date
,
timedelta
from
datetime
import
date
from
freezegun
import
freeze_time
from
test.topydo_testcase
import
TopydoTest
...
...
@@ -40,6 +40,18 @@ class RelativeDateTester(TopydoTest):
result
=
relative_date_to_date
(
'1d'
)
self
.
assertEqual
(
result
,
self
.
tomorrow
)
def
test_zero_bdays
(
self
):
result
=
relative_date_to_date
(
'0b'
)
self
.
assertEqual
(
result
,
self
.
today
)
def
test_one_bday
(
self
):
result
=
relative_date_to_date
(
'1b'
)
self
.
assertEqual
(
result
,
self
.
monday
)
def
test_one_bweek
(
self
):
result
=
relative_date_to_date
(
'5b'
)
self
.
assertEqual
(
result
,
self
.
friday
)
def
test_one_week
(
self
):
result
=
relative_date_to_date
(
'1w'
)
self
.
assertEqual
(
result
,
date
(
2015
,
11
,
13
))
...
...
@@ -152,6 +164,14 @@ class RelativeDateTester(TopydoTest):
result
=
relative_date_to_date
(
'-0d'
)
self
.
assertTrue
(
result
,
self
.
today
)
def
test_negative_period3
(
self
):
result
=
relative_date_to_date
(
'-1b'
)
self
.
assertEqual
(
result
,
date
(
2015
,
11
,
5
))
def
test_negative_period4
(
self
):
result
=
relative_date_to_date
(
'-5b'
)
self
.
assertEqual
(
result
,
date
(
2015
,
10
,
30
))
def
test_weekday_next_week
(
self
):
"""
When entering "Friday" on a Friday, return next week Friday instead of
...
...
topydo/lib/RelativeDate.py
View file @
25dd79b5
...
...
@@ -37,9 +37,26 @@ def _add_months(p_sourcedate, p_months):
return
date
(
year
,
month
,
day
)
def
_add_business_days
(
p_sourcedate
,
p_bdays
):
""" Adds a number of business days to the source date. """
result
=
p_sourcedate
delta
=
1
if
p_bdays
>
0
else
-
1
while
abs
(
p_bdays
)
>
0
:
result
+=
timedelta
(
delta
)
weekday
=
result
.
weekday
()
if
weekday
>=
5
:
continue
p_bdays
=
p_bdays
-
1
if
delta
>
0
else
p_bdays
+
1
return
result
def
_convert_pattern
(
p_length
,
p_periodunit
,
p_offset
=
None
):
"""
Converts a pattern in the form [0-9][dwmy] and returns a date from the
Converts a pattern in the form [0-9][dwmy
b
] and returns a date from the
offset with the period of time added to it.
"""
result
=
None
...
...
@@ -55,6 +72,8 @@ def _convert_pattern(p_length, p_periodunit, p_offset=None):
result
=
_add_months
(
p_offset
,
p_length
)
elif
p_periodunit
==
'y'
:
result
=
_add_months
(
p_offset
,
p_length
*
12
)
elif
p_periodunit
==
'b'
:
result
=
_add_business_days
(
p_offset
,
p_length
)
return
result
...
...
@@ -98,7 +117,8 @@ def relative_date_to_date(p_date, p_offset=None):
p_date
=
p_date
.
lower
()
p_offset
=
p_offset
or
date
.
today
()
relative
=
re
.
match
(
'(?P<length>-?[0-9]+)(?P<period>[dwmy])$'
,
p_date
,
re
.
I
)
relative
=
re
.
match
(
'(?P<length>-?[0-9]+)(?P<period>[dwmyb])$'
,
p_date
,
re
.
I
)
monday
=
'mo(n(day)?)?$'
tuesday
=
'tu(e(sday)?)?$'
...
...
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