Bug in time module?
Gordon McMillan
gmcm at hypernet.com
Wed Sep 8 14:06:08 EDT 1999
lec wrote:
> Gordon McMillan wrote:
>
> >
> > The only editing Python's time module does is to ensure that you've
> > passed the right number and kind of args. Everything else is the
> > result of your platform's implementation of strptime. If you want
> > something _good_, you should probably use MA Lemburg's mxDateTime.
> >
> > - Gordon
>
> Consider the following exception raised:
>
> Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201
> (egcs-1.1.1 on linux2 Copyright 1991-1995 Stichting Mathematisch
> Centrum, Amsterdam
> >>> import time
> >>> time.strptime('31/13/1999', "%d/%m/%Y")
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> ValueError: format mismatch
>
> Shouldn't the same exception be raised for
> time.strptime('31/02/1999', "%d/%m/%Y") ?
"Should / shouldn't" is a very different question from "why".
Consider the following:
static PyObject *
time_strptime(self, args)
PyObject *self;
PyObject *args;
{
struct tm tm;
char *fmt = "%a %b %d %H:%M:%S %Y";
char *buf;
char *s;
if (!PyArg_ParseTuple(args, "s|s", &buf, &fmt)) {
PyErr_SetString(PyExc_ValueError, "invalid argument");
return NULL;
}
memset((ANY *) &tm, '\0', sizeof(tm));
s = strptime(buf, fmt, &tm);
if (s == NULL) {
PyErr_SetString(PyExc_ValueError, "format mismatch");
return NULL;
}
while (*s && isspace(*s))
s++;
if (*s) {
PyErr_Format(PyExc_ValueError,
"unconverted data remains: '%.400s'", s);
return NULL;
}
return tmtotuple(&tm);
Do you see any Python edits of values there?
Consider the following:
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>
import time >>> time.strptime('31/13/1999', '%d/%m/%Y') Traceback
(innermost last):
File "<stdin>", line 1, in ?
AttributeError: strptime
No strptime in Windows c runtime.
I leave the "should" question untouched.
- Gordon
More information about the Python-list
mailing list