*** Doc/lib/libdatetime.tex.orig 2005-02-01 20:30:39.000000000 -0500 --- Doc/lib/libdatetime.tex 2005-02-01 20:36:18.000000000 -0500 *************** *** 320,325 **** --- 320,334 ---- \var{d}}. \end{methoddesc} + \begin{methoddesc}{strptime}{date_string, format} + Return a \class{date} corresponding to \var{date_string}, parsed + according to \var{format}. This is equivalent to + \code{date(*(time.strptime(date_string, + format)[0:3]))}. \exception{ValueError} is raised if the date_string and + format can't be parsed by \function{time.strptime()}, if it returns a + value which isn't a time tuple, or if the time part is nonzero. + \end{methoddesc} + Class attributes: \begin{memberdesc}{min} *************** *** 998,1003 **** --- 1007,1023 ---- \var{tzinfo}, which defaults to \constant{None}. \end{classdesc} + Other constructors, all class methods: + + \begin{methoddesc}{strptime}{date_string, format} + Return a \class{time} corresponding to \var{date_string}, parsed + according to \var{format}. This is equivalent to + \code{time(*(time.strptime(date_string, + format)[4:6]))}. \exception{ValueError} is raised if the date_string and + format can't be parsed by \function{time.strptime()}, if it returns a + value which isn't a time tuple, or if the date part is nonzero. + \end{methoddesc} + Class attributes: \begin{memberdesc}{min} *** Modules/datetimemodule.c.orig 2005-02-01 19:55:36.000000000 -0500 --- Modules/datetimemodule.c 2005-02-01 23:31:15.274132000 -0500 *************** *** 2319,2324 **** --- 2319,2347 ---- return result; } + /* Return new date from time.strptime(). */ + static PyObject * + date_strptime(PyObject *cls, PyObject *args) + { + PyObject *date = NULL; + PyObject *datetime = (PyObject *)datetime_strptime(&PyDateTime_DateTimeType, args); + + if (datetime == NULL) + return NULL; + + if (DATE_GET_HOUR(datetime) + || DATE_GET_MINUTE(datetime) + || DATE_GET_SECOND(datetime) + || DATE_GET_MICROSECOND(datetime)) + PyErr_SetString(PyExc_ValueError, "date.strptime mustn't parse time"); + else + date = datetime_getdate(datetime); + + Py_DECREF(datetime); + + return date; + } + /* * Date arithmetic. */ *************** *** 2619,2624 **** --- 2642,2652 ---- PyDoc_STR("Current date or datetime: same as " "self.__class__.fromtimestamp(time.time()).")}, + {"strptime", (PyCFunction)date_strptime, + METH_VARARGS | METH_CLASS, + PyDoc_STR("string, format -> new date parsed from a string " + "(like time.strptime()).")}, + /* Instance methods: */ {"ctime", (PyCFunction)date_ctime, METH_NOARGS, *************** *** 3088,3093 **** --- 3116,3149 ---- return self; } + /* Return new time from time.strptime(). */ + static PyObject * + time_strptime(PyObject *cls, PyObject *args) + { + PyObject *time = NULL; + PyObject *datetime = (PyObject *)datetime_strptime(&PyDateTime_DateTimeType, args); + + if (datetime == NULL) + return NULL; + + PyObject *emptyString = PyString_FromString(""); + PyObject *emptyStringPair = PyTuple_Pack(2, emptyString, emptyString); + PyObject *emptyDatetime = (PyObject *)datetime_strptime(&PyDateTime_DateTimeType, emptyStringPair); + if (GET_YEAR(datetime) != GET_YEAR(emptyDatetime) + || GET_MONTH(datetime) != GET_MONTH(emptyDatetime) + || GET_DAY(datetime) != GET_DAY(emptyDatetime)) + PyErr_SetString(PyExc_ValueError, "time.strptime mustn't parse date"); + else + time = datetime_gettime(datetime); + + Py_DECREF(emptyDatetime); + Py_DECREF(emptyStringPair); + Py_DECREF(emptyString); + Py_DECREF(datetime); + + return time; + } + /* * Destructor. */ *************** *** 3405,3410 **** --- 3461,3475 ---- static PyMethodDef time_methods[] = { + /* Class methods: */ + + {"strptime", (PyCFunction)time_strptime, + METH_VARARGS | METH_CLASS, + PyDoc_STR("string, format -> new time parsed from a string " + "(like time.strptime()).")}, + + /* Instance methods: */ + {"isoformat", (PyCFunction)time_isoformat, METH_KEYWORDS, PyDoc_STR("Return string in ISO 8601 format, HH:MM:SS[.mmmmmm]" "[+HH:MM].")},