mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #28076 -- Added support for PostgreSQL's interval format to parse_duration().
This commit is contained in:
parent
684c0a35f6
commit
493f7e9e1e
3 changed files with 40 additions and 4 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue