[Python-bugs-list] [Bug #115146] time.strptime returns bad day of month

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Sep 2000 21:39:59 -0700


Bug #115146, was updated on 2000-Sep-22 15:39
Here is a current snapshot of the bug.

Project: Python
Category: Modules
Status: Closed
Resolution: Later
Bug Group: 3rd Party
Priority: 5
Summary: time.strptime returns bad day of month

Details: Python 1.5.2 (#1, May  9 2000, 15:05:56)  [GCC 2.95.3 19991030 (prerelease)] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import time
>>> time.strptime("00:00","%M:%S")
(1900, 1, 0, 0, 0, 0, 6, 1, 0)

According to documentation (Beazley, "Python Essential Reference" p172), strptime "returns a time tuple of the same form as returned by localtime() or gmtime()." Documentation for gmtime() (ibid, pp170-1) states that the valid range for day is 1-31. I suspect someone's either used to the POSIX strftime, or there's an off-by-one error.


Q #1: Why 1900? Why not assume epoch unless told otherwise?

Q #2: If you're assuming things, why not assume day-of-month as 1, not 0? According

Follow-Ups:

Date: 2000-Sep-22 17:20
By: tim_one

Comment:
Marked 3rdParty and assigned to Fred.

The function time_strptime in Python's timemodule.c simply calls the platform strptime function, and converts the result to a tuple.  Virtually all bugs claimed in it so far have been traced to the platform's implementation of strptime.

In particular, since Python passes on the day value untouched, it's clearly a bug in your version of libc that you're getting a 0 value.  As to the 1900, that's how a struct tm is defined to work, but again it's almost certainly your platform strptime screwing up in not setting that field to 70.

Unfortunately, since strptime is not defined by the ANSI/ISO C std, results in endcases do vary across platforms.
-------------------------------------------------------

Date: 2000-Sep-22 21:39
By: fdrake

Comment:
Added some warnings to the strptime() documentation about the vagaries of the return value based on Tim's comments and the Linux manpage for strptime().  Checked in as Doc/lib/libtime.tex revision 1.34.

Closed this and added a request for a portable (& working!) strptime() implementation to PEP 42.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=115146&group_id=5470