|
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 |
|
@@ -2788,9 +2789,8 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
2788 | 2789 | return self;
|
2789 | 2790 | }
|
2790 | 2791 |
|
2791 |
| -/* Return new date from localtime(t). */ |
2792 | 2792 | static PyObject *
|
2793 |
| -date_local_from_object(PyObject *cls, PyObject *obj) |
| 2793 | +date_fromtimestamp(PyObject *cls, PyObject *obj) |
2794 | 2794 | {
|
2795 | 2795 | struct tm tm;
|
2796 | 2796 | time_t t;
|
@@ -2835,19 +2835,26 @@ date_today(PyObject *cls, PyObject *dummy)
|
2835 | 2835 | return result;
|
2836 | 2836 | }
|
2837 | 2837 |
|
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 | + |
2839 | 2851 | 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]*/ |
2841 | 2854 | {
|
2842 |
| - PyObject *timestamp; |
2843 |
| - PyObject *result = NULL; |
2844 |
| - |
2845 |
| - if (PyArg_ParseTuple(args, "O:fromtimestamp", ×tamp)) |
2846 |
| - result = date_local_from_object(cls, timestamp); |
2847 |
| - return result; |
| 2855 | + return date_fromtimestamp((PyObject *) type, timestamp); |
2848 | 2856 | }
|
2849 | 2857 |
|
2850 |
| - |
2851 | 2858 | /* Return new date from proleptic Gregorian ordinal. Raises ValueError if
|
2852 | 2859 | * the ordinal is out of range.
|
2853 | 2860 | */
|
@@ -3193,11 +3200,7 @@ date_reduce(PyDateTime_Date *self, PyObject *arg)
|
3193 | 3200 | static PyMethodDef date_methods[] = {
|
3194 | 3201 |
|
3195 | 3202 | /* 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 |
3201 | 3204 |
|
3202 | 3205 | {"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS |
|
3203 | 3206 | METH_CLASS,
|
|
0 commit comments