Skip to content

Commit 59a5e57

Browse files
committed
Migrate datetime.date.fromtimestamp to Argument Clinic
1 parent c6dabe3 commit 59a5e57

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
@@ -668,6 +668,7 @@ Benjamin Hodgson
668668
Joerg-Cyril Hoehle
669669
Gregor Hoffleit
670670
Chris Hoffman
671+
Tim Hoffmann
671672
Stefan Hoffmeister
672673
Albert Hofkamp
673674
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

@@ -2785,9 +2786,8 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
27852786
return self;
27862787
}
27872788

2788-
/* Return new date from localtime(t). */
27892789
static PyObject *
2790-
date_local_from_object(PyObject *cls, PyObject *obj)
2790+
date_fromtimestamp(PyObject *cls, PyObject *obj)
27912791
{
27922792
struct tm tm;
27932793
time_t t;
@@ -2832,19 +2832,26 @@ date_today(PyObject *cls, PyObject *dummy)
28322832
return result;
28332833
}
28342834

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

2847-
28482855
/* Return new date from proleptic Gregorian ordinal. Raises ValueError if
28492856
* the ordinal is out of range.
28502857
*/
@@ -3184,11 +3191,7 @@ date_reduce(PyDateTime_Date *self, PyObject *arg)
31843191
static PyMethodDef date_methods[] = {
31853192

31863193
/* Class methods: */
3187-
3188-
{"fromtimestamp", (PyCFunction)date_fromtimestamp, METH_VARARGS |
3189-
METH_CLASS,
3190-
PyDoc_STR("timestamp -> local date from a POSIX timestamp (like "
3191-
"time.time()).")},
3194+
DATETIME_DATE_FROMTIMESTAMP_METHODDEF
31923195

31933196
{"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS |
31943197
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)