Opened 16 years ago
Closed 5 years ago
#11385 closed New feature (fixed)
DateTimeField doesn't accept ISO 8601 formatted date string
Reported by: | Jani Tiainen | Owned by: | Claude Paroz |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | datetime orm format |
Cc: | bronger@…, W. Trevor King | 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
DateTimeField doesn't accept ISO 8601 formatted date string. Differene is that ISO format allows date and time separator to be capital T letter. (Format being YYYY-MM-DDTHH:MM:SS. Django expects to have only space as a date and time separator.
Change History (11)
follow-up: 3 comment:1 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
I think the problem can't be resolved with DATETIME_INPUT_FORMATS tweaking.
ISO8601 format allows timezone info: '2010-09-01T19:52:15+04:00'. Such strings can't be parsed with python's strptime because python's strptime doesn't support '%z' format char (http://bugs.python.org/issue6641). So DATETIME_INPUT_FORMATS directive is not helpful for ISO8601 handling.
The solution is probably to use custom form field.
comment:3 by , 9 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
Replying to russellm:
ISO8601 is a good machine format, but not a particularly nice human readable format. Form processing is primarily about human-readable input.
If you disagree, the DateTimeField input formats are configurable (DATETIME_INPUT_FORMATS), so you can add ISO8601 format in your own projects if you want.
Hi Russell,
I understand your reasoning at the time this was closed for not supporting the T separator. However, this is not relevant again because of the way HTML5 provides the new Input Types. By default, using the datetime-local Input Type results in the format of YYYY-MM-DDTHH:MM. It would definitely make it nice to allow for that Input Type default to work properly with DateTimeField.
comment:4 by , 9 years ago
Component: | Database layer (models, ORM) → Forms |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → New feature |
Version: | 1.0 → master |
Reopening, considering comment:3, Python issue 6641 being fixed on Python 3 and the presence of django.utils.formats.ISO_INPUT_FORMATS
.
comment:6 by , 9 years ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
comment:7 by , 8 years ago
As kmike mentioned above, customizing the form field with an input_formats
containing the timezone marker %z
doesn't help — at least on Python 2.7. For anyone hitting this, I worked around it by using a custom form field and overriding the strptime
method:
from django.utils.dateparse import parse_datetime from django.utils.encoding import force_str class ISODateTimeField(forms.DateTimeField): def strptime(self, value, format): return parse_datetime(force_str(value))
I use Django's own parse_datetime
utility. Note this is limited to ISO datetimes, and effectively any input_formats
are omitted.
comment:8 by , 7 years ago
Cc: | added |
---|
comment:9 by , 5 years ago
Has patch: | set |
---|
Interest for this is revived by the HTML5 <input type="datetime-local">
which is sending input formatted with ISO 8601.
comment:10 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
ISO8601 is a good machine format, but not a particularly nice human readable format. Form processing is primarily about human-readable input.
If you disagree, the DateTimeField input formats are configurable (DATETIME_INPUT_FORMATS), so you can add ISO8601 format in your own projects if you want.