Debian Codegraph @

Modules/clinic/_datetimemodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
12 "fromtimestamp($type, timestamp, /)\n"
13 "--\n"
14 "\n"
15 "Create a date from a POSIX timestamp.\n"
16 "\n"
17 "The timestamp is a number, e.g. created via time.time(), that is interpreted\n"
18 "as local time.");
19
20 #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \
21 {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
22
23 static PyObject *
24 datetime_date_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp);
25
26 static PyObject *
27 datetime_date_fromtimestamp(PyObject *type, PyObject *timestamp)
28 {
29 PyObject *return_value = NULL;
30
31 return_value = datetime_date_fromtimestamp_impl((PyTypeObject *)type, timestamp);
32
33 return return_value;
34 }
35
36 static PyObject *
37 iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
38 int weekday);
39
40 static PyObject *
41 iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
42 {
43 PyObject *return_value = NULL;
44 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
45
46 #define NUM_KEYWORDS 3
47 static struct {
48 PyGC_Head _this_is_not_used;
49 PyObject_VAR_HEAD
50 Py_hash_t ob_hash;
51 PyObject *ob_item[NUM_KEYWORDS];
52 } _kwtuple = {
53 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
54 .ob_hash = -1,
55 .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(weekday), },
56 };
57 #undef NUM_KEYWORDS
58 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
59
60 #else // !Py_BUILD_CORE
61 # define KWTUPLE NULL
62 #endif // !Py_BUILD_CORE
63
64 static const char * const _keywords[] = {"year", "week", "weekday", NULL};
65 static _PyArg_Parser _parser = {
66 .keywords = _keywords,
67 .fname = "IsoCalendarDate",
68 .kwtuple = KWTUPLE,
69 };
70 #undef KWTUPLE
71 PyObject *argsbuf[3];
72 PyObject * const *fastargs;
73 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
74 int year;
75 int week;
76 int weekday;
77
78 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
79 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
80 if (!fastargs) {
81 goto exit;
82 }
83 year = PyLong_AsInt(fastargs[0]);
84 if (year == -1 && PyErr_Occurred()) {
85 goto exit;
86 }
87 week = PyLong_AsInt(fastargs[1]);
88 if (week == -1 && PyErr_Occurred()) {
89 goto exit;
90 }
91 weekday = PyLong_AsInt(fastargs[2]);
92 if (weekday == -1 && PyErr_Occurred()) {
93 goto exit;
94 }
95 return_value = iso_calendar_date_new_impl(type, year, week, weekday);
96
97 exit:
98 return return_value;
99 }
100
101 PyDoc_STRVAR(datetime_date_replace__doc__,
102 "replace($self, /, year=unchanged, month=unchanged, day=unchanged)\n"
103 "--\n"
104 "\n"
105 "Return date with new specified fields.");
106
107 #define DATETIME_DATE_REPLACE_METHODDEF \
108 {"replace", _PyCFunction_CAST(datetime_date_replace), METH_FASTCALL|METH_KEYWORDS, datetime_date_replace__doc__},
109
110 static PyObject *
111 datetime_date_replace_impl(PyDateTime_Date *self, int year, int month,
112 int day);
113
114 static PyObject *
115 datetime_date_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
116 {
117 PyObject *return_value = NULL;
118 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
119
120 #define NUM_KEYWORDS 3
121 static struct {
122 PyGC_Head _this_is_not_used;
123 PyObject_VAR_HEAD
124 Py_hash_t ob_hash;
125 PyObject *ob_item[NUM_KEYWORDS];
126 } _kwtuple = {
127 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
128 .ob_hash = -1,
129 .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), },
130 };
131 #undef NUM_KEYWORDS
132 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
133
134 #else // !Py_BUILD_CORE
135 # define KWTUPLE NULL
136 #endif // !Py_BUILD_CORE
137
138 static const char * const _keywords[] = {"year", "month", "day", NULL};
139 static _PyArg_Parser _parser = {
140 .keywords = _keywords,
141 .fname = "replace",
142 .kwtuple = KWTUPLE,
143 };
144 #undef KWTUPLE
145 PyObject *argsbuf[3];
146 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
147 int year = GET_YEAR(self);
148 int month = GET_MONTH(self);
149 int day = GET_DAY(self);
150
151 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
152 /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
153 if (!args) {
154 goto exit;
155 }
156 if (!noptargs) {
157 goto skip_optional_pos;
158 }
159 if (args[0]) {
160 year = PyLong_AsInt(args[0]);
161 if (year == -1 && PyErr_Occurred()) {
162 goto exit;
163 }
164 if (!--noptargs) {
165 goto skip_optional_pos;
166 }
167 }
168 if (args[1]) {
169 month = PyLong_AsInt(args[1]);
170 if (month == -1 && PyErr_Occurred()) {
171 goto exit;
172 }
173 if (!--noptargs) {
174 goto skip_optional_pos;
175 }
176 }
177 day = PyLong_AsInt(args[2]);
178 if (day == -1 && PyErr_Occurred()) {
179 goto exit;
180 }
181 skip_optional_pos:
182 return_value = datetime_date_replace_impl((PyDateTime_Date *)self, year, month, day);
183
184 exit:
185 return return_value;
186 }
187
188 PyDoc_STRVAR(datetime_time_replace__doc__,
189 "replace($self, /, hour=unchanged, minute=unchanged, second=unchanged,\n"
190 " microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
191 "--\n"
192 "\n"
193 "Return time with new specified fields.");
194
195 #define DATETIME_TIME_REPLACE_METHODDEF \
196 {"replace", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL|METH_KEYWORDS, datetime_time_replace__doc__},
197
198 static PyObject *
199 datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute,
200 int second, int microsecond, PyObject *tzinfo,
201 int fold);
202
203 static PyObject *
204 datetime_time_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
205 {
206 PyObject *return_value = NULL;
207 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
208
209 #define NUM_KEYWORDS 6
210 static struct {
211 PyGC_Head _this_is_not_used;
212 PyObject_VAR_HEAD
213 Py_hash_t ob_hash;
214 PyObject *ob_item[NUM_KEYWORDS];
215 } _kwtuple = {
216 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
217 .ob_hash = -1,
218 .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
219 };
220 #undef NUM_KEYWORDS
221 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
222
223 #else // !Py_BUILD_CORE
224 # define KWTUPLE NULL
225 #endif // !Py_BUILD_CORE
226
227 static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
228 static _PyArg_Parser _parser = {
229 .keywords = _keywords,
230 .fname = "replace",
231 .kwtuple = KWTUPLE,
232 };
233 #undef KWTUPLE
234 PyObject *argsbuf[6];
235 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
236 int hour = TIME_GET_HOUR(self);
237 int minute = TIME_GET_MINUTE(self);
238 int second = TIME_GET_SECOND(self);
239 int microsecond = TIME_GET_MICROSECOND(self);
240 PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None;
241 int fold = TIME_GET_FOLD(self);
242
243 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
244 /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
245 if (!args) {
246 goto exit;
247 }
248 if (!noptargs) {
249 goto skip_optional_pos;
250 }
251 if (args[0]) {
252 hour = PyLong_AsInt(args[0]);
253 if (hour == -1 && PyErr_Occurred()) {
254 goto exit;
255 }
256 if (!--noptargs) {
257 goto skip_optional_pos;
258 }
259 }
260 if (args[1]) {
261 minute = PyLong_AsInt(args[1]);
262 if (minute == -1 && PyErr_Occurred()) {
263 goto exit;
264 }
265 if (!--noptargs) {
266 goto skip_optional_pos;
267 }
268 }
269 if (args[2]) {
270 second = PyLong_AsInt(args[2]);
271 if (second == -1 && PyErr_Occurred()) {
272 goto exit;
273 }
274 if (!--noptargs) {
275 goto skip_optional_pos;
276 }
277 }
278 if (args[3]) {
279 microsecond = PyLong_AsInt(args[3]);
280 if (microsecond == -1 && PyErr_Occurred()) {
281 goto exit;
282 }
283 if (!--noptargs) {
284 goto skip_optional_pos;
285 }
286 }
287 if (args[4]) {
288 tzinfo = args[4];
289 if (!--noptargs) {
290 goto skip_optional_pos;
291 }
292 }
293 skip_optional_pos:
294 if (!noptargs) {
295 goto skip_optional_kwonly;
296 }
297 fold = PyLong_AsInt(args[5]);
298 if (fold == -1 && PyErr_Occurred()) {
299 goto exit;
300 }
301 skip_optional_kwonly:
302 return_value = datetime_time_replace_impl((PyDateTime_Time *)self, hour, minute, second, microsecond, tzinfo, fold);
303
304 exit:
305 return return_value;
306 }
307
308 PyDoc_STRVAR(datetime_datetime_now__doc__,
309 "now($type, /, tz=None)\n"
310 "--\n"
311 "\n"
312 "Returns new datetime object representing current time local to tz.\n"
313 "\n"
314 " tz\n"
315 " Timezone object.\n"
316 "\n"
317 "If no tz is specified, uses local timezone.");
318
319 #define DATETIME_DATETIME_NOW_METHODDEF \
320 {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
321
322 static PyObject *
323 datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
324
325 static PyObject *
326 datetime_datetime_now(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
327 {
328 PyObject *return_value = NULL;
329 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
330
331 #define NUM_KEYWORDS 1
332 static struct {
333 PyGC_Head _this_is_not_used;
334 PyObject_VAR_HEAD
335 Py_hash_t ob_hash;
336 PyObject *ob_item[NUM_KEYWORDS];
337 } _kwtuple = {
338 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
339 .ob_hash = -1,
340 .ob_item = { &_Py_ID(tz), },
341 };
342 #undef NUM_KEYWORDS
343 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
344
345 #else // !Py_BUILD_CORE
346 # define KWTUPLE NULL
347 #endif // !Py_BUILD_CORE
348
349 static const char * const _keywords[] = {"tz", NULL};
350 static _PyArg_Parser _parser = {
351 .keywords = _keywords,
352 .fname = "now",
353 .kwtuple = KWTUPLE,
354 };
355 #undef KWTUPLE
356 PyObject *argsbuf[1];
357 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
358 PyObject *tz = Py_None;
359
360 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
361 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
362 if (!args) {
363 goto exit;
364 }
365 if (!noptargs) {
366 goto skip_optional_pos;
367 }
368 tz = args[0];
369 skip_optional_pos:
370 return_value = datetime_datetime_now_impl((PyTypeObject *)type, tz);
371
372 exit:
373 return return_value;
374 }
375
376 PyDoc_STRVAR(datetime_datetime_replace__doc__,
377 "replace($self, /, year=unchanged, month=unchanged, day=unchanged,\n"
378 " hour=unchanged, minute=unchanged, second=unchanged,\n"
379 " microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
380 "--\n"
381 "\n"
382 "Return datetime with new specified fields.");
383
384 #define DATETIME_DATETIME_REPLACE_METHODDEF \
385 {"replace", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_replace__doc__},
386
387 static PyObject *
388 datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year,
389 int month, int day, int hour, int minute,
390 int second, int microsecond, PyObject *tzinfo,
391 int fold);
392
393 static PyObject *
394 datetime_datetime_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
395 {
396 PyObject *return_value = NULL;
397 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
398
399 #define NUM_KEYWORDS 9
400 static struct {
401 PyGC_Head _this_is_not_used;
402 PyObject_VAR_HEAD
403 Py_hash_t ob_hash;
404 PyObject *ob_item[NUM_KEYWORDS];
405 } _kwtuple = {
406 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
407 .ob_hash = -1,
408 .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
409 };
410 #undef NUM_KEYWORDS
411 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
412
413 #else // !Py_BUILD_CORE
414 # define KWTUPLE NULL
415 #endif // !Py_BUILD_CORE
416
417 static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
418 static _PyArg_Parser _parser = {
419 .keywords = _keywords,
420 .fname = "replace",
421 .kwtuple = KWTUPLE,
422 };
423 #undef KWTUPLE
424 PyObject *argsbuf[9];
425 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
426 int year = GET_YEAR(self);
427 int month = GET_MONTH(self);
428 int day = GET_DAY(self);
429 int hour = DATE_GET_HOUR(self);
430 int minute = DATE_GET_MINUTE(self);
431 int second = DATE_GET_SECOND(self);
432 int microsecond = DATE_GET_MICROSECOND(self);
433 PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None;
434 int fold = DATE_GET_FOLD(self);
435
436 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
437 /*minpos*/ 0, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
438 if (!args) {
439 goto exit;
440 }
441 if (!noptargs) {
442 goto skip_optional_pos;
443 }
444 if (args[0]) {
445 year = PyLong_AsInt(args[0]);
446 if (year == -1 && PyErr_Occurred()) {
447 goto exit;
448 }
449 if (!--noptargs) {
450 goto skip_optional_pos;
451 }
452 }
453 if (args[1]) {
454 month = PyLong_AsInt(args[1]);
455 if (month == -1 && PyErr_Occurred()) {
456 goto exit;
457 }
458 if (!--noptargs) {
459 goto skip_optional_pos;
460 }
461 }
462 if (args[2]) {
463 day = PyLong_AsInt(args[2]);
464 if (day == -1 && PyErr_Occurred()) {
465 goto exit;
466 }
467 if (!--noptargs) {
468 goto skip_optional_pos;
469 }
470 }
471 if (args[3]) {
472 hour = PyLong_AsInt(args[3]);
473 if (hour == -1 && PyErr_Occurred()) {
474 goto exit;
475 }
476 if (!--noptargs) {
477 goto skip_optional_pos;
478 }
479 }
480 if (args[4]) {
481 minute = PyLong_AsInt(args[4]);
482 if (minute == -1 && PyErr_Occurred()) {
483 goto exit;
484 }
485 if (!--noptargs) {
486 goto skip_optional_pos;
487 }
488 }
489 if (args[5]) {
490 second = PyLong_AsInt(args[5]);
491 if (second == -1 && PyErr_Occurred()) {
492 goto exit;
493 }
494 if (!--noptargs) {
495 goto skip_optional_pos;
496 }
497 }
498 if (args[6]) {
499 microsecond = PyLong_AsInt(args[6]);
500 if (microsecond == -1 && PyErr_Occurred()) {
501 goto exit;
502 }
503 if (!--noptargs) {
504 goto skip_optional_pos;
505 }
506 }
507 if (args[7]) {
508 tzinfo = args[7];
509 if (!--noptargs) {
510 goto skip_optional_pos;
511 }
512 }
513 skip_optional_pos:
514 if (!noptargs) {
515 goto skip_optional_kwonly;
516 }
517 fold = PyLong_AsInt(args[8]);
518 if (fold == -1 && PyErr_Occurred()) {
519 goto exit;
520 }
521 skip_optional_kwonly:
522 return_value = datetime_datetime_replace_impl((PyDateTime_DateTime *)self, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
523
524 exit:
525 return return_value;
526 }
527 /*[clinic end generated code: output=809640e747529c72 input=a9049054013a1b77]*/