• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
6 "fromtimestamp($type, timestamp, /)\n"
7 "--\n"
8 "\n"
9 "Create a date from a POSIX timestamp.\n"
10 "\n"
11 "The timestamp is a number, e.g. created via time.time(), that is interpreted\n"
12 "as local time.");
13 
14 #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF    \
15     {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
16 
17 static PyObject *
18 iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
19                            int weekday);
20 
21 static PyObject *
iso_calendar_date_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)22 iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24     PyObject *return_value = NULL;
25     static const char * const _keywords[] = {"year", "week", "weekday", NULL};
26     static _PyArg_Parser _parser = {NULL, _keywords, "IsoCalendarDate", 0};
27     PyObject *argsbuf[3];
28     PyObject * const *fastargs;
29     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
30     int year;
31     int week;
32     int weekday;
33 
34     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 3, 3, 0, argsbuf);
35     if (!fastargs) {
36         goto exit;
37     }
38     if (PyFloat_Check(fastargs[0])) {
39         PyErr_SetString(PyExc_TypeError,
40                         "integer argument expected, got float" );
41         goto exit;
42     }
43     year = _PyLong_AsInt(fastargs[0]);
44     if (year == -1 && PyErr_Occurred()) {
45         goto exit;
46     }
47     if (PyFloat_Check(fastargs[1])) {
48         PyErr_SetString(PyExc_TypeError,
49                         "integer argument expected, got float" );
50         goto exit;
51     }
52     week = _PyLong_AsInt(fastargs[1]);
53     if (week == -1 && PyErr_Occurred()) {
54         goto exit;
55     }
56     if (PyFloat_Check(fastargs[2])) {
57         PyErr_SetString(PyExc_TypeError,
58                         "integer argument expected, got float" );
59         goto exit;
60     }
61     weekday = _PyLong_AsInt(fastargs[2]);
62     if (weekday == -1 && PyErr_Occurred()) {
63         goto exit;
64     }
65     return_value = iso_calendar_date_new_impl(type, year, week, weekday);
66 
67 exit:
68     return return_value;
69 }
70 
71 PyDoc_STRVAR(datetime_datetime_now__doc__,
72 "now($type, /, tz=None)\n"
73 "--\n"
74 "\n"
75 "Returns new datetime object representing current time local to tz.\n"
76 "\n"
77 "  tz\n"
78 "    Timezone object.\n"
79 "\n"
80 "If no tz is specified, uses local timezone.");
81 
82 #define DATETIME_DATETIME_NOW_METHODDEF    \
83     {"now", (PyCFunction)(void(*)(void))datetime_datetime_now, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
84 
85 static PyObject *
86 datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
87 
88 static PyObject *
datetime_datetime_now(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)89 datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
90 {
91     PyObject *return_value = NULL;
92     static const char * const _keywords[] = {"tz", NULL};
93     static _PyArg_Parser _parser = {NULL, _keywords, "now", 0};
94     PyObject *argsbuf[1];
95     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
96     PyObject *tz = Py_None;
97 
98     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
99     if (!args) {
100         goto exit;
101     }
102     if (!noptargs) {
103         goto skip_optional_pos;
104     }
105     tz = args[0];
106 skip_optional_pos:
107     return_value = datetime_datetime_now_impl(type, tz);
108 
109 exit:
110     return return_value;
111 }
112 /*[clinic end generated code: output=5e17549f29a439a5 input=a9049054013a1b77]*/
113