From 7078afa42c1916823227287f6a6f60c104ebe3cd Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Sat, 14 Apr 2018 00:23:31 -0400 Subject: [PATCH] Change ISO 8601 date format to exclude year/month (#5936) --- rest_framework/utils/humanize_datetime.py | 2 +- tests/test_fields.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rest_framework/utils/humanize_datetime.py b/rest_framework/utils/humanize_datetime.py index 649f2abc6..48ef89547 100644 --- a/rest_framework/utils/humanize_datetime.py +++ b/rest_framework/utils/humanize_datetime.py @@ -13,7 +13,7 @@ def datetime_formats(formats): def date_formats(formats): - format = ', '.join(formats).replace(ISO_8601, 'YYYY[-MM[-DD]]') + format = ', '.join(formats).replace(ISO_8601, 'YYYY-MM-DD') return humanize_strptime(format) diff --git a/tests/test_fields.py b/tests/test_fields.py index eee794eaa..c5bf4fc66 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1122,8 +1122,10 @@ class TestDateField(FieldValues): datetime.date(2001, 1, 1): datetime.date(2001, 1, 1), } invalid_inputs = { - 'abc': ['Date has wrong format. Use one of these formats instead: YYYY[-MM[-DD]].'], - '2001-99-99': ['Date has wrong format. Use one of these formats instead: YYYY[-MM[-DD]].'], + 'abc': ['Date has wrong format. Use one of these formats instead: YYYY-MM-DD.'], + '2001-99-99': ['Date has wrong format. Use one of these formats instead: YYYY-MM-DD.'], + '2001-01': ['Date has wrong format. Use one of these formats instead: YYYY-MM-DD.'], + '2001': ['Date has wrong format. Use one of these formats instead: YYYY-MM-DD.'], datetime.datetime(2001, 1, 1, 12, 00): ['Expected a date but got a datetime.'], } outputs = {