Skip to content
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

Closed
cancan101 opened this issue May 29, 2015 · 4 comments · Fixed by #31
Closed

Not Correctly Handling Timezone Aware Times #24

cancan101 opened this issue May 29, 2015 · 4 comments · Fixed by #31

Comments

@cancan101
Copy link

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

@philipn
Copy link
Owner

philipn commented May 30, 2015

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.

On May 29, 2015, at 4:29 PM, Alex Rothberg notifications@github.com wrote:

This datetime does not seem to parse correctly: 2010-1-2T23:18:23.861723Z even though DRF handles the format.


Reply to this email directly or view it on GitHub.

@philipn
Copy link
Owner

philipn commented May 30, 2015

@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?

@cancan101
Copy link
Author

I think it's actually Django which handles the datetime parsing: https://github.com/django/django/blob/0ed7d155635da9f79d4dd67e4889087d3673c6da/django/utils/dateparse.py#L84-L109

@cancan101
Copy link
Author

Something like this (perhaps with a check to see if 'iso-8601' is in api_settings.DATETIME_INPUT_FORMATS):

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

rpkilby pushed a commit to rpkilby/django-rest-framework-filters that referenced this issue Sep 14, 2015
philipn added a commit that referenced this issue Sep 16, 2015
Fix timezone-aware datetime handling (#24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants