#13486 closed (fixed)
TIME_INPUT_FORMATS %P doesn't work
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | 1.2-beta |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In settings I put
TIME_INPUT_FORMATS = ('%I:%M %P',)
Which should display times like 8:30 PM
It displays times fine but on saving it raises validation errors. Also when hitting the "now" button in the admin interface it displays what should be PM or AM as undefined. I'm running 1.2 RC 1
Change History (8)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
I am not sure %P is supposed to work as an input format. Doc here: http://docs.djangoproject.com/en/dev/ref/settings/#time-input-formats notes that "these format strings are specified in Python's datetime module syntax, that is different from the one used by Django for formatting dates to be displayed". I don't see, %P listed in the Python datetime table here: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior, just %p.
However I do see a problem in attempting to use the input format "I%:%M %p". When I click "Now" in the admin, or select Now from the "Choose a time" dropdown, I get the time in GMT, that is 4 hours ahead of my local time. Using the default input formats clicking either of these Now options gives me now in local time.
comment:3 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
%P isn't a valid formatting character, %p is. Hence the failure. Closing invalid.
As for Karen's reported problem: I couldn't reproduce this, and speaking with Karen on IRC, she couldn't reproduce her earlier failure.
comment:4 by , 14 years ago
Hmm I was looking at the times I get when clicking "now".
At 2:21 PM when I click "now" I get 10:21 PM. Strange.
Here is from my settings
TIME_ZONE = 'America/New York'
TIME_INPUT_FORMATS = ('%I:%M %p',)
My computer is in the same time zone. Now when I delete TIME_INPUT_FORMATS It displays correctly, although in 24 hour time. Could this be a bug?
Here are the other settings I get from clicking on the admin widget
Midnight: 00:00 AM Shouldn't it be 12:00 AM Python Doc says for %I "Hour (12-hour clock) as a decimal number [01,12]." so 00 should never come up right?
- a.m. is correct
noon is correct as 12:00 PM
comment:5 by , 14 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
The "Now" problem is caused by Date.prototype.getTwelveHours in core.js. The formula for converting a 24-hour time to a 12-hour time, provided it's 1 pm or later, is the 24-hour time minus 12 hours, i.e.
Date.prototype.getTwelveHours = function() { return (this.getHours() <= 12) ? this.getHours() : this.getHours() - 12; }
Currently, we have:
Date.prototype.getTwelveHours = function() { return (this.getHours() <= 12) ? this.getHours() : 24 - this.getHours(); }
Also, getHours() returns a value from 0-23, so we should consider checking for zero and replacing it with twelve. I couldn't think of a clever way to do this, though; nested inline conditionals seem ugly to me.
comment:6 by , 14 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:7 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Oh just a note and workaround it only seems to effect %P not %p so this works fine
('%I:%M %p',)