Problems with strptime
scott
scott at chronis.pobox.com
Sun Oct 10 17:46:23 EDT 1999
On systems that have strptime as part of their C library (like SUSE), python
just uses that. I suspect that the problem is with the systems's strptime()
function, not python.
One thing that may cause breakage is the fact that all of your examples
start with 3 '0's in a row. You should try coding the same thing in C
and then see if that breaks. If it does, you should report the problem to
the maintainers of glibc, or try to fix it yourself.
1009 11:51 bort:~% python
Python 1.5.2 (#8, May 28 1999, 21:09:50) [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import time
>>> time.strptime("000311212045Z", '%y%m%d%H%M%SZ')
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: format mismatch
>>> time.strptime("010311212045Z", '%y%m%d%H%M%SZ')
(2010, 3, 11, 21, 20, 45, 6, 1, 0)
>>> time.strptime("100311212045Z", '%y%m%d%H%M%SZ')
(2010, 3, 11, 21, 20, 45, 6, 1, 0)
>>>
1010 17:34 bort:~% uname -a
Linux bort 2.0.36 #6 Fri Dec 18 12:18:39 EST 1998 i686 unknown
1010 17:35 bort:~%
yup, glibc is broke. I bet glibc uses atoi() which skips leading zeros
as if they aren't there in the first place. on the other hand:
1010 17:36 chronis:icg-work/icgmh% python
Python 1.5.2 (#2, Sep 22 1999, 15:46:56) [GCC 2.7.2.3] on freebsd3
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import time
>>> time.strptime("000311212045Z", '%y%m%d%H%M%SZ')
(2000, 3, 11, 21, 20, 45, 6, 1, 0)
>>> time.strptime("010311212045Z", '%y%m%d%H%M%SZ')
(2001, 3, 11, 21, 20, 45, 6, 1, 0)
>>> time.strptime("100311212045Z", '%y%m%d%H%M%SZ')
(2010, 3, 11, 21, 20, 45, 6, 1, 0)
>>>
010 17:37 chronis:icg-work/icgmh% uname -a # output broken up to fit lines
FreeBSD chronis.pobox.com 3.3-STABLE FreeBSD 3.3-STABLE #0:
Mon Sep 20 09:58:31 EDT 1999
root at chronis.pobox.com:/usr/src/sys/compile/MYBSD i386
1010 17:37 chronis:icg-work/icgmh%
But that's only 'cause I fixed strptime in FreeBSD's C library. Still waiting
for them to integrate the patch, though.
strptime-seems-broke-everywhere'ly yers
cott
On systems with strptime as part of the C libraryi
On Sun, 10 Oct 1999 15:24:22 +0200, Michael Strder
<michael.stroeder at inka.de> wrote:
>HI!
>
>I'm using time.strptime to parse several time-stamp strings like
>time.strptime('451014100704Z','%y%m%d%H%M%SZ') with year without
>century. This does not work in every case. Here's a list of time-strings
>which failed. I cannot see a reason or a pattern why this fails.
>
>***strptime failed 000311212045Z
>***strptime failed 000323170912Z
>***strptime failed 000325110134Z
>***strptime failed 000212090033Z
>***strptime failed 000311213753Z
>***strptime failed 000311212045Z
>***strptime failed 000323170912Z
>***strptime failed 000325110134Z
>***strptime failed 000311213753Z
>
>My system is: S.u.S.E.-Linux 6.2 based on glibc-2.1 with pre-installed
>Python 1.5.2.
>
>Ciao, Michael.
More information about the Python-list
mailing list