Code

Opened 3 years ago

Closed 17 months ago

#16888 closed Bug (fixed)

USE_L10N and microseconds

Reported by: anonymous Owned by: claudep
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: hv@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

I have a problem when I'm using "USE_L10N = True" and "DateTimeField" eg in auth.User model.
I can't save the form, because it contains field "last_login" with the time including microseconds. These are defined in DATETIME_INPUT_FORMATS, but only in global_settings.py, not in the formats directory.

django.conf.global_settings:

DATETIME_INPUT_FORMATS = (
    '%Y-%m-%d %H:%M:%S',
    '%Y-%m-%d %H:%M:%S.%f',  # OKAY
    ...
}

django.conf.locale.en.formats:

DATETIME_INPUT_FORMATS = (
    '%d.%m.%Y %H:%M:%S',
    '%d.%m.%Y %H:%M',       # '25.10.2006 14:30'
    '%d.%m.%Y',             # '25.10.2006'
    '%Y-%m-%d %H:%M:%S',    # '2006-10-25 14:30:59'
    '%Y-%m-%d %H:%M',       # '2006-10-25 14:30'
    '%Y-%m-%d',             # '2006-10-25'
)

Here is ".%f" missing.

Now I have my own formats directory, where I add the ".%f" to the locales ​what needs my application. But I think it's not very elegant solution.

Thank you
Ross

Attachments (0)

Change History (5)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This problem probably affects most of the 33 locales that define their own DATETIME_INPUT_FORMATS.

Note that %f only exists since Python 2.6, but there's a hack in django.forms.fields.BaseTemporalField.to_python to support format strings ending in %f.

comment:2 Changed 2 years ago by guettli

  • Cc hv@… added

comment:3 Changed 2 years ago by guettli

Django 1.5 will drop support for Python 2.5. This means that the current development version of django can safely use %f to parse microseconds. I think '%Y-%m-%d %H:%M:%S.%f' should be in the DATETIME_INPUT_FORMATS list of every language, since a hidden datetime input field should not loose microseconds.

Last edited 2 years ago by guettli (previous) (diff)

comment:4 Changed 17 months ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from new to assigned

comment:5 Changed 17 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 21722702c8ca85895d245ce2967e7336a168585d:

Fixed #16888 -- Added microseconds in localized input formats

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.