diff options
| author | zauddelig <zauddelig@gmail.com> | 2015-06-02 11:08:41 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-02 12:42:31 -0400 |
| commit | 7f92b6e576daace8051785dc046aca00bdccfed4 (patch) | |
| tree | 48bfb39afe875b4987df89a902ecd8371fdaadf0 | |
| parent | 9d83de8ff3b835603fe09e8842529c9810bc1dcd (diff) | |
[1.8.x] Fixed #24897 -- Allowed using choices longer than 1 day with DurationField
Backport of 262d4db8c4c849b0fdd84550fb96472446cf90df from master
| -rw-r--r-- | django/utils/dateparse.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.8.3.txt | 3 | ||||
| -rw-r--r-- | tests/utils_tests/test_dateparse.py | 14 |
3 files changed, 18 insertions, 1 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index a3c760e8fb..30a96f818e 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -29,7 +29,7 @@ datetime_re = re.compile( standard_duration_re = re.compile( r'^' - r'(?:(?P<days>-?\d+) )?' + r'(?:(?P<days>-?\d+) (days?, )?)?' r'((?:(?P<hours>\d+):)(?=\d+:\d+))?' r'(?:(?P<minutes>\d+):)?' r'(?P<seconds>\d+)' diff --git a/docs/releases/1.8.3.txt b/docs/releases/1.8.3.txt index 78e6766872..2761f06271 100644 --- a/docs/releases/1.8.3.txt +++ b/docs/releases/1.8.3.txt @@ -40,3 +40,6 @@ Bugfixes * Fixed queryset pickling when using ``prefetch_related()`` after deleting objects (:ticket:`24831`). + +* Allowed using ``choices`` longer than 1 day with ``DurationField`` + (:ticket:`24897`). diff --git a/tests/utils_tests/test_dateparse.py b/tests/utils_tests/test_dateparse.py index 7d4767feb7..1a1111df21 100644 --- a/tests/utils_tests/test_dateparse.py +++ b/tests/utils_tests/test_dateparse.py @@ -51,6 +51,20 @@ class DateParseTests(unittest.TestCase): class DurationParseTests(unittest.TestCase): + + def test_parse_python_format(self): + timedeltas = [ + timedelta(days=4, minutes=15, seconds=30, milliseconds=100), # fractions of seconds + timedelta(hours=10, minutes=15, seconds=30), # hours, minutes, seconds + timedelta(days=4, minutes=15, seconds=30), # multiple days + timedelta(days=1, minutes=00, seconds=00), # single day + timedelta(days=-4, minutes=15, seconds=30), # negative durations + timedelta(minutes=15, seconds=30), # minute & seconds + timedelta(seconds=30), # seconds + ] + for delta in timedeltas: + self.assertEqual(parse_duration(format(delta)), delta) + def test_seconds(self): self.assertEqual(parse_duration('30'), timedelta(seconds=30)) |
