Phillip gives a rundown on the various modules which deal with dates and times in Python.
I personally use the mxDateTime module. It has really helped out quite a bit.
Posted by Josh at May 26, 2003 11:45 PM | TrackBackI'd been using mx.DateTime for a while until I ran into this
bug. The author has not responded to my report.
>>> import mx.DateTime
>>> mx.DateTime.DateTimeFrom("12:00 pm")
Traceback (most recent call last):
File "", line 1, in ?
File "/usr/lib/python2.2/site-packages/mx/DateTime/DateTime.py", line 219, in DateTimeFrom
return Parser.DateTimeFromString(arg)
File "/usr/lib/python2.2/site-packages/mx/DateTime/Parser.py", line 567, in DateTimeFromString
raise DateTime.RangeError,\
mx.DateTime.RangeError: Failed to parse "12:00 pm": hour out of range (0-23): 24
Lee -
I don't think mx likes the 'pm.' If you just pass in "12:00" all is well.
It looks like it will parse a 24-hour string so you won't need am/pm.
Hope this helps.
Posted by: Josh on May 28, 2003 09:48 AMI know how to get around it. The point is that this package is supposed to be useful for parsing dates that might be in an unpredictable format, and claims to be flexible enough to deal with dates that use "am" and "pm". And it works in most cases:
>>> mx.DateTime.DateTimeFrom("1:30 pm")
<DateTime object for '2003-05-29 13:30:00.00' at 169920>
>>> mx.DateTime.DateTimeFrom("1:30 am")
<DateTime object for '2003-05-29 01:30:00.00' at 186660>
The fact that it fails only for 12:xx pm is obviously a bug (probably in Parser.py). I should find the time to go in there and fix it - I'm just being lazy and hoping that someone else does it first.
Ah, I misunderstood.
Yeah, that definitely is a bug and I'm surprised it is still there. You'd think it would have been noticed before.
Posted by: Josh on May 29, 2003 09:51 AMI just got a reply to my bug report to the author. He says that he knows about this bug and that it is fixed in an "upcoming" version 2.1. So I can go back to being lazy and waiting until it gets fixed.
Posted by: Lee Phillips on June 3, 2003 11:22 AM