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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Sep 2000 17:20:42 -0700


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

Project: Python
Category: Modules
Status: Open
Resolution: None
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.
-------------------------------------------------------

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