|
23 | 23 | /*[clinic input]
|
24 | 24 | module datetime
|
25 | 25 | class datetime.datetime "PyDateTime_DateTime *" "&PyDateTime_DateTimeType"
|
| 26 | +class datetime.date "PyDateTime_Date *" "&PyDateTime_DateType" |
26 | 27 | [clinic start generated code]*/
|
27 |
| -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78142cb64b9e98bc]*/ |
| 28 | +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=25138ad6a696b785]*/ |
28 | 29 |
|
29 | 30 | #include "clinic/_datetimemodule.c.h"
|
30 | 31 |
|
@@ -2785,9 +2786,8 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
2785 | 2786 | return self;
|
2786 | 2787 | }
|
2787 | 2788 |
|
2788 |
| -/* Return new date from localtime(t). */ |
2789 | 2789 | static PyObject *
|
2790 |
| -date_local_from_object(PyObject *cls, PyObject *obj) |
| 2790 | +date_fromtimestamp(PyObject *cls, PyObject *obj) |
2791 | 2791 | {
|
2792 | 2792 | struct tm tm;
|
2793 | 2793 | time_t t;
|
@@ -2832,19 +2832,26 @@ date_today(PyObject *cls, PyObject *dummy)
|
2832 | 2832 | return result;
|
2833 | 2833 | }
|
2834 | 2834 |
|
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 | + |
2836 | 2848 | 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]*/ |
2838 | 2851 | {
|
2839 |
| - PyObject *timestamp; |
2840 |
| - PyObject *result = NULL; |
2841 |
| - |
2842 |
| - if (PyArg_ParseTuple(args, "O:fromtimestamp", ×tamp)) |
2843 |
| - result = date_local_from_object(cls, timestamp); |
2844 |
| - return result; |
| 2852 | + return date_fromtimestamp((PyObject *) type, timestamp); |
2845 | 2853 | }
|
2846 | 2854 |
|
2847 |
| - |
2848 | 2855 | /* Return new date from proleptic Gregorian ordinal. Raises ValueError if
|
2849 | 2856 | * the ordinal is out of range.
|
2850 | 2857 | */
|
@@ -3184,11 +3191,7 @@ date_reduce(PyDateTime_Date *self, PyObject *arg)
|
3184 | 3191 | static PyMethodDef date_methods[] = {
|
3185 | 3192 |
|
3186 | 3193 | /* 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 |
3192 | 3195 |
|
3193 | 3196 | {"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS |
|
3194 | 3197 | METH_CLASS,
|
|
0 commit comments