mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #28076 -- Added support for PostgreSQL's interval format to parse_duration().
This commit is contained in:
committed by
Tim Graham
parent
684c0a35f6
commit
493f7e9e1e
@@ -65,6 +65,21 @@ class DurationParseTests(unittest.TestCase):
|
||||
with self.subTest(delta=delta):
|
||||
self.assertEqual(parse_duration(format(delta)), delta)
|
||||
|
||||
def test_parse_postgresql_format(self):
|
||||
test_values = (
|
||||
('1 day', timedelta(1)),
|
||||
('1 day 0:00:01', timedelta(days=1, seconds=1)),
|
||||
('1 day -0:00:01', timedelta(days=1, seconds=-1)),
|
||||
('-1 day -0:00:01', timedelta(days=-1, seconds=-1)),
|
||||
('-1 day +0:00:01', timedelta(days=-1, seconds=1)),
|
||||
('4 days 0:15:30.1', timedelta(days=4, minutes=15, seconds=30, milliseconds=100)),
|
||||
('4 days 0:15:30.0001', timedelta(days=4, minutes=15, seconds=30, microseconds=100)),
|
||||
('-4 days -15:00:30', timedelta(days=-4, hours=-15, seconds=-30)),
|
||||
)
|
||||
for source, expected in test_values:
|
||||
with self.subTest(source=source):
|
||||
self.assertEqual(parse_duration(source), expected)
|
||||
|
||||
def test_seconds(self):
|
||||
self.assertEqual(parse_duration('30'), timedelta(seconds=30))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user