Skip to content

Commit a0fd7f1

Browse files
timhoffmencukou
authored andcommitted
Migrate datetime.date.fromtimestamp to Argument Clinic (GH-8535)
1 parent 9718b59 commit a0fd7f1

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ Benjamin Hodgson
672672
Joerg-Cyril Hoehle
673673
Gregor Hoffleit
674674
Chris Hoffman
675+
Tim Hoffmann
675676
Stefan Hoffmeister
676677
Albert Hofkamp
677678
Chris Hogan
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Migrate datetime.date.fromtimestamp to Argument Clinic. Patch by Tim Hoffmann.

Modules/_datetimemodule.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
/*[clinic input]
2424
module datetime
2525
class datetime.datetime "PyDateTime_DateTime *" "&PyDateTime_DateTimeType"
26+
class datetime.date "PyDateTime_Date *" "&PyDateTime_DateType"
2627
[clinic start generated code]*/
27-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78142cb64b9e98bc]*/
28+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=25138ad6a696b785]*/
2829

2930
#include "clinic/_datetimemodule.c.h"
3031

@@ -2788,9 +2789,8 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
27882789
return self;
27892790
}
27902791

2791-
/* Return new date from localtime(t). */
27922792
static PyObject *
2793-
date_local_from_object(PyObject *cls, PyObject *obj)
2793+
date_fromtimestamp(PyObject *cls, PyObject *obj)
27942794
{
27952795
struct tm tm;
27962796
time_t t;
@@ -2835,19 +2835,26 @@ date_today(PyObject *cls, PyObject *dummy)
28352835
return result;
28362836
}
28372837

2838-
/* Return new date from given timestamp (Python timestamp -- a double). */
2838+
/*[clinic input]
2839+
@classmethod
2840+
datetime.date.fromtimestamp
2841+
2842+
timestamp: object
2843+
/
2844+
2845+
Create a date from a POSIX timestamp.
2846+
2847+
The timestamp is a number, e.g. created via time.time(), that is interpreted
2848+
as local time.
2849+
[clinic start generated code]*/
2850+
28392851
static PyObject *
2840-
date_fromtimestamp(PyObject *cls, PyObject *args)
2852+
datetime_date_fromtimestamp(PyTypeObject *type, PyObject *timestamp)
2853+
/*[clinic end generated code: output=fd045fda58168869 input=eabb3fe7f40491fe]*/
28412854
{
2842-
PyObject *timestamp;
2843-
PyObject *result = NULL;
2844-
2845-
if (PyArg_ParseTuple(args, "O:fromtimestamp", &timestamp))
2846-
result = date_local_from_object(cls, timestamp);
2847-
return result;
2855+
return date_fromtimestamp((PyObject *) type, timestamp);
28482856
}
28492857

2850-
28512858
/* Return new date from proleptic Gregorian ordinal. Raises ValueError if
28522859
* the ordinal is out of range.
28532860
*/
@@ -3193,11 +3200,7 @@ date_reduce(PyDateTime_Date *self, PyObject *arg)
31933200
static PyMethodDef date_methods[] = {
31943201

31953202
/* Class methods: */
3196-
3197-
{"fromtimestamp", (PyCFunction)date_fromtimestamp, METH_VARARGS |
3198-
METH_CLASS,
3199-
PyDoc_STR("timestamp -> local date from a POSIX timestamp (like "
3200-
"time.time()).")},
3203+
DATETIME_DATE_FROMTIMESTAMP_METHODDEF
32013204

32023205
{"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS |
32033206
METH_CLASS,

Modules/clinic/_datetimemodule.c.h

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)