Skip to content

Commit

Permalink
Migrate datetime.date.fromtimestamp to Argument Clinic (pythonGH-8535)
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm authored and encukou committed Sep 24, 2018
1 parent 9718b59 commit a0fd7f1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ Benjamin Hodgson
Joerg-Cyril Hoehle
Gregor Hoffleit
Chris Hoffman
Tim Hoffmann
Stefan Hoffmeister
Albert Hofkamp
Chris Hogan
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate datetime.date.fromtimestamp to Argument Clinic. Patch by Tim Hoffmann.
37 changes: 20 additions & 17 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion Modules/clinic/_datetimemodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0fd7f1

Please sign in to comment.