mirror of https://github.com/django/django.git
Fixed #30141 -- Fixed parse_duration() for some negative durations.
This commit is contained in:
parent
36300ef336
commit
99fc5dc13c
|
@ -29,9 +29,10 @@ datetime_re = re.compile(
|
||||||
standard_duration_re = re.compile(
|
standard_duration_re = re.compile(
|
||||||
r'^'
|
r'^'
|
||||||
r'(?:(?P<days>-?\d+) (days?, )?)?'
|
r'(?:(?P<days>-?\d+) (days?, )?)?'
|
||||||
r'((?:(?P<hours>-?\d+):)(?=\d+:\d+))?'
|
r'(?P<sign>-?)'
|
||||||
r'(?:(?P<minutes>-?\d+):)?'
|
r'((?:(?P<hours>\d+):)(?=\d+:\d+))?'
|
||||||
r'(?P<seconds>-?\d+)'
|
r'(?:(?P<minutes>\d+):)?'
|
||||||
|
r'(?P<seconds>\d+)'
|
||||||
r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
|
r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
|
||||||
r'$'
|
r'$'
|
||||||
)
|
)
|
||||||
|
|
|
@ -113,9 +113,12 @@ class DurationParseTests(unittest.TestCase):
|
||||||
test_values = (
|
test_values = (
|
||||||
('-4 15:30', timedelta(days=-4, minutes=15, seconds=30)),
|
('-4 15:30', timedelta(days=-4, minutes=15, seconds=30)),
|
||||||
('-172800', timedelta(days=-2)),
|
('-172800', timedelta(days=-2)),
|
||||||
('-15:30', timedelta(minutes=-15, seconds=30)),
|
('-15:30', timedelta(minutes=-15, seconds=-30)),
|
||||||
('-1:15:30', timedelta(hours=-1, minutes=15, seconds=30)),
|
('-1:15:30', timedelta(hours=-1, minutes=-15, seconds=-30)),
|
||||||
('-30.1', timedelta(seconds=-30, milliseconds=-100)),
|
('-30.1', timedelta(seconds=-30, milliseconds=-100)),
|
||||||
|
('-00:01:01', timedelta(minutes=-1, seconds=-1)),
|
||||||
|
('-01:01', timedelta(seconds=-61)),
|
||||||
|
('-01:-01', None),
|
||||||
)
|
)
|
||||||
for source, expected in test_values:
|
for source, expected in test_values:
|
||||||
with self.subTest(source=source):
|
with self.subTest(source=source):
|
||||||
|
|
Loading…
Reference in New Issue