-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not Correctly Handling Timezone Aware Times #24
Comments
I don't know off the top of my head, but I believe I added added in special date time handing here as, at the time, DRF was incapable of correctly parsing ISO 8601 formatted times.
|
@cancan101 You may want to investigate here: https://github.com/philipn/django-rest-framework-filters/blob/master/rest_framework_filters/filters.py#L12 We may simply want to remove these definitions, as it appears DRF fixes this issue in its 3.0 release? |
I think it's actually Django which handles the datetime parsing: https://github.com/django/django/blob/0ed7d155635da9f79d4dd67e4889087d3673c6da/django/utils/dateparse.py#L84-L109 |
Something like this (perhaps with a check to see if class DateTimeFormFieldFixed(forms.DateTimeField):
def to_python(self, value):
try:
return super(DateTimeFormFieldFixed, self).to_python(value)
except ValidationError as ex:
if ex.code != 'invalid':
raise
try:
result = parse_datetime(value)
except ValueError:
raise ValidationError(self.error_messages['invalid'], code='invalid')
if result is None:
raise
return from_current_timezone(result)
class DateTimeFilterFixed(DateTimeFilter):
field_class = DateTimeFormFieldFixed |
Fix timezone-aware datetime handling (#24)
This datetime does not seem to parse correctly:
2010-1-2T23:18:23.861723Z
even though DRF handles the format.See also: http://www.django-rest-framework.org/api-guide/fields/#datetimefield
The text was updated successfully, but these errors were encountered: