mxDateTime: does strptime not exist?
M.-A. Lemburg
mal at lemburg.com
Thu May 3 13:49:49 EDT 2001
Geoff Talvola wrote:
>
> At 06:57 PM 5/3/01 +0200, M.-A. Lemburg wrote:
> >Note that there's a much more elaborte date/time parser
> >available in mxDateTime though: the submodules Parser, ISO
> >and ARPA.
> >
> >These will do a pretty good job on a very wide range of
> >possible formats, e.g.
> >
> > >>> from mx.DateTime import *
> > >>> DateTimeFrom('09:49')
> ><DateTime object for '2001-05-03 09:49:00.00' at 8177198>
> > >>> DateTimeDeltaFrom('09:49')
> ><DateTimeDelta object for '09:49:00.00' at 816f058>
>
> The one gotcha I found is that it does the wrong thing for 12-hour time
> with an explicit "PM" (in version 2.0.0 of mxDateTime):
>
> >>> from mx import DateTime
> >>> DateTime.TimeFrom('5:34 PM')
> <DateTimeDelta object for '05:34:00.00' at 8415c0>
>
> But it does seem to be able to handle just about any date format I can
> think of.
>
> Any chance the time parser could be upgraded in the next version? In the
> meantime, it's not too painful to work around, for example:
>
> def TimeFromString(s):
> t = DateTime.TimeFrom(s)
> if s.lower().find('p') >= 0:
> t += DateTime.DateTimeDelta(0,12)
> return t
>
> >>> TimeFromString('5:34 PM')
> <DateTimeDelta object for '17:34:00.00' at 842fd0>
> >>> TimeFromString('5:34 AM')
> <DateTimeDelta object for '05:34:00.00' at 842500>
I'll put that on the TODO list for mxDateTime.
--
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/
More information about the Python-list
mailing list