Opened 3 years ago

Last modified 3 years ago

#32727 closed Bug

Support spaces separaters in ISO-8601 datetimes between times and timezone strings — at Initial Version

Reported by: Ben Wilber Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to ISO-8601, there can be any number of whitespace characters between the time strings and timezone strings.

Unfortunately the spec isn't public, but here's the link anyway https://www.iso.org/iso-8601-date-and-time-format.html.

Examples:

This is a valid ISO-8601 datetime string:

`
2012-04-23T10:20:30.400-02
`
Django's django.utils.dateparse.parse_datetime parses this correctly.

This is also a valid ISO-8601 datetime string:
`
2012-04-23T10:20:30.400 -02
`
Django's django.utils.dateparse.parse_datetime does not parse this correctly and returns None,

However, python-dateutil parses it correctly. The difference is that Django uses a very brittle REGEX to parse ISO-8601 datetime strings, and python-dateutil does not.

I would recommend that Django:

1) Depend on python-dateutil
2) Inline python-dateutils' parsing functions

As far as I know there is no regex that can parse the full spec of ISO-8601 datetime strings.

In the meantime, this is a patch to support (valid) whitespace characters between the seconds/millseconds part and the timezone string.

GitHub Pull Request: https://github.com/django/django/pull/14368

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top