Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#13619 closed (invalid)

Accepting AM/ PM Time Formats

Reported by: Tom Clancy Owned by: nobody
Component: Forms Version: 1.1
Severity: Keywords:
Cc: tclancy@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a form with two TimeFields. Because I want to accept "AM" and "PM, I've set the input_formats to ['%H:%M%p', '%H:%M %p', '%H:%M']. While this passes the validator, time.strftime() (as of Python 2.5 anyway) doesn't seem to differentiate between "AM" and "PM", it just lops it off and treats both as an AM value. While I realize this is an issue with the underlying Python code and that there are internationalization concerns, can the TimeField/ DateTimeField be updated to add 12 hours to any string with "PM" in it? Maybe as an optional argument to init? I'm happy to take a crack at it if this is worth pursuing.

You can see the full tale of my struggle (with code) here. Apologies if this is covered in full elsewhere or a dumb question, but I couldn't see if 1.2 fixes this.

Change History (2)

comment:1 by Karen Tracey, 14 years ago

Resolution: invalid
Status: newclosed

You need to use %I to parse the hours when you also want to accept %p. See Note 1 under the table here: http://docs.python.org/library/time.html#time.strftime. This should be fixed by providing correct input formats, not by putting a hack into Django.

comment:2 by Tom Clancy, 14 years ago

Ah, thanks. I knew I was missing something.

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