diff options
| author | Will Hardy <Will.Hardy@thermondo.de> | 2016-05-26 14:48:36 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-07-14 13:34:15 -0400 |
| commit | 8ef78b81654ebcf19a1fc241e2b1ede35100096b (patch) | |
| tree | 67baaa077b5ed4530330a2202b5d3906708690b3 /django/utils/dateparse.py | |
| parent | a7b5dfd1703a8fbed70b7aca5e6dda092af51154 (diff) | |
Fixed #26656 -- Added duration (timedelta) support to DjangoJSONEncoder.
Diffstat (limited to 'django/utils/dateparse.py')
| -rw-r--r-- | django/utils/dateparse.py | 6 |
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) |
