summaryrefslogtreecommitdiff
path: root/django/utils/dateparse.py
diff options
context:
space:
mode:
authorJinank Jain <jinank94@gmail.com>2017-01-14 11:17:54 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-14 11:17:54 +0100
commitf4c0eec713a6ffe7616fdc5f4744b40110d4fed1 (patch)
treefe7b98e1b57bc3902293c19968443dc39d2e2c14 /django/utils/dateparse.py
parent8ade277ab1843306221d248c18648ffd1b950a31 (diff)
Fixed #27699 -- Added negative timedelta support to parse_duration()
Diffstat (limited to 'django/utils/dateparse.py')
-rw-r--r--django/utils/dateparse.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py
index c3d7eb06b9..b2020b5281 100644
--- a/django/utils/dateparse.py
+++ b/django/utils/dateparse.py
@@ -30,9 +30,9 @@ datetime_re = re.compile(
standard_duration_re = re.compile(
r'^'
r'(?:(?P<days>-?\d+) (days?, )?)?'
- r'((?:(?P<hours>\d+):)(?=\d+:\d+))?'
- r'(?:(?P<minutes>\d+):)?'
- r'(?P<seconds>\d+)'
+ r'((?:(?P<hours>-?\d+):)(?=\d+:\d+))?'
+ r'(?:(?P<minutes>-?\d+):)?'
+ r'(?P<seconds>-?\d+)'
r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
r'$'
)
@@ -125,5 +125,7 @@ def parse_duration(value):
sign = -1 if kw.pop('sign', '+') == '-' else 1
if kw.get('microseconds'):
kw['microseconds'] = kw['microseconds'].ljust(6, '0')
+ if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'):
+ kw['microseconds'] = '-' + kw['microseconds']
kw = {k: float(v) for k, v in six.iteritems(kw) if v is not None}
return sign * datetime.timedelta(**kw)