aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hoffmann <2836374+timhoffm@users.noreply.github.com>2018-09-24 10:39:02 +0200
committerPetr Viktorin <encukou@gmail.com>2018-09-24 10:39:02 +0200
commita0fd7f1b55a1d76842fa2c6b5777a39cdcf2bb5e (patch)
treeea55a55e2e4be74e3a9ab1d9d281e7bca2a172dd /Modules/_datetimemodule.c
parentbpo-34659: Adds initial kwarg to itertools.accumulate() (GH-9345) (diff)
downloadcpython-a0fd7f1b55a1d76842fa2c6b5777a39cdcf2bb5e.tar.gz
cpython-a0fd7f1b55a1d76842fa2c6b5777a39cdcf2bb5e.tar.bz2
cpython-a0fd7f1b55a1d76842fa2c6b5777a39cdcf2bb5e.zip
Migrate datetime.date.fromtimestamp to Argument Clinic (GH-8535)
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 3ba700bbf85..b7c59f1bd86 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -23,8 +23,9 @@
/*[clinic input]
module datetime
class datetime.datetime "PyDateTime_DateTime *" "&PyDateTime_DateTimeType"
+class datetime.date "PyDateTime_Date *" "&PyDateTime_DateType"
[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78142cb64b9e98bc]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=25138ad6a696b785]*/
#include "clinic/_datetimemodule.c.h"
@@ -2788,9 +2789,8 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return self;
}
-/* Return new date from localtime(t). */
static PyObject *
-date_local_from_object(PyObject *cls, PyObject *obj)
+date_fromtimestamp(PyObject *cls, PyObject *obj)
{
struct tm tm;
time_t t;
@@ -2835,19 +2835,26 @@ date_today(PyObject *cls, PyObject *dummy)
return result;
}
-/* Return new date from given timestamp (Python timestamp -- a double). */
+/*[clinic input]
+@classmethod
+datetime.date.fromtimestamp
+
+ timestamp: object
+ /
+
+Create a date from a POSIX timestamp.
+
+The timestamp is a number, e.g. created via time.time(), that is interpreted
+as local time.
+[clinic start generated code]*/
+
static PyObject *
-date_fromtimestamp(PyObject *cls, PyObject *args)
+datetime_date_fromtimestamp(PyTypeObject *type, PyObject *timestamp)
+/*[clinic end generated code: output=fd045fda58168869 input=eabb3fe7f40491fe]*/
{
- PyObject *timestamp;
- PyObject *result = NULL;
-
- if (PyArg_ParseTuple(args, "O:fromtimestamp", &timestamp))
- result = date_local_from_object(cls, timestamp);
- return result;
+ return date_fromtimestamp((PyObject *) type, timestamp);
}
-
/* Return new date from proleptic Gregorian ordinal. Raises ValueError if
* the ordinal is out of range.
*/
@@ -3193,11 +3200,7 @@ date_reduce(PyDateTime_Date *self, PyObject *arg)
static PyMethodDef date_methods[] = {
/* Class methods: */
-
- {"fromtimestamp", (PyCFunction)date_fromtimestamp, METH_VARARGS |
- METH_CLASS,
- PyDoc_STR("timestamp -> local date from a POSIX timestamp (like "
- "time.time()).")},
+ DATETIME_DATE_FROMTIMESTAMP_METHODDEF
{"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS |
METH_CLASS,