[Python-Dev] Broken strptime in Python 2.3a1 & CVS

Kevin Jacobs jacobs@penguin.theopalgroup.com
Wed, 8 Jan 2003 19:44:52 -0500 (EST)


On Wed, 8 Jan 2003, Brett Cannon wrote:
> i.e., here is an exerpt from
> > the mktime man page on my linux system on how the values in a time-tuple are
> > interpreted:
> >
> >      The  mktime() function converts a broken-down time structure, expressed
> >      as local time, to calendar time representation.  The function ignores
> >      the specified contents of the structure members tm_wday and tm_yday and
> >      recomputes them from the other information in the broken-down time
> >      structure.  If structure members are outside their legal interval, they
> >      will be normalized (so that, e.g., 40 October is changed into 9 Novem-
> >      ber).
> >
> > Thus, mktime correctly returns a time-from-epoch that is 1 hour, 1 minute,
> > and 1 second (3661 seconds) behind where it should be (unless it is DST).
> 
> How lovely.  OK, so I am up for suggestions.  I mean I could return
> default values that are within the acceptable range (one-line change since
> I just initialize the list I use to store values with default values of -1
> as it is), but I don't want to mislead users into thinking that the values
> were extracted from the data string.  Does obviousness come before or
> after following a spec?  Would setting default values within range but to
> their minimum value (so if the month is not known, set it to 1 for Jan
> instead of -1) solve your problem, Kevin?

No, -1 is the appropriate missing value for months, days, and years.  

e.g.:
print time.strptime('12:22:23', '%H:%M:%S') # libc's strptime
> (-1, -1, -1, 12, 22, 23, -1, -1, -1)

All of your questions about what should be returned will be answered (in
great detail) by the various standard that define strptime.  Most UNIX
system man pages provide fairly good definitions for how strptime should
work.  It would also be wise to built a test suite that you can use to
validate your strptime implementation against the libc strptime
implementations (like I did for the one case that I posted).  That way you
can eventually use your strptime to detect problems in platform strptime
implementations, though that will have to wait until your version has been
validated to conform very strictly.

I am very greatful for the effort you put in to your strptime implementation
and hope that it won't be too inconvenient to go this last mile.

Thanks,
-Kevin

--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19         E-mail: jacobs@theopalgroup.com
Fax:   (216) 986-0714              WWW:    http://www.theopalgroup.com