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
0788dad0
Commit
0788dad0
authored
Sep 09, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some docstrings and other things to make pylint happier.
parent
b1a99d64
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
17 deletions
+29
-17
RelativeDate.py
RelativeDate.py
+29
-17
No files found.
RelativeDate.py
View file @
0788dad0
""" This module deals with relative dates (2d, 5y, Monday, today, etc.) """
from
datetime
import
date
,
timedelta
import
re
def
_convert_pattern
(
p_length
,
p_period
):
def
_convert_pattern
(
p_length
,
p_periodunit
):
"""
Converts a pattern in the form [0-9][dwmy] and returns a date from today
with the period of time added to it.
"""
result
=
None
p_length
=
int
(
p_length
)
if
p_period
==
'd'
:
if
p_period
unit
==
'd'
:
result
=
date
.
today
()
+
timedelta
(
p_length
)
elif
p_period
==
'w'
:
elif
p_period
unit
==
'w'
:
result
=
date
.
today
()
+
timedelta
(
weeks
=
p_length
)
elif
p_period
==
'm'
:
elif
p_period
unit
==
'm'
:
# we'll consider a month to be 30 days
result
=
date
.
today
()
+
timedelta
(
30
*
p_length
)
elif
p_period
==
'y'
:
elif
p_period
unit
==
'y'
:
# we'll consider a year to be 365 days (yeah, I'm aware of leap years)
result
=
date
.
today
()
+
timedelta
(
365
*
p_length
)
return
result
def
_convert_weekday_pattern
(
p_weekday
):
"""
Converts a weekday name to an absolute date.
When today's day of the week is entered, it will return today and not next
week's.
"""
day_value
=
{
'mo'
:
0
,
'tu'
:
1
,
...
...
@@ -30,12 +42,12 @@ def _convert_weekday_pattern(p_weekday):
'su'
:
6
}
target
DayS
tring
=
p_weekday
[:
2
].
lower
()
target
Day
=
day_value
[
targetDayS
tring
]
target
_day_s
tring
=
p_weekday
[:
2
].
lower
()
target
_day
=
day_value
[
target_day_s
tring
]
day
=
date
.
today
().
weekday
()
shift
=
(
target
D
ay
-
day
)
%
7
shift
=
(
target
_d
ay
-
day
)
%
7
return
date
.
today
()
+
timedelta
(
shift
)
def
relative_date_to_date
(
p_date
):
...
...
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