Refs #30803 -- Allowed comma separators for decimal fractions in parse_duration().
This commit is contained in:
parent
cab3661832
commit
42b23d1e79
|
@ -137,11 +137,11 @@ def parse_duration(value):
|
|||
)
|
||||
if match:
|
||||
kw = match.groupdict()
|
||||
days = datetime.timedelta(float(kw.pop('days', 0) or 0))
|
||||
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 kw.items() if v is not None}
|
||||
kw = {k: float(v.replace(',', '.')) for k, v in kw.items() if v is not None}
|
||||
days = datetime.timedelta(kw.pop('days', .0) or .0)
|
||||
return days + sign * datetime.timedelta(**kw)
|
||||
|
|
|
@ -154,6 +154,11 @@ The functions defined in this module share the following properties:
|
|||
8601 (e.g. ``P4DT1H15M20S`` which is equivalent to ``4 1:15:20``) or
|
||||
PostgreSQL's day-time interval format (e.g. ``3 days 04:05:06``).
|
||||
|
||||
.. versionchanged:: 3.1
|
||||
|
||||
Support for comma separators for decimal fractions in the ISO 8601
|
||||
format was added.
|
||||
|
||||
``django.utils.decorators``
|
||||
===========================
|
||||
|
||||
|
|
|
@ -256,6 +256,9 @@ Utilities
|
|||
* :func:`~django.utils.encoding.filepath_to_uri` now supports
|
||||
:class:`pathlib.Path`.
|
||||
|
||||
* :func:`~django.utils.dateparse.parse_duration` now supports comma separators
|
||||
for decimal fractions in the ISO 8601 format.
|
||||
|
||||
Validators
|
||||
~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -131,10 +131,12 @@ class DurationParseTests(unittest.TestCase):
|
|||
('P4W', None),
|
||||
('P4D', timedelta(days=4)),
|
||||
('P0.5D', timedelta(hours=12)),
|
||||
('P0,5D', timedelta(hours=12)),
|
||||
('PT5H', timedelta(hours=5)),
|
||||
('PT5M', timedelta(minutes=5)),
|
||||
('PT5S', timedelta(seconds=5)),
|
||||
('PT0.000005S', timedelta(microseconds=5)),
|
||||
('PT0,000005S', timedelta(microseconds=5)),
|
||||
)
|
||||
for source, expected in test_values:
|
||||
with self.subTest(source=source):
|
||||
|
|
Loading…
Reference in New Issue