Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13619 closed (invalid)

Accepting AM/ PM Time Formats

Reported by: tclancy 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: UI/UX:

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 Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 5 years ago by tclancy

Ah, thanks. I knew I was missing something.

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