summaryrefslogtreecommitdiff
path: root/django/utils/dateparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils/dateparse.py')
-rw-r--r--django/utils/dateparse.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py
index 30a96f818e..c3d7eb06b9 100644
--- a/django/utils/dateparse.py
+++ b/django/utils/dateparse.py
@@ -40,7 +40,8 @@ standard_duration_re = re.compile(
# Support the sections of ISO 8601 date representation that are accepted by
# timedelta
iso8601_duration_re = re.compile(
- r'^P'
+ r'^(?P<sign>[-+]?)'
+ r'P'
r'(?:(?P<days>\d+(.\d+)?)D)?'
r'(?:T'
r'(?:(?P<hours>\d+(.\d+)?)H)?'
@@ -121,7 +122,8 @@ def parse_duration(value):
match = iso8601_duration_re.match(value)
if match:
kw = match.groupdict()
+ sign = -1 if kw.pop('sign', '+') == '-' else 1
if kw.get('microseconds'):
kw['microseconds'] = kw['microseconds'].ljust(6, '0')
kw = {k: float(v) for k, v in six.iteritems(kw) if v is not None}
- return datetime.timedelta(**kw)
+ return sign * datetime.timedelta(**kw)