mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Introduce datetime_parser as class level attribute on all date/time fields. Refs #3093.
This commit is contained in:
parent
6ce9e3baf0
commit
c4f908d4ee
|
@ -954,6 +954,7 @@ class DateField(Field):
|
|||
}
|
||||
format = api_settings.DATE_FORMAT
|
||||
input_formats = api_settings.DATE_INPUT_FORMATS
|
||||
datetime_parser = datetime.datetime.strptime
|
||||
|
||||
def __init__(self, format=empty, input_formats=None, *args, **kwargs):
|
||||
self.format = format if format is not empty else self.format
|
||||
|
@ -978,7 +979,7 @@ class DateField(Field):
|
|||
return parsed
|
||||
else:
|
||||
try:
|
||||
parsed = datetime.datetime.strptime(value, format)
|
||||
parsed = self.datetime_parser(value, format)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
else:
|
||||
|
@ -1017,6 +1018,7 @@ class TimeField(Field):
|
|||
}
|
||||
format = api_settings.TIME_FORMAT
|
||||
input_formats = api_settings.TIME_INPUT_FORMATS
|
||||
datetime_parser = datetime.datetime.strptime
|
||||
|
||||
def __init__(self, format=empty, input_formats=None, *args, **kwargs):
|
||||
self.format = format if format is not empty else self.format
|
||||
|
@ -1038,7 +1040,7 @@ class TimeField(Field):
|
|||
return parsed
|
||||
else:
|
||||
try:
|
||||
parsed = datetime.datetime.strptime(value, format)
|
||||
parsed = self.datetime_parser(value, format)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user