Coverage Report

Created: 2026-05-30 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/_datetimemodule.c.h
Line
Count
Source
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(delta_new__doc__,
12
"timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0,\n"
13
"          hours=0, weeks=0)\n"
14
"--\n"
15
"\n"
16
"Difference between two datetime values.\n"
17
"\n"
18
"All arguments are optional and default to 0.\n"
19
"Arguments may be integers or floats, and may be positive or negative.");
20
21
static PyObject *
22
delta_new_impl(PyTypeObject *type, PyObject *days, PyObject *seconds,
23
               PyObject *microseconds, PyObject *milliseconds,
24
               PyObject *minutes, PyObject *hours, PyObject *weeks);
25
26
static PyObject *
27
delta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
28
12.2k
{
29
12.2k
    PyObject *return_value = NULL;
30
12.2k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
31
32
12.2k
    #define NUM_KEYWORDS 7
33
12.2k
    static struct {
34
12.2k
        PyGC_Head _this_is_not_used;
35
12.2k
        PyObject_VAR_HEAD
36
12.2k
        Py_hash_t ob_hash;
37
12.2k
        PyObject *ob_item[NUM_KEYWORDS];
38
12.2k
    } _kwtuple = {
39
12.2k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
40
12.2k
        .ob_hash = -1,
41
12.2k
        .ob_item = { &_Py_ID(days), &_Py_ID(seconds), &_Py_ID(microseconds), &_Py_ID(milliseconds), &_Py_ID(minutes), &_Py_ID(hours), &_Py_ID(weeks), },
42
12.2k
    };
43
12.2k
    #undef NUM_KEYWORDS
44
12.2k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
45
46
    #else  // !Py_BUILD_CORE
47
    #  define KWTUPLE NULL
48
    #endif  // !Py_BUILD_CORE
49
50
12.2k
    static const char * const _keywords[] = {"days", "seconds", "microseconds", "milliseconds", "minutes", "hours", "weeks", NULL};
51
12.2k
    static _PyArg_Parser _parser = {
52
12.2k
        .keywords = _keywords,
53
12.2k
        .fname = "timedelta",
54
12.2k
        .kwtuple = KWTUPLE,
55
12.2k
    };
56
12.2k
    #undef KWTUPLE
57
12.2k
    PyObject *argsbuf[7];
58
12.2k
    PyObject * const *fastargs;
59
12.2k
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
60
12.2k
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
61
12.2k
    PyObject *days = NULL;
62
12.2k
    PyObject *seconds = NULL;
63
12.2k
    PyObject *microseconds = NULL;
64
12.2k
    PyObject *milliseconds = NULL;
65
12.2k
    PyObject *minutes = NULL;
66
12.2k
    PyObject *hours = NULL;
67
12.2k
    PyObject *weeks = NULL;
68
69
12.2k
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
70
12.2k
            /*minpos*/ 0, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
71
12.2k
    if (!fastargs) {
72
0
        goto exit;
73
0
    }
74
12.2k
    if (!noptargs) {
75
0
        goto skip_optional_pos;
76
0
    }
77
12.2k
    if (fastargs[0]) {
78
8
        days = fastargs[0];
79
8
        if (!--noptargs) {
80
8
            goto skip_optional_pos;
81
8
        }
82
8
    }
83
12.1k
    if (fastargs[1]) {
84
12.1k
        seconds = fastargs[1];
85
12.1k
        if (!--noptargs) {
86
12.1k
            goto skip_optional_pos;
87
12.1k
        }
88
12.1k
    }
89
8
    if (fastargs[2]) {
90
0
        microseconds = fastargs[2];
91
0
        if (!--noptargs) {
92
0
            goto skip_optional_pos;
93
0
        }
94
0
    }
95
8
    if (fastargs[3]) {
96
4
        milliseconds = fastargs[3];
97
4
        if (!--noptargs) {
98
4
            goto skip_optional_pos;
99
4
        }
100
4
    }
101
4
    if (fastargs[4]) {
102
4
        minutes = fastargs[4];
103
4
        if (!--noptargs) {
104
0
            goto skip_optional_pos;
105
0
        }
106
4
    }
107
4
    if (fastargs[5]) {
108
4
        hours = fastargs[5];
109
4
        if (!--noptargs) {
110
4
            goto skip_optional_pos;
111
4
        }
112
4
    }
113
0
    weeks = fastargs[6];
114
12.2k
skip_optional_pos:
115
12.2k
    return_value = delta_new_impl(type, days, seconds, microseconds, milliseconds, minutes, hours, weeks);
116
117
12.2k
exit:
118
12.2k
    return return_value;
119
12.2k
}
120
121
PyDoc_STRVAR(datetime_date__doc__,
122
"date(year, month, day)\n"
123
"--\n"
124
"\n"
125
"Concrete date type.");
126
127
static PyObject *
128
datetime_date_impl(PyTypeObject *type, int year, int month, int day);
129
130
static PyObject *
131
datetime_date(PyTypeObject *type, PyObject *args, PyObject *kwargs)
132
194
{
133
194
    PyObject *return_value = NULL;
134
194
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
135
136
194
    #define NUM_KEYWORDS 3
137
194
    static struct {
138
194
        PyGC_Head _this_is_not_used;
139
194
        PyObject_VAR_HEAD
140
194
        Py_hash_t ob_hash;
141
194
        PyObject *ob_item[NUM_KEYWORDS];
142
194
    } _kwtuple = {
143
194
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
144
194
        .ob_hash = -1,
145
194
        .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), },
146
194
    };
147
194
    #undef NUM_KEYWORDS
148
194
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
149
150
    #else  // !Py_BUILD_CORE
151
    #  define KWTUPLE NULL
152
    #endif  // !Py_BUILD_CORE
153
154
194
    static const char * const _keywords[] = {"year", "month", "day", NULL};
155
194
    static _PyArg_Parser _parser = {
156
194
        .keywords = _keywords,
157
194
        .fname = "date",
158
194
        .kwtuple = KWTUPLE,
159
194
    };
160
194
    #undef KWTUPLE
161
194
    PyObject *argsbuf[3];
162
194
    PyObject * const *fastargs;
163
194
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
164
194
    int year;
165
194
    int month;
166
194
    int day;
167
168
194
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
169
194
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
170
194
    if (!fastargs) {
171
0
        goto exit;
172
0
    }
173
194
    year = PyLong_AsInt(fastargs[0]);
174
194
    if (year == -1 && PyErr_Occurred()) {
175
0
        goto exit;
176
0
    }
177
194
    month = PyLong_AsInt(fastargs[1]);
178
194
    if (month == -1 && PyErr_Occurred()) {
179
0
        goto exit;
180
0
    }
181
194
    day = PyLong_AsInt(fastargs[2]);
182
194
    if (day == -1 && PyErr_Occurred()) {
183
0
        goto exit;
184
0
    }
185
194
    return_value = datetime_date_impl(type, year, month, day);
186
187
194
exit:
188
194
    return return_value;
189
194
}
190
191
PyDoc_STRVAR(datetime_date_today__doc__,
192
"today($type, /)\n"
193
"--\n"
194
"\n"
195
"Current date or datetime.\n"
196
"\n"
197
"Equivalent to fromtimestamp(time.time()).");
198
199
#define DATETIME_DATE_TODAY_METHODDEF    \
200
    {"today", (PyCFunction)datetime_date_today, METH_NOARGS|METH_CLASS, datetime_date_today__doc__},
201
202
static PyObject *
203
datetime_date_today_impl(PyTypeObject *type);
204
205
static PyObject *
206
datetime_date_today(PyObject *type, PyObject *Py_UNUSED(ignored))
207
0
{
208
0
    return datetime_date_today_impl((PyTypeObject *)type);
209
0
}
210
211
PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
212
"fromtimestamp($type, timestamp, /)\n"
213
"--\n"
214
"\n"
215
"Create a date from a POSIX timestamp.\n"
216
"\n"
217
"The timestamp is a number, e.g. created via time.time(), that is\n"
218
"interpreted as local time.");
219
220
#define DATETIME_DATE_FROMTIMESTAMP_METHODDEF    \
221
    {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__},
222
223
static PyObject *
224
datetime_date_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp);
225
226
static PyObject *
227
datetime_date_fromtimestamp(PyObject *type, PyObject *timestamp)
228
0
{
229
0
    PyObject *return_value = NULL;
230
231
0
    return_value = datetime_date_fromtimestamp_impl((PyTypeObject *)type, timestamp);
232
233
0
    return return_value;
234
0
}
235
236
PyDoc_STRVAR(datetime_date_fromordinal__doc__,
237
"fromordinal($type, ordinal, /)\n"
238
"--\n"
239
"\n"
240
"Construct a date from a proleptic Gregorian ordinal.\n"
241
"\n"
242
"January 1 of year 1 is day 1.  Only the year, month and day are\n"
243
"non-zero in the result.");
244
245
#define DATETIME_DATE_FROMORDINAL_METHODDEF    \
246
    {"fromordinal", (PyCFunction)datetime_date_fromordinal, METH_O|METH_CLASS, datetime_date_fromordinal__doc__},
247
248
static PyObject *
249
datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal);
250
251
static PyObject *
252
datetime_date_fromordinal(PyObject *type, PyObject *arg)
253
0
{
254
0
    PyObject *return_value = NULL;
255
0
    int ordinal;
256
257
0
    ordinal = PyLong_AsInt(arg);
258
0
    if (ordinal == -1 && PyErr_Occurred()) {
259
0
        goto exit;
260
0
    }
261
0
    return_value = datetime_date_fromordinal_impl((PyTypeObject *)type, ordinal);
262
263
0
exit:
264
0
    return return_value;
265
0
}
266
267
PyDoc_STRVAR(datetime_date_fromisoformat__doc__,
268
"fromisoformat($type, string, /)\n"
269
"--\n"
270
"\n"
271
"Construct a date from a string in ISO 8601 format.");
272
273
#define DATETIME_DATE_FROMISOFORMAT_METHODDEF    \
274
    {"fromisoformat", (PyCFunction)datetime_date_fromisoformat, METH_O|METH_CLASS, datetime_date_fromisoformat__doc__},
275
276
static PyObject *
277
datetime_date_fromisoformat_impl(PyTypeObject *type, PyObject *string);
278
279
static PyObject *
280
datetime_date_fromisoformat(PyObject *type, PyObject *arg)
281
0
{
282
0
    PyObject *return_value = NULL;
283
0
    PyObject *string;
284
285
0
    if (!PyUnicode_Check(arg)) {
286
0
        _PyArg_BadArgument("fromisoformat", "argument", "str", arg);
287
0
        goto exit;
288
0
    }
289
0
    string = arg;
290
0
    return_value = datetime_date_fromisoformat_impl((PyTypeObject *)type, string);
291
292
0
exit:
293
0
    return return_value;
294
0
}
295
296
PyDoc_STRVAR(datetime_date_fromisocalendar__doc__,
297
"fromisocalendar($type, /, year, week, day)\n"
298
"--\n"
299
"\n"
300
"Construct a date from the ISO year, week number and weekday.\n"
301
"\n"
302
"This is the inverse of the date.isocalendar() function.");
303
304
#define DATETIME_DATE_FROMISOCALENDAR_METHODDEF    \
305
    {"fromisocalendar", _PyCFunction_CAST(datetime_date_fromisocalendar), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_date_fromisocalendar__doc__},
306
307
static PyObject *
308
datetime_date_fromisocalendar_impl(PyTypeObject *type, int year, int week,
309
                                   int day);
310
311
static PyObject *
312
datetime_date_fromisocalendar(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
313
0
{
314
0
    PyObject *return_value = NULL;
315
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
316
317
0
    #define NUM_KEYWORDS 3
318
0
    static struct {
319
0
        PyGC_Head _this_is_not_used;
320
0
        PyObject_VAR_HEAD
321
0
        Py_hash_t ob_hash;
322
0
        PyObject *ob_item[NUM_KEYWORDS];
323
0
    } _kwtuple = {
324
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
325
0
        .ob_hash = -1,
326
0
        .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(day), },
327
0
    };
328
0
    #undef NUM_KEYWORDS
329
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
330
331
    #else  // !Py_BUILD_CORE
332
    #  define KWTUPLE NULL
333
    #endif  // !Py_BUILD_CORE
334
335
0
    static const char * const _keywords[] = {"year", "week", "day", NULL};
336
0
    static _PyArg_Parser _parser = {
337
0
        .keywords = _keywords,
338
0
        .fname = "fromisocalendar",
339
0
        .kwtuple = KWTUPLE,
340
0
    };
341
0
    #undef KWTUPLE
342
0
    PyObject *argsbuf[3];
343
0
    int year;
344
0
    int week;
345
0
    int day;
346
347
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
348
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
349
0
    if (!args) {
350
0
        goto exit;
351
0
    }
352
0
    year = PyLong_AsInt(args[0]);
353
0
    if (year == -1 && PyErr_Occurred()) {
354
0
        goto exit;
355
0
    }
356
0
    week = PyLong_AsInt(args[1]);
357
0
    if (week == -1 && PyErr_Occurred()) {
358
0
        goto exit;
359
0
    }
360
0
    day = PyLong_AsInt(args[2]);
361
0
    if (day == -1 && PyErr_Occurred()) {
362
0
        goto exit;
363
0
    }
364
0
    return_value = datetime_date_fromisocalendar_impl((PyTypeObject *)type, year, week, day);
365
366
0
exit:
367
0
    return return_value;
368
0
}
369
370
PyDoc_STRVAR(datetime_date_strptime__doc__,
371
"strptime($type, string, format, /)\n"
372
"--\n"
373
"\n"
374
"Parse string according to the given date format (like time.strptime()).\n"
375
"\n"
376
"For a list of supported format codes, see the documentation:\n"
377
"    https://docs.python.org/3/library/datetime.html#format-codes");
378
379
#define DATETIME_DATE_STRPTIME_METHODDEF    \
380
    {"strptime", _PyCFunction_CAST(datetime_date_strptime), METH_FASTCALL|METH_CLASS, datetime_date_strptime__doc__},
381
382
static PyObject *
383
datetime_date_strptime_impl(PyTypeObject *type, PyObject *string,
384
                            PyObject *format);
385
386
static PyObject *
387
datetime_date_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
388
0
{
389
0
    PyObject *return_value = NULL;
390
0
    PyObject *string;
391
0
    PyObject *format;
392
393
0
    if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) {
394
0
        goto exit;
395
0
    }
396
0
    if (!PyUnicode_Check(args[0])) {
397
0
        _PyArg_BadArgument("strptime", "argument 1", "str", args[0]);
398
0
        goto exit;
399
0
    }
400
0
    string = args[0];
401
0
    if (!PyUnicode_Check(args[1])) {
402
0
        _PyArg_BadArgument("strptime", "argument 2", "str", args[1]);
403
0
        goto exit;
404
0
    }
405
0
    format = args[1];
406
0
    return_value = datetime_date_strptime_impl((PyTypeObject *)type, string, format);
407
408
0
exit:
409
0
    return return_value;
410
0
}
411
412
PyDoc_STRVAR(datetime_date_strftime__doc__,
413
"strftime($self, /, format)\n"
414
"--\n"
415
"\n"
416
"Format using strftime().\n"
417
"\n"
418
"Example: \"%d/%m/%Y, %H:%M:%S\".\n"
419
"\n"
420
"For a list of supported format codes, see the documentation:\n"
421
"    https://docs.python.org/3/library/datetime.html#format-codes");
422
423
#define DATETIME_DATE_STRFTIME_METHODDEF    \
424
    {"strftime", _PyCFunction_CAST(datetime_date_strftime), METH_FASTCALL|METH_KEYWORDS, datetime_date_strftime__doc__},
425
426
static PyObject *
427
datetime_date_strftime_impl(PyObject *self, PyObject *format);
428
429
static PyObject *
430
datetime_date_strftime(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
431
192
{
432
192
    PyObject *return_value = NULL;
433
192
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
434
435
192
    #define NUM_KEYWORDS 1
436
192
    static struct {
437
192
        PyGC_Head _this_is_not_used;
438
192
        PyObject_VAR_HEAD
439
192
        Py_hash_t ob_hash;
440
192
        PyObject *ob_item[NUM_KEYWORDS];
441
192
    } _kwtuple = {
442
192
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
443
192
        .ob_hash = -1,
444
192
        .ob_item = { &_Py_ID(format), },
445
192
    };
446
192
    #undef NUM_KEYWORDS
447
192
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
448
449
    #else  // !Py_BUILD_CORE
450
    #  define KWTUPLE NULL
451
    #endif  // !Py_BUILD_CORE
452
453
192
    static const char * const _keywords[] = {"format", NULL};
454
192
    static _PyArg_Parser _parser = {
455
192
        .keywords = _keywords,
456
192
        .fname = "strftime",
457
192
        .kwtuple = KWTUPLE,
458
192
    };
459
192
    #undef KWTUPLE
460
192
    PyObject *argsbuf[1];
461
192
    PyObject *format;
462
463
192
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
464
192
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
465
192
    if (!args) {
466
0
        goto exit;
467
0
    }
468
192
    if (!PyUnicode_Check(args[0])) {
469
0
        _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]);
470
0
        goto exit;
471
0
    }
472
192
    format = args[0];
473
192
    return_value = datetime_date_strftime_impl(self, format);
474
475
192
exit:
476
192
    return return_value;
477
192
}
478
479
PyDoc_STRVAR(datetime_date___format____doc__,
480
"__format__($self, format, /)\n"
481
"--\n"
482
"\n"
483
"Formats self with strftime.");
484
485
#define DATETIME_DATE___FORMAT___METHODDEF    \
486
    {"__format__", (PyCFunction)datetime_date___format__, METH_O, datetime_date___format____doc__},
487
488
static PyObject *
489
datetime_date___format___impl(PyObject *self, PyObject *format);
490
491
static PyObject *
492
datetime_date___format__(PyObject *self, PyObject *arg)
493
0
{
494
0
    PyObject *return_value = NULL;
495
0
    PyObject *format;
496
497
0
    if (!PyUnicode_Check(arg)) {
498
0
        _PyArg_BadArgument("__format__", "argument", "str", arg);
499
0
        goto exit;
500
0
    }
501
0
    format = arg;
502
0
    return_value = datetime_date___format___impl(self, format);
503
504
0
exit:
505
0
    return return_value;
506
0
}
507
508
static PyObject *
509
iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
510
                           int weekday);
511
512
static PyObject *
513
iso_calendar_date_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
514
0
{
515
0
    PyObject *return_value = NULL;
516
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
517
518
0
    #define NUM_KEYWORDS 3
519
0
    static struct {
520
0
        PyGC_Head _this_is_not_used;
521
0
        PyObject_VAR_HEAD
522
0
        Py_hash_t ob_hash;
523
0
        PyObject *ob_item[NUM_KEYWORDS];
524
0
    } _kwtuple = {
525
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
526
0
        .ob_hash = -1,
527
0
        .ob_item = { &_Py_ID(year), &_Py_ID(week), &_Py_ID(weekday), },
528
0
    };
529
0
    #undef NUM_KEYWORDS
530
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
531
532
    #else  // !Py_BUILD_CORE
533
    #  define KWTUPLE NULL
534
    #endif  // !Py_BUILD_CORE
535
536
0
    static const char * const _keywords[] = {"year", "week", "weekday", NULL};
537
0
    static _PyArg_Parser _parser = {
538
0
        .keywords = _keywords,
539
0
        .fname = "IsoCalendarDate",
540
0
        .kwtuple = KWTUPLE,
541
0
    };
542
0
    #undef KWTUPLE
543
0
    PyObject *argsbuf[3];
544
0
    PyObject * const *fastargs;
545
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
546
0
    int year;
547
0
    int week;
548
0
    int weekday;
549
550
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
551
0
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
552
0
    if (!fastargs) {
553
0
        goto exit;
554
0
    }
555
0
    year = PyLong_AsInt(fastargs[0]);
556
0
    if (year == -1 && PyErr_Occurred()) {
557
0
        goto exit;
558
0
    }
559
0
    week = PyLong_AsInt(fastargs[1]);
560
0
    if (week == -1 && PyErr_Occurred()) {
561
0
        goto exit;
562
0
    }
563
0
    weekday = PyLong_AsInt(fastargs[2]);
564
0
    if (weekday == -1 && PyErr_Occurred()) {
565
0
        goto exit;
566
0
    }
567
0
    return_value = iso_calendar_date_new_impl(type, year, week, weekday);
568
569
0
exit:
570
0
    return return_value;
571
0
}
572
573
PyDoc_STRVAR(datetime_date_replace__doc__,
574
"replace($self, /, year=unchanged, month=unchanged, day=unchanged)\n"
575
"--\n"
576
"\n"
577
"Return date with new specified fields.");
578
579
#define DATETIME_DATE_REPLACE_METHODDEF    \
580
    {"replace", _PyCFunction_CAST(datetime_date_replace), METH_FASTCALL|METH_KEYWORDS, datetime_date_replace__doc__},
581
582
static PyObject *
583
datetime_date_replace_impl(PyDateTime_Date *self, int year, int month,
584
                           int day);
585
586
static PyObject *
587
datetime_date_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
588
0
{
589
0
    PyObject *return_value = NULL;
590
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
591
592
0
    #define NUM_KEYWORDS 3
593
0
    static struct {
594
0
        PyGC_Head _this_is_not_used;
595
0
        PyObject_VAR_HEAD
596
0
        Py_hash_t ob_hash;
597
0
        PyObject *ob_item[NUM_KEYWORDS];
598
0
    } _kwtuple = {
599
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
600
0
        .ob_hash = -1,
601
0
        .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), },
602
0
    };
603
0
    #undef NUM_KEYWORDS
604
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
605
606
    #else  // !Py_BUILD_CORE
607
    #  define KWTUPLE NULL
608
    #endif  // !Py_BUILD_CORE
609
610
0
    static const char * const _keywords[] = {"year", "month", "day", NULL};
611
0
    static _PyArg_Parser _parser = {
612
0
        .keywords = _keywords,
613
0
        .fname = "replace",
614
0
        .kwtuple = KWTUPLE,
615
0
    };
616
0
    #undef KWTUPLE
617
0
    PyObject *argsbuf[3];
618
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
619
0
    int year = GET_YEAR(self);
620
0
    int month = GET_MONTH(self);
621
0
    int day = GET_DAY(self);
622
623
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
624
0
            /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
625
0
    if (!args) {
626
0
        goto exit;
627
0
    }
628
0
    if (!noptargs) {
629
0
        goto skip_optional_pos;
630
0
    }
631
0
    if (args[0]) {
632
0
        year = PyLong_AsInt(args[0]);
633
0
        if (year == -1 && PyErr_Occurred()) {
634
0
            goto exit;
635
0
        }
636
0
        if (!--noptargs) {
637
0
            goto skip_optional_pos;
638
0
        }
639
0
    }
640
0
    if (args[1]) {
641
0
        month = PyLong_AsInt(args[1]);
642
0
        if (month == -1 && PyErr_Occurred()) {
643
0
            goto exit;
644
0
        }
645
0
        if (!--noptargs) {
646
0
            goto skip_optional_pos;
647
0
        }
648
0
    }
649
0
    day = PyLong_AsInt(args[2]);
650
0
    if (day == -1 && PyErr_Occurred()) {
651
0
        goto exit;
652
0
    }
653
0
skip_optional_pos:
654
0
    return_value = datetime_date_replace_impl((PyDateTime_Date *)self, year, month, day);
655
656
0
exit:
657
0
    return return_value;
658
0
}
659
660
PyDoc_STRVAR(timezone_new__doc__,
661
"timezone(offset, name=<unrepresentable>)\n"
662
"--\n"
663
"\n"
664
"Fixed offset from UTC implementation of tzinfo.");
665
666
static PyObject *
667
timezone_new_impl(PyTypeObject *type, PyObject *offset, PyObject *name);
668
669
static PyObject *
670
timezone_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
671
4
{
672
4
    PyObject *return_value = NULL;
673
4
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
674
675
4
    #define NUM_KEYWORDS 2
676
4
    static struct {
677
4
        PyGC_Head _this_is_not_used;
678
4
        PyObject_VAR_HEAD
679
4
        Py_hash_t ob_hash;
680
4
        PyObject *ob_item[NUM_KEYWORDS];
681
4
    } _kwtuple = {
682
4
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
683
4
        .ob_hash = -1,
684
4
        .ob_item = { &_Py_ID(offset), &_Py_ID(name), },
685
4
    };
686
4
    #undef NUM_KEYWORDS
687
4
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
688
689
    #else  // !Py_BUILD_CORE
690
    #  define KWTUPLE NULL
691
    #endif  // !Py_BUILD_CORE
692
693
4
    static const char * const _keywords[] = {"offset", "name", NULL};
694
4
    static _PyArg_Parser _parser = {
695
4
        .keywords = _keywords,
696
4
        .fname = "timezone",
697
4
        .kwtuple = KWTUPLE,
698
4
    };
699
4
    #undef KWTUPLE
700
4
    PyObject *argsbuf[2];
701
4
    PyObject * const *fastargs;
702
4
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
703
4
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
704
4
    PyObject *offset;
705
4
    PyObject *name = NULL;
706
707
4
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
708
4
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
709
4
    if (!fastargs) {
710
0
        goto exit;
711
0
    }
712
4
    if (!PyObject_TypeCheck(fastargs[0], DELTA_TYPE(NO_STATE))) {
713
0
        _PyArg_BadArgument("timezone", "argument 'offset'", (DELTA_TYPE(NO_STATE))->tp_name, fastargs[0]);
714
0
        goto exit;
715
0
    }
716
4
    offset = fastargs[0];
717
4
    if (!noptargs) {
718
4
        goto skip_optional_pos;
719
4
    }
720
0
    if (!PyUnicode_Check(fastargs[1])) {
721
0
        _PyArg_BadArgument("timezone", "argument 'name'", "str", fastargs[1]);
722
0
        goto exit;
723
0
    }
724
0
    name = fastargs[1];
725
4
skip_optional_pos:
726
4
    return_value = timezone_new_impl(type, offset, name);
727
728
4
exit:
729
4
    return return_value;
730
4
}
731
732
PyDoc_STRVAR(datetime_time__doc__,
733
"time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)\n"
734
"--\n"
735
"\n"
736
"Time with time zone.\n"
737
"\n"
738
"All arguments are optional. tzinfo may be None, or an instance of\n"
739
"a tzinfo subclass. The remaining arguments may be ints.");
740
741
static PyObject *
742
datetime_time_impl(PyTypeObject *type, int hour, int minute, int second,
743
                   int microsecond, PyObject *tzinfo, int fold);
744
745
static PyObject *
746
datetime_time(PyTypeObject *type, PyObject *args, PyObject *kwargs)
747
158
{
748
158
    PyObject *return_value = NULL;
749
158
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
750
751
158
    #define NUM_KEYWORDS 6
752
158
    static struct {
753
158
        PyGC_Head _this_is_not_used;
754
158
        PyObject_VAR_HEAD
755
158
        Py_hash_t ob_hash;
756
158
        PyObject *ob_item[NUM_KEYWORDS];
757
158
    } _kwtuple = {
758
158
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
759
158
        .ob_hash = -1,
760
158
        .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
761
158
    };
762
158
    #undef NUM_KEYWORDS
763
158
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
764
765
    #else  // !Py_BUILD_CORE
766
    #  define KWTUPLE NULL
767
    #endif  // !Py_BUILD_CORE
768
769
158
    static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
770
158
    static _PyArg_Parser _parser = {
771
158
        .keywords = _keywords,
772
158
        .fname = "time",
773
158
        .kwtuple = KWTUPLE,
774
158
    };
775
158
    #undef KWTUPLE
776
158
    PyObject *argsbuf[6];
777
158
    PyObject * const *fastargs;
778
158
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
779
158
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
780
158
    int hour = 0;
781
158
    int minute = 0;
782
158
    int second = 0;
783
158
    int microsecond = 0;
784
158
    PyObject *tzinfo = Py_None;
785
158
    int fold = 0;
786
787
158
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
788
158
            /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
789
158
    if (!fastargs) {
790
0
        goto exit;
791
0
    }
792
158
    if (!noptargs) {
793
0
        goto skip_optional_pos;
794
0
    }
795
158
    if (fastargs[0]) {
796
158
        hour = PyLong_AsInt(fastargs[0]);
797
158
        if (hour == -1 && PyErr_Occurred()) {
798
0
            goto exit;
799
0
        }
800
158
        if (!--noptargs) {
801
0
            goto skip_optional_pos;
802
0
        }
803
158
    }
804
158
    if (fastargs[1]) {
805
158
        minute = PyLong_AsInt(fastargs[1]);
806
158
        if (minute == -1 && PyErr_Occurred()) {
807
0
            goto exit;
808
0
        }
809
158
        if (!--noptargs) {
810
0
            goto skip_optional_pos;
811
0
        }
812
158
    }
813
158
    if (fastargs[2]) {
814
158
        second = PyLong_AsInt(fastargs[2]);
815
158
        if (second == -1 && PyErr_Occurred()) {
816
0
            goto exit;
817
0
        }
818
158
        if (!--noptargs) {
819
0
            goto skip_optional_pos;
820
0
        }
821
158
    }
822
158
    if (fastargs[3]) {
823
158
        microsecond = PyLong_AsInt(fastargs[3]);
824
158
        if (microsecond == -1 && PyErr_Occurred()) {
825
0
            goto exit;
826
0
        }
827
158
        if (!--noptargs) {
828
158
            goto skip_optional_pos;
829
158
        }
830
158
    }
831
0
    if (fastargs[4]) {
832
0
        tzinfo = fastargs[4];
833
0
        if (!--noptargs) {
834
0
            goto skip_optional_pos;
835
0
        }
836
0
    }
837
158
skip_optional_pos:
838
158
    if (!noptargs) {
839
158
        goto skip_optional_kwonly;
840
158
    }
841
0
    fold = PyLong_AsInt(fastargs[5]);
842
0
    if (fold == -1 && PyErr_Occurred()) {
843
0
        goto exit;
844
0
    }
845
158
skip_optional_kwonly:
846
158
    return_value = datetime_time_impl(type, hour, minute, second, microsecond, tzinfo, fold);
847
848
158
exit:
849
158
    return return_value;
850
158
}
851
852
PyDoc_STRVAR(datetime_time_strptime__doc__,
853
"strptime($type, string, format, /)\n"
854
"--\n"
855
"\n"
856
"Parse string according to the given time format (like time.strptime()).\n"
857
"\n"
858
"For a list of supported format codes, see the documentation:\n"
859
"    https://docs.python.org/3/library/datetime.html#format-codes");
860
861
#define DATETIME_TIME_STRPTIME_METHODDEF    \
862
    {"strptime", _PyCFunction_CAST(datetime_time_strptime), METH_FASTCALL|METH_CLASS, datetime_time_strptime__doc__},
863
864
static PyObject *
865
datetime_time_strptime_impl(PyTypeObject *type, PyObject *string,
866
                            PyObject *format);
867
868
static PyObject *
869
datetime_time_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
870
0
{
871
0
    PyObject *return_value = NULL;
872
0
    PyObject *string;
873
0
    PyObject *format;
874
875
0
    if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) {
876
0
        goto exit;
877
0
    }
878
0
    if (!PyUnicode_Check(args[0])) {
879
0
        _PyArg_BadArgument("strptime", "argument 1", "str", args[0]);
880
0
        goto exit;
881
0
    }
882
0
    string = args[0];
883
0
    if (!PyUnicode_Check(args[1])) {
884
0
        _PyArg_BadArgument("strptime", "argument 2", "str", args[1]);
885
0
        goto exit;
886
0
    }
887
0
    format = args[1];
888
0
    return_value = datetime_time_strptime_impl((PyTypeObject *)type, string, format);
889
890
0
exit:
891
0
    return return_value;
892
0
}
893
894
PyDoc_STRVAR(datetime_time_isoformat__doc__,
895
"isoformat($self, /, timespec=\'auto\')\n"
896
"--\n"
897
"\n"
898
"Return the time formatted according to ISO.\n"
899
"\n"
900
"The full format is \'HH:MM:SS.mmmmmm+zz:zz\'. By default, the\n"
901
"fractional part is omitted if self.microsecond == 0.\n"
902
"\n"
903
"The optional argument timespec specifies the number of additional\n"
904
"terms of the time to include. Valid options are \'auto\', \'hours\',\n"
905
"\'minutes\', \'seconds\', \'milliseconds\' and \'microseconds\'.");
906
907
#define DATETIME_TIME_ISOFORMAT_METHODDEF    \
908
    {"isoformat", _PyCFunction_CAST(datetime_time_isoformat), METH_FASTCALL|METH_KEYWORDS, datetime_time_isoformat__doc__},
909
910
static PyObject *
911
datetime_time_isoformat_impl(PyDateTime_Time *self, const char *timespec);
912
913
static PyObject *
914
datetime_time_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
915
0
{
916
0
    PyObject *return_value = NULL;
917
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
918
919
0
    #define NUM_KEYWORDS 1
920
0
    static struct {
921
0
        PyGC_Head _this_is_not_used;
922
0
        PyObject_VAR_HEAD
923
0
        Py_hash_t ob_hash;
924
0
        PyObject *ob_item[NUM_KEYWORDS];
925
0
    } _kwtuple = {
926
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
927
0
        .ob_hash = -1,
928
0
        .ob_item = { &_Py_ID(timespec), },
929
0
    };
930
0
    #undef NUM_KEYWORDS
931
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
932
933
    #else  // !Py_BUILD_CORE
934
    #  define KWTUPLE NULL
935
    #endif  // !Py_BUILD_CORE
936
937
0
    static const char * const _keywords[] = {"timespec", NULL};
938
0
    static _PyArg_Parser _parser = {
939
0
        .keywords = _keywords,
940
0
        .fname = "isoformat",
941
0
        .kwtuple = KWTUPLE,
942
0
    };
943
0
    #undef KWTUPLE
944
0
    PyObject *argsbuf[1];
945
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
946
0
    const char *timespec = NULL;
947
948
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
949
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
950
0
    if (!args) {
951
0
        goto exit;
952
0
    }
953
0
    if (!noptargs) {
954
0
        goto skip_optional_pos;
955
0
    }
956
0
    if (!PyUnicode_Check(args[0])) {
957
0
        _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[0]);
958
0
        goto exit;
959
0
    }
960
0
    Py_ssize_t timespec_length;
961
0
    timespec = PyUnicode_AsUTF8AndSize(args[0], &timespec_length);
962
0
    if (timespec == NULL) {
963
0
        goto exit;
964
0
    }
965
0
    if (strlen(timespec) != (size_t)timespec_length) {
966
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
967
0
        goto exit;
968
0
    }
969
0
skip_optional_pos:
970
0
    return_value = datetime_time_isoformat_impl((PyDateTime_Time *)self, timespec);
971
972
0
exit:
973
0
    return return_value;
974
0
}
975
976
PyDoc_STRVAR(datetime_time_strftime__doc__,
977
"strftime($self, /, format)\n"
978
"--\n"
979
"\n"
980
"Format using strftime().\n"
981
"\n"
982
"The date part of the timestamp passed to underlying strftime should\n"
983
"not be used.\n"
984
"\n"
985
"For a list of supported format codes, see the documentation:\n"
986
"    https://docs.python.org/3/library/datetime.html#format-codes");
987
988
#define DATETIME_TIME_STRFTIME_METHODDEF    \
989
    {"strftime", _PyCFunction_CAST(datetime_time_strftime), METH_FASTCALL|METH_KEYWORDS, datetime_time_strftime__doc__},
990
991
static PyObject *
992
datetime_time_strftime_impl(PyDateTime_Time *self, PyObject *format);
993
994
static PyObject *
995
datetime_time_strftime(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
996
0
{
997
0
    PyObject *return_value = NULL;
998
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
999
1000
0
    #define NUM_KEYWORDS 1
1001
0
    static struct {
1002
0
        PyGC_Head _this_is_not_used;
1003
0
        PyObject_VAR_HEAD
1004
0
        Py_hash_t ob_hash;
1005
0
        PyObject *ob_item[NUM_KEYWORDS];
1006
0
    } _kwtuple = {
1007
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1008
0
        .ob_hash = -1,
1009
0
        .ob_item = { &_Py_ID(format), },
1010
0
    };
1011
0
    #undef NUM_KEYWORDS
1012
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1013
1014
    #else  // !Py_BUILD_CORE
1015
    #  define KWTUPLE NULL
1016
    #endif  // !Py_BUILD_CORE
1017
1018
0
    static const char * const _keywords[] = {"format", NULL};
1019
0
    static _PyArg_Parser _parser = {
1020
0
        .keywords = _keywords,
1021
0
        .fname = "strftime",
1022
0
        .kwtuple = KWTUPLE,
1023
0
    };
1024
0
    #undef KWTUPLE
1025
0
    PyObject *argsbuf[1];
1026
0
    PyObject *format;
1027
1028
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1029
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1030
0
    if (!args) {
1031
0
        goto exit;
1032
0
    }
1033
0
    if (!PyUnicode_Check(args[0])) {
1034
0
        _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]);
1035
0
        goto exit;
1036
0
    }
1037
0
    format = args[0];
1038
0
    return_value = datetime_time_strftime_impl((PyDateTime_Time *)self, format);
1039
1040
0
exit:
1041
0
    return return_value;
1042
0
}
1043
1044
PyDoc_STRVAR(datetime_time___format____doc__,
1045
"__format__($self, format, /)\n"
1046
"--\n"
1047
"\n"
1048
"Formats self with strftime.");
1049
1050
#define DATETIME_TIME___FORMAT___METHODDEF    \
1051
    {"__format__", (PyCFunction)datetime_time___format__, METH_O, datetime_time___format____doc__},
1052
1053
static PyObject *
1054
datetime_time___format___impl(PyObject *self, PyObject *format);
1055
1056
static PyObject *
1057
datetime_time___format__(PyObject *self, PyObject *arg)
1058
0
{
1059
0
    PyObject *return_value = NULL;
1060
0
    PyObject *format;
1061
1062
0
    if (!PyUnicode_Check(arg)) {
1063
0
        _PyArg_BadArgument("__format__", "argument", "str", arg);
1064
0
        goto exit;
1065
0
    }
1066
0
    format = arg;
1067
0
    return_value = datetime_time___format___impl(self, format);
1068
1069
0
exit:
1070
0
    return return_value;
1071
0
}
1072
1073
PyDoc_STRVAR(datetime_time_replace__doc__,
1074
"replace($self, /, hour=unchanged, minute=unchanged, second=unchanged,\n"
1075
"        microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
1076
"--\n"
1077
"\n"
1078
"Return time with new specified fields.");
1079
1080
#define DATETIME_TIME_REPLACE_METHODDEF    \
1081
    {"replace", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL|METH_KEYWORDS, datetime_time_replace__doc__},
1082
1083
static PyObject *
1084
datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute,
1085
                           int second, int microsecond, PyObject *tzinfo,
1086
                           int fold);
1087
1088
static PyObject *
1089
datetime_time_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1090
0
{
1091
0
    PyObject *return_value = NULL;
1092
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1093
1094
0
    #define NUM_KEYWORDS 6
1095
0
    static struct {
1096
0
        PyGC_Head _this_is_not_used;
1097
0
        PyObject_VAR_HEAD
1098
0
        Py_hash_t ob_hash;
1099
0
        PyObject *ob_item[NUM_KEYWORDS];
1100
0
    } _kwtuple = {
1101
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1102
0
        .ob_hash = -1,
1103
0
        .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
1104
0
    };
1105
0
    #undef NUM_KEYWORDS
1106
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1107
1108
    #else  // !Py_BUILD_CORE
1109
    #  define KWTUPLE NULL
1110
    #endif  // !Py_BUILD_CORE
1111
1112
0
    static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1113
0
    static _PyArg_Parser _parser = {
1114
0
        .keywords = _keywords,
1115
0
        .fname = "replace",
1116
0
        .kwtuple = KWTUPLE,
1117
0
    };
1118
0
    #undef KWTUPLE
1119
0
    PyObject *argsbuf[6];
1120
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1121
0
    int hour = TIME_GET_HOUR(self);
1122
0
    int minute = TIME_GET_MINUTE(self);
1123
0
    int second = TIME_GET_SECOND(self);
1124
0
    int microsecond = TIME_GET_MICROSECOND(self);
1125
0
    PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None;
1126
0
    int fold = TIME_GET_FOLD(self);
1127
1128
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1129
0
            /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1130
0
    if (!args) {
1131
0
        goto exit;
1132
0
    }
1133
0
    if (!noptargs) {
1134
0
        goto skip_optional_pos;
1135
0
    }
1136
0
    if (args[0]) {
1137
0
        hour = PyLong_AsInt(args[0]);
1138
0
        if (hour == -1 && PyErr_Occurred()) {
1139
0
            goto exit;
1140
0
        }
1141
0
        if (!--noptargs) {
1142
0
            goto skip_optional_pos;
1143
0
        }
1144
0
    }
1145
0
    if (args[1]) {
1146
0
        minute = PyLong_AsInt(args[1]);
1147
0
        if (minute == -1 && PyErr_Occurred()) {
1148
0
            goto exit;
1149
0
        }
1150
0
        if (!--noptargs) {
1151
0
            goto skip_optional_pos;
1152
0
        }
1153
0
    }
1154
0
    if (args[2]) {
1155
0
        second = PyLong_AsInt(args[2]);
1156
0
        if (second == -1 && PyErr_Occurred()) {
1157
0
            goto exit;
1158
0
        }
1159
0
        if (!--noptargs) {
1160
0
            goto skip_optional_pos;
1161
0
        }
1162
0
    }
1163
0
    if (args[3]) {
1164
0
        microsecond = PyLong_AsInt(args[3]);
1165
0
        if (microsecond == -1 && PyErr_Occurred()) {
1166
0
            goto exit;
1167
0
        }
1168
0
        if (!--noptargs) {
1169
0
            goto skip_optional_pos;
1170
0
        }
1171
0
    }
1172
0
    if (args[4]) {
1173
0
        tzinfo = args[4];
1174
0
        if (!--noptargs) {
1175
0
            goto skip_optional_pos;
1176
0
        }
1177
0
    }
1178
0
skip_optional_pos:
1179
0
    if (!noptargs) {
1180
0
        goto skip_optional_kwonly;
1181
0
    }
1182
0
    fold = PyLong_AsInt(args[5]);
1183
0
    if (fold == -1 && PyErr_Occurred()) {
1184
0
        goto exit;
1185
0
    }
1186
0
skip_optional_kwonly:
1187
0
    return_value = datetime_time_replace_impl((PyDateTime_Time *)self, hour, minute, second, microsecond, tzinfo, fold);
1188
1189
0
exit:
1190
0
    return return_value;
1191
0
}
1192
1193
PyDoc_STRVAR(datetime_time_fromisoformat__doc__,
1194
"fromisoformat($type, string, /)\n"
1195
"--\n"
1196
"\n"
1197
"Construct a time from a string in ISO 8601 format.");
1198
1199
#define DATETIME_TIME_FROMISOFORMAT_METHODDEF    \
1200
    {"fromisoformat", (PyCFunction)datetime_time_fromisoformat, METH_O|METH_CLASS, datetime_time_fromisoformat__doc__},
1201
1202
static PyObject *
1203
datetime_time_fromisoformat_impl(PyTypeObject *type, PyObject *string);
1204
1205
static PyObject *
1206
datetime_time_fromisoformat(PyObject *type, PyObject *arg)
1207
0
{
1208
0
    PyObject *return_value = NULL;
1209
0
    PyObject *string;
1210
1211
0
    if (!PyUnicode_Check(arg)) {
1212
0
        _PyArg_BadArgument("fromisoformat", "argument", "str", arg);
1213
0
        goto exit;
1214
0
    }
1215
0
    string = arg;
1216
0
    return_value = datetime_time_fromisoformat_impl((PyTypeObject *)type, string);
1217
1218
0
exit:
1219
0
    return return_value;
1220
0
}
1221
1222
PyDoc_STRVAR(datetime_time___reduce_ex____doc__,
1223
"__reduce_ex__($self, proto, /)\n"
1224
"--\n"
1225
"\n");
1226
1227
#define DATETIME_TIME___REDUCE_EX___METHODDEF    \
1228
    {"__reduce_ex__", (PyCFunction)datetime_time___reduce_ex__, METH_O, datetime_time___reduce_ex____doc__},
1229
1230
static PyObject *
1231
datetime_time___reduce_ex___impl(PyDateTime_Time *self, int proto);
1232
1233
static PyObject *
1234
datetime_time___reduce_ex__(PyObject *self, PyObject *arg)
1235
0
{
1236
0
    PyObject *return_value = NULL;
1237
0
    int proto;
1238
1239
0
    proto = PyLong_AsInt(arg);
1240
0
    if (proto == -1 && PyErr_Occurred()) {
1241
0
        goto exit;
1242
0
    }
1243
0
    return_value = datetime_time___reduce_ex___impl((PyDateTime_Time *)self, proto);
1244
1245
0
exit:
1246
0
    return return_value;
1247
0
}
1248
1249
PyDoc_STRVAR(datetime_time___reduce____doc__,
1250
"__reduce__($self, /)\n"
1251
"--\n"
1252
"\n");
1253
1254
#define DATETIME_TIME___REDUCE___METHODDEF    \
1255
    {"__reduce__", (PyCFunction)datetime_time___reduce__, METH_NOARGS, datetime_time___reduce____doc__},
1256
1257
static PyObject *
1258
datetime_time___reduce___impl(PyDateTime_Time *self);
1259
1260
static PyObject *
1261
datetime_time___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
1262
0
{
1263
0
    return datetime_time___reduce___impl((PyDateTime_Time *)self);
1264
0
}
1265
1266
PyDoc_STRVAR(datetime_datetime__doc__,
1267
"datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0,\n"
1268
"         tzinfo=None, *, fold=0)\n"
1269
"--\n"
1270
"\n"
1271
"A combination of a date and a time.\n"
1272
"\n"
1273
"The year, month and day arguments are required. tzinfo may be None, or\n"
1274
"an instance of a tzinfo subclass. The remaining arguments may be ints.");
1275
1276
static PyObject *
1277
datetime_datetime_impl(PyTypeObject *type, int year, int month, int day,
1278
                       int hour, int minute, int second, int microsecond,
1279
                       PyObject *tzinfo, int fold);
1280
1281
static PyObject *
1282
datetime_datetime(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1283
174
{
1284
174
    PyObject *return_value = NULL;
1285
174
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1286
1287
174
    #define NUM_KEYWORDS 9
1288
174
    static struct {
1289
174
        PyGC_Head _this_is_not_used;
1290
174
        PyObject_VAR_HEAD
1291
174
        Py_hash_t ob_hash;
1292
174
        PyObject *ob_item[NUM_KEYWORDS];
1293
174
    } _kwtuple = {
1294
174
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1295
174
        .ob_hash = -1,
1296
174
        .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), },
1297
174
    };
1298
174
    #undef NUM_KEYWORDS
1299
174
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1300
1301
    #else  // !Py_BUILD_CORE
1302
    #  define KWTUPLE NULL
1303
    #endif  // !Py_BUILD_CORE
1304
1305
174
    static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1306
174
    static _PyArg_Parser _parser = {
1307
174
        .keywords = _keywords,
1308
174
        .fname = "datetime",
1309
174
        .kwtuple = KWTUPLE,
1310
174
    };
1311
174
    #undef KWTUPLE
1312
174
    PyObject *argsbuf[9];
1313
174
    PyObject * const *fastargs;
1314
174
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1315
174
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 3;
1316
174
    int year;
1317
174
    int month;
1318
174
    int day;
1319
174
    int hour = 0;
1320
174
    int minute = 0;
1321
174
    int second = 0;
1322
174
    int microsecond = 0;
1323
174
    PyObject *tzinfo = Py_None;
1324
174
    int fold = 0;
1325
1326
174
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1327
174
            /*minpos*/ 3, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1328
174
    if (!fastargs) {
1329
0
        goto exit;
1330
0
    }
1331
174
    year = PyLong_AsInt(fastargs[0]);
1332
174
    if (year == -1 && PyErr_Occurred()) {
1333
0
        goto exit;
1334
0
    }
1335
174
    month = PyLong_AsInt(fastargs[1]);
1336
174
    if (month == -1 && PyErr_Occurred()) {
1337
0
        goto exit;
1338
0
    }
1339
174
    day = PyLong_AsInt(fastargs[2]);
1340
174
    if (day == -1 && PyErr_Occurred()) {
1341
0
        goto exit;
1342
0
    }
1343
174
    if (!noptargs) {
1344
17
        goto skip_optional_pos;
1345
17
    }
1346
157
    if (fastargs[3]) {
1347
157
        hour = PyLong_AsInt(fastargs[3]);
1348
157
        if (hour == -1 && PyErr_Occurred()) {
1349
0
            goto exit;
1350
0
        }
1351
157
        if (!--noptargs) {
1352
0
            goto skip_optional_pos;
1353
0
        }
1354
157
    }
1355
157
    if (fastargs[4]) {
1356
157
        minute = PyLong_AsInt(fastargs[4]);
1357
157
        if (minute == -1 && PyErr_Occurred()) {
1358
0
            goto exit;
1359
0
        }
1360
157
        if (!--noptargs) {
1361
0
            goto skip_optional_pos;
1362
0
        }
1363
157
    }
1364
157
    if (fastargs[5]) {
1365
157
        second = PyLong_AsInt(fastargs[5]);
1366
157
        if (second == -1 && PyErr_Occurred()) {
1367
0
            goto exit;
1368
0
        }
1369
157
        if (!--noptargs) {
1370
110
            goto skip_optional_pos;
1371
110
        }
1372
157
    }
1373
47
    if (fastargs[6]) {
1374
47
        microsecond = PyLong_AsInt(fastargs[6]);
1375
47
        if (microsecond == -1 && PyErr_Occurred()) {
1376
0
            goto exit;
1377
0
        }
1378
47
        if (!--noptargs) {
1379
0
            goto skip_optional_pos;
1380
0
        }
1381
47
    }
1382
47
    if (fastargs[7]) {
1383
47
        tzinfo = fastargs[7];
1384
47
        if (!--noptargs) {
1385
47
            goto skip_optional_pos;
1386
47
        }
1387
47
    }
1388
174
skip_optional_pos:
1389
174
    if (!noptargs) {
1390
174
        goto skip_optional_kwonly;
1391
174
    }
1392
0
    fold = PyLong_AsInt(fastargs[8]);
1393
0
    if (fold == -1 && PyErr_Occurred()) {
1394
0
        goto exit;
1395
0
    }
1396
174
skip_optional_kwonly:
1397
174
    return_value = datetime_datetime_impl(type, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
1398
1399
174
exit:
1400
174
    return return_value;
1401
174
}
1402
1403
PyDoc_STRVAR(datetime_datetime_now__doc__,
1404
"now($type, /, tz=None)\n"
1405
"--\n"
1406
"\n"
1407
"Returns new datetime object representing current time local to tz.\n"
1408
"\n"
1409
"  tz\n"
1410
"    Timezone object.\n"
1411
"\n"
1412
"If no tz is specified, uses local timezone.");
1413
1414
#define DATETIME_DATETIME_NOW_METHODDEF    \
1415
    {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
1416
1417
static PyObject *
1418
datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
1419
1420
static PyObject *
1421
datetime_datetime_now(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1422
0
{
1423
0
    PyObject *return_value = NULL;
1424
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1425
1426
0
    #define NUM_KEYWORDS 1
1427
0
    static struct {
1428
0
        PyGC_Head _this_is_not_used;
1429
0
        PyObject_VAR_HEAD
1430
0
        Py_hash_t ob_hash;
1431
0
        PyObject *ob_item[NUM_KEYWORDS];
1432
0
    } _kwtuple = {
1433
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1434
0
        .ob_hash = -1,
1435
0
        .ob_item = { &_Py_ID(tz), },
1436
0
    };
1437
0
    #undef NUM_KEYWORDS
1438
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1439
1440
    #else  // !Py_BUILD_CORE
1441
    #  define KWTUPLE NULL
1442
    #endif  // !Py_BUILD_CORE
1443
1444
0
    static const char * const _keywords[] = {"tz", NULL};
1445
0
    static _PyArg_Parser _parser = {
1446
0
        .keywords = _keywords,
1447
0
        .fname = "now",
1448
0
        .kwtuple = KWTUPLE,
1449
0
    };
1450
0
    #undef KWTUPLE
1451
0
    PyObject *argsbuf[1];
1452
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1453
0
    PyObject *tz = Py_None;
1454
1455
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1456
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1457
0
    if (!args) {
1458
0
        goto exit;
1459
0
    }
1460
0
    if (!noptargs) {
1461
0
        goto skip_optional_pos;
1462
0
    }
1463
0
    tz = args[0];
1464
0
skip_optional_pos:
1465
0
    return_value = datetime_datetime_now_impl((PyTypeObject *)type, tz);
1466
1467
0
exit:
1468
0
    return return_value;
1469
0
}
1470
1471
PyDoc_STRVAR(datetime_datetime_utcnow__doc__,
1472
"utcnow($type, /)\n"
1473
"--\n"
1474
"\n"
1475
"Return a new datetime representing UTC day and time.");
1476
1477
#define DATETIME_DATETIME_UTCNOW_METHODDEF    \
1478
    {"utcnow", (PyCFunction)datetime_datetime_utcnow, METH_NOARGS|METH_CLASS, datetime_datetime_utcnow__doc__},
1479
1480
static PyObject *
1481
datetime_datetime_utcnow_impl(PyTypeObject *type);
1482
1483
static PyObject *
1484
datetime_datetime_utcnow(PyObject *type, PyObject *Py_UNUSED(ignored))
1485
0
{
1486
0
    return datetime_datetime_utcnow_impl((PyTypeObject *)type);
1487
0
}
1488
1489
PyDoc_STRVAR(datetime_datetime_fromtimestamp__doc__,
1490
"fromtimestamp($type, /, timestamp, tz=None)\n"
1491
"--\n"
1492
"\n"
1493
"Create a datetime from a POSIX timestamp.\n"
1494
"\n"
1495
"The timestamp is a number, e.g. created via time.time(), that is\n"
1496
"interpreted as local time.");
1497
1498
#define DATETIME_DATETIME_FROMTIMESTAMP_METHODDEF    \
1499
    {"fromtimestamp", _PyCFunction_CAST(datetime_datetime_fromtimestamp), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_fromtimestamp__doc__},
1500
1501
static PyObject *
1502
datetime_datetime_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp,
1503
                                     PyObject *tzinfo);
1504
1505
static PyObject *
1506
datetime_datetime_fromtimestamp(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1507
0
{
1508
0
    PyObject *return_value = NULL;
1509
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1510
1511
0
    #define NUM_KEYWORDS 2
1512
0
    static struct {
1513
0
        PyGC_Head _this_is_not_used;
1514
0
        PyObject_VAR_HEAD
1515
0
        Py_hash_t ob_hash;
1516
0
        PyObject *ob_item[NUM_KEYWORDS];
1517
0
    } _kwtuple = {
1518
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1519
0
        .ob_hash = -1,
1520
0
        .ob_item = { &_Py_ID(timestamp), &_Py_ID(tz), },
1521
0
    };
1522
0
    #undef NUM_KEYWORDS
1523
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1524
1525
    #else  // !Py_BUILD_CORE
1526
    #  define KWTUPLE NULL
1527
    #endif  // !Py_BUILD_CORE
1528
1529
0
    static const char * const _keywords[] = {"timestamp", "tz", NULL};
1530
0
    static _PyArg_Parser _parser = {
1531
0
        .keywords = _keywords,
1532
0
        .fname = "fromtimestamp",
1533
0
        .kwtuple = KWTUPLE,
1534
0
    };
1535
0
    #undef KWTUPLE
1536
0
    PyObject *argsbuf[2];
1537
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1538
0
    PyObject *timestamp;
1539
0
    PyObject *tzinfo = Py_None;
1540
1541
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1542
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1543
0
    if (!args) {
1544
0
        goto exit;
1545
0
    }
1546
0
    timestamp = args[0];
1547
0
    if (!noptargs) {
1548
0
        goto skip_optional_pos;
1549
0
    }
1550
0
    tzinfo = args[1];
1551
0
skip_optional_pos:
1552
0
    return_value = datetime_datetime_fromtimestamp_impl((PyTypeObject *)type, timestamp, tzinfo);
1553
1554
0
exit:
1555
0
    return return_value;
1556
0
}
1557
1558
PyDoc_STRVAR(datetime_datetime_utcfromtimestamp__doc__,
1559
"utcfromtimestamp($type, timestamp, /)\n"
1560
"--\n"
1561
"\n"
1562
"Create a naive UTC datetime from a POSIX timestamp.");
1563
1564
#define DATETIME_DATETIME_UTCFROMTIMESTAMP_METHODDEF    \
1565
    {"utcfromtimestamp", (PyCFunction)datetime_datetime_utcfromtimestamp, METH_O|METH_CLASS, datetime_datetime_utcfromtimestamp__doc__},
1566
1567
static PyObject *
1568
datetime_datetime_utcfromtimestamp_impl(PyTypeObject *type,
1569
                                        PyObject *timestamp);
1570
1571
static PyObject *
1572
datetime_datetime_utcfromtimestamp(PyObject *type, PyObject *timestamp)
1573
0
{
1574
0
    PyObject *return_value = NULL;
1575
1576
0
    return_value = datetime_datetime_utcfromtimestamp_impl((PyTypeObject *)type, timestamp);
1577
1578
0
    return return_value;
1579
0
}
1580
1581
PyDoc_STRVAR(datetime_datetime_strptime__doc__,
1582
"strptime($type, string, format, /)\n"
1583
"--\n"
1584
"\n"
1585
"Parse string according to the given date and time format (like time.strptime()).\n"
1586
"\n"
1587
"For a list of supported format codes, see the documentation:\n"
1588
"    https://docs.python.org/3/library/datetime.html#format-codes");
1589
1590
#define DATETIME_DATETIME_STRPTIME_METHODDEF    \
1591
    {"strptime", _PyCFunction_CAST(datetime_datetime_strptime), METH_FASTCALL|METH_CLASS, datetime_datetime_strptime__doc__},
1592
1593
static PyObject *
1594
datetime_datetime_strptime_impl(PyTypeObject *type, PyObject *string,
1595
                                PyObject *format);
1596
1597
static PyObject *
1598
datetime_datetime_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
1599
0
{
1600
0
    PyObject *return_value = NULL;
1601
0
    PyObject *string;
1602
0
    PyObject *format;
1603
1604
0
    if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) {
1605
0
        goto exit;
1606
0
    }
1607
0
    if (!PyUnicode_Check(args[0])) {
1608
0
        _PyArg_BadArgument("strptime", "argument 1", "str", args[0]);
1609
0
        goto exit;
1610
0
    }
1611
0
    string = args[0];
1612
0
    if (!PyUnicode_Check(args[1])) {
1613
0
        _PyArg_BadArgument("strptime", "argument 2", "str", args[1]);
1614
0
        goto exit;
1615
0
    }
1616
0
    format = args[1];
1617
0
    return_value = datetime_datetime_strptime_impl((PyTypeObject *)type, string, format);
1618
1619
0
exit:
1620
0
    return return_value;
1621
0
}
1622
1623
PyDoc_STRVAR(datetime_datetime_combine__doc__,
1624
"combine($type, /, date, time, tzinfo=<unrepresentable>)\n"
1625
"--\n"
1626
"\n"
1627
"Construct a datetime from a given date and a given time.");
1628
1629
#define DATETIME_DATETIME_COMBINE_METHODDEF    \
1630
    {"combine", _PyCFunction_CAST(datetime_datetime_combine), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_combine__doc__},
1631
1632
static PyObject *
1633
datetime_datetime_combine_impl(PyTypeObject *type, PyObject *date,
1634
                               PyObject *time, PyObject *tzinfo);
1635
1636
static PyObject *
1637
datetime_datetime_combine(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1638
0
{
1639
0
    PyObject *return_value = NULL;
1640
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1641
1642
0
    #define NUM_KEYWORDS 3
1643
0
    static struct {
1644
0
        PyGC_Head _this_is_not_used;
1645
0
        PyObject_VAR_HEAD
1646
0
        Py_hash_t ob_hash;
1647
0
        PyObject *ob_item[NUM_KEYWORDS];
1648
0
    } _kwtuple = {
1649
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1650
0
        .ob_hash = -1,
1651
0
        .ob_item = { &_Py_ID(date), &_Py_ID(time), &_Py_ID(tzinfo), },
1652
0
    };
1653
0
    #undef NUM_KEYWORDS
1654
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1655
1656
    #else  // !Py_BUILD_CORE
1657
    #  define KWTUPLE NULL
1658
    #endif  // !Py_BUILD_CORE
1659
1660
0
    static const char * const _keywords[] = {"date", "time", "tzinfo", NULL};
1661
0
    static _PyArg_Parser _parser = {
1662
0
        .keywords = _keywords,
1663
0
        .fname = "combine",
1664
0
        .kwtuple = KWTUPLE,
1665
0
    };
1666
0
    #undef KWTUPLE
1667
0
    PyObject *argsbuf[3];
1668
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1669
0
    PyObject *date;
1670
0
    PyObject *time;
1671
0
    PyObject *tzinfo = NULL;
1672
1673
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1674
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1675
0
    if (!args) {
1676
0
        goto exit;
1677
0
    }
1678
0
    if (!PyObject_TypeCheck(args[0], DATE_TYPE(NO_STATE))) {
1679
0
        _PyArg_BadArgument("combine", "argument 'date'", (DATE_TYPE(NO_STATE))->tp_name, args[0]);
1680
0
        goto exit;
1681
0
    }
1682
0
    date = args[0];
1683
0
    if (!PyObject_TypeCheck(args[1], TIME_TYPE(NO_STATE))) {
1684
0
        _PyArg_BadArgument("combine", "argument 'time'", (TIME_TYPE(NO_STATE))->tp_name, args[1]);
1685
0
        goto exit;
1686
0
    }
1687
0
    time = args[1];
1688
0
    if (!noptargs) {
1689
0
        goto skip_optional_pos;
1690
0
    }
1691
0
    tzinfo = args[2];
1692
0
skip_optional_pos:
1693
0
    return_value = datetime_datetime_combine_impl((PyTypeObject *)type, date, time, tzinfo);
1694
1695
0
exit:
1696
0
    return return_value;
1697
0
}
1698
1699
PyDoc_STRVAR(datetime_datetime_fromisoformat__doc__,
1700
"fromisoformat($type, string, /)\n"
1701
"--\n"
1702
"\n"
1703
"Construct a date from a string in ISO 8601 format.");
1704
1705
#define DATETIME_DATETIME_FROMISOFORMAT_METHODDEF    \
1706
    {"fromisoformat", (PyCFunction)datetime_datetime_fromisoformat, METH_O|METH_CLASS, datetime_datetime_fromisoformat__doc__},
1707
1708
static PyObject *
1709
datetime_datetime_fromisoformat_impl(PyTypeObject *type, PyObject *string);
1710
1711
static PyObject *
1712
datetime_datetime_fromisoformat(PyObject *type, PyObject *arg)
1713
0
{
1714
0
    PyObject *return_value = NULL;
1715
0
    PyObject *string;
1716
1717
0
    if (!PyUnicode_Check(arg)) {
1718
0
        _PyArg_BadArgument("fromisoformat", "argument", "str", arg);
1719
0
        goto exit;
1720
0
    }
1721
0
    string = arg;
1722
0
    return_value = datetime_datetime_fromisoformat_impl((PyTypeObject *)type, string);
1723
1724
0
exit:
1725
0
    return return_value;
1726
0
}
1727
1728
PyDoc_STRVAR(datetime_datetime_isoformat__doc__,
1729
"isoformat($self, /, sep=\'T\', timespec=\'auto\')\n"
1730
"--\n"
1731
"\n"
1732
"Return the time formatted according to ISO.\n"
1733
"\n"
1734
"The full format looks like \'YYYY-MM-DD HH:MM:SS.mmmmmm\'.\n"
1735
"By default, the fractional part is omitted if self.microsecond == 0.\n"
1736
"\n"
1737
"If self.tzinfo is not None, the UTC offset is also attached, giving\n"
1738
"a full format of \'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM\'.\n"
1739
"\n"
1740
"Optional argument sep specifies the separator between date and\n"
1741
"time, default \'T\'.\n"
1742
"\n"
1743
"The optional argument timespec specifies the number of additional\n"
1744
"terms of the time to include. Valid options are \'auto\', \'hours\',\n"
1745
"\'minutes\', \'seconds\', \'milliseconds\' and \'microseconds\'.");
1746
1747
#define DATETIME_DATETIME_ISOFORMAT_METHODDEF    \
1748
    {"isoformat", _PyCFunction_CAST(datetime_datetime_isoformat), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_isoformat__doc__},
1749
1750
static PyObject *
1751
datetime_datetime_isoformat_impl(PyDateTime_DateTime *self, int sep,
1752
                                 const char *timespec);
1753
1754
static PyObject *
1755
datetime_datetime_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1756
0
{
1757
0
    PyObject *return_value = NULL;
1758
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1759
1760
0
    #define NUM_KEYWORDS 2
1761
0
    static struct {
1762
0
        PyGC_Head _this_is_not_used;
1763
0
        PyObject_VAR_HEAD
1764
0
        Py_hash_t ob_hash;
1765
0
        PyObject *ob_item[NUM_KEYWORDS];
1766
0
    } _kwtuple = {
1767
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1768
0
        .ob_hash = -1,
1769
0
        .ob_item = { &_Py_ID(sep), &_Py_ID(timespec), },
1770
0
    };
1771
0
    #undef NUM_KEYWORDS
1772
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1773
1774
    #else  // !Py_BUILD_CORE
1775
    #  define KWTUPLE NULL
1776
    #endif  // !Py_BUILD_CORE
1777
1778
0
    static const char * const _keywords[] = {"sep", "timespec", NULL};
1779
0
    static _PyArg_Parser _parser = {
1780
0
        .keywords = _keywords,
1781
0
        .fname = "isoformat",
1782
0
        .kwtuple = KWTUPLE,
1783
0
    };
1784
0
    #undef KWTUPLE
1785
0
    PyObject *argsbuf[2];
1786
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1787
0
    int sep = 'T';
1788
0
    const char *timespec = NULL;
1789
1790
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1791
0
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1792
0
    if (!args) {
1793
0
        goto exit;
1794
0
    }
1795
0
    if (!noptargs) {
1796
0
        goto skip_optional_pos;
1797
0
    }
1798
0
    if (args[0]) {
1799
0
        if (!PyUnicode_Check(args[0])) {
1800
0
            _PyArg_BadArgument("isoformat", "argument 'sep'", "a unicode character", args[0]);
1801
0
            goto exit;
1802
0
        }
1803
0
        if (PyUnicode_GET_LENGTH(args[0]) != 1) {
1804
0
            PyErr_Format(PyExc_TypeError,
1805
0
                "isoformat(): argument 'sep' must be a unicode character, "
1806
0
                "not a string of length %zd",
1807
0
                PyUnicode_GET_LENGTH(args[0]));
1808
0
            goto exit;
1809
0
        }
1810
0
        sep = PyUnicode_READ_CHAR(args[0], 0);
1811
0
        if (!--noptargs) {
1812
0
            goto skip_optional_pos;
1813
0
        }
1814
0
    }
1815
0
    if (!PyUnicode_Check(args[1])) {
1816
0
        _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[1]);
1817
0
        goto exit;
1818
0
    }
1819
0
    Py_ssize_t timespec_length;
1820
0
    timespec = PyUnicode_AsUTF8AndSize(args[1], &timespec_length);
1821
0
    if (timespec == NULL) {
1822
0
        goto exit;
1823
0
    }
1824
0
    if (strlen(timespec) != (size_t)timespec_length) {
1825
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
1826
0
        goto exit;
1827
0
    }
1828
0
skip_optional_pos:
1829
0
    return_value = datetime_datetime_isoformat_impl((PyDateTime_DateTime *)self, sep, timespec);
1830
1831
0
exit:
1832
0
    return return_value;
1833
0
}
1834
1835
PyDoc_STRVAR(datetime_datetime_replace__doc__,
1836
"replace($self, /, year=unchanged, month=unchanged, day=unchanged,\n"
1837
"        hour=unchanged, minute=unchanged, second=unchanged,\n"
1838
"        microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
1839
"--\n"
1840
"\n"
1841
"Return datetime with new specified fields.");
1842
1843
#define DATETIME_DATETIME_REPLACE_METHODDEF    \
1844
    {"replace", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_replace__doc__},
1845
1846
static PyObject *
1847
datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year,
1848
                               int month, int day, int hour, int minute,
1849
                               int second, int microsecond, PyObject *tzinfo,
1850
                               int fold);
1851
1852
static PyObject *
1853
datetime_datetime_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1854
0
{
1855
0
    PyObject *return_value = NULL;
1856
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1857
1858
0
    #define NUM_KEYWORDS 9
1859
0
    static struct {
1860
0
        PyGC_Head _this_is_not_used;
1861
0
        PyObject_VAR_HEAD
1862
0
        Py_hash_t ob_hash;
1863
0
        PyObject *ob_item[NUM_KEYWORDS];
1864
0
    } _kwtuple = {
1865
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1866
0
        .ob_hash = -1,
1867
0
        .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), },
1868
0
    };
1869
0
    #undef NUM_KEYWORDS
1870
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1871
1872
    #else  // !Py_BUILD_CORE
1873
    #  define KWTUPLE NULL
1874
    #endif  // !Py_BUILD_CORE
1875
1876
0
    static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1877
0
    static _PyArg_Parser _parser = {
1878
0
        .keywords = _keywords,
1879
0
        .fname = "replace",
1880
0
        .kwtuple = KWTUPLE,
1881
0
    };
1882
0
    #undef KWTUPLE
1883
0
    PyObject *argsbuf[9];
1884
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1885
0
    int year = GET_YEAR(self);
1886
0
    int month = GET_MONTH(self);
1887
0
    int day = GET_DAY(self);
1888
0
    int hour = DATE_GET_HOUR(self);
1889
0
    int minute = DATE_GET_MINUTE(self);
1890
0
    int second = DATE_GET_SECOND(self);
1891
0
    int microsecond = DATE_GET_MICROSECOND(self);
1892
0
    PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None;
1893
0
    int fold = DATE_GET_FOLD(self);
1894
1895
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1896
0
            /*minpos*/ 0, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1897
0
    if (!args) {
1898
0
        goto exit;
1899
0
    }
1900
0
    if (!noptargs) {
1901
0
        goto skip_optional_pos;
1902
0
    }
1903
0
    if (args[0]) {
1904
0
        year = PyLong_AsInt(args[0]);
1905
0
        if (year == -1 && PyErr_Occurred()) {
1906
0
            goto exit;
1907
0
        }
1908
0
        if (!--noptargs) {
1909
0
            goto skip_optional_pos;
1910
0
        }
1911
0
    }
1912
0
    if (args[1]) {
1913
0
        month = PyLong_AsInt(args[1]);
1914
0
        if (month == -1 && PyErr_Occurred()) {
1915
0
            goto exit;
1916
0
        }
1917
0
        if (!--noptargs) {
1918
0
            goto skip_optional_pos;
1919
0
        }
1920
0
    }
1921
0
    if (args[2]) {
1922
0
        day = PyLong_AsInt(args[2]);
1923
0
        if (day == -1 && PyErr_Occurred()) {
1924
0
            goto exit;
1925
0
        }
1926
0
        if (!--noptargs) {
1927
0
            goto skip_optional_pos;
1928
0
        }
1929
0
    }
1930
0
    if (args[3]) {
1931
0
        hour = PyLong_AsInt(args[3]);
1932
0
        if (hour == -1 && PyErr_Occurred()) {
1933
0
            goto exit;
1934
0
        }
1935
0
        if (!--noptargs) {
1936
0
            goto skip_optional_pos;
1937
0
        }
1938
0
    }
1939
0
    if (args[4]) {
1940
0
        minute = PyLong_AsInt(args[4]);
1941
0
        if (minute == -1 && PyErr_Occurred()) {
1942
0
            goto exit;
1943
0
        }
1944
0
        if (!--noptargs) {
1945
0
            goto skip_optional_pos;
1946
0
        }
1947
0
    }
1948
0
    if (args[5]) {
1949
0
        second = PyLong_AsInt(args[5]);
1950
0
        if (second == -1 && PyErr_Occurred()) {
1951
0
            goto exit;
1952
0
        }
1953
0
        if (!--noptargs) {
1954
0
            goto skip_optional_pos;
1955
0
        }
1956
0
    }
1957
0
    if (args[6]) {
1958
0
        microsecond = PyLong_AsInt(args[6]);
1959
0
        if (microsecond == -1 && PyErr_Occurred()) {
1960
0
            goto exit;
1961
0
        }
1962
0
        if (!--noptargs) {
1963
0
            goto skip_optional_pos;
1964
0
        }
1965
0
    }
1966
0
    if (args[7]) {
1967
0
        tzinfo = args[7];
1968
0
        if (!--noptargs) {
1969
0
            goto skip_optional_pos;
1970
0
        }
1971
0
    }
1972
0
skip_optional_pos:
1973
0
    if (!noptargs) {
1974
0
        goto skip_optional_kwonly;
1975
0
    }
1976
0
    fold = PyLong_AsInt(args[8]);
1977
0
    if (fold == -1 && PyErr_Occurred()) {
1978
0
        goto exit;
1979
0
    }
1980
0
skip_optional_kwonly:
1981
0
    return_value = datetime_datetime_replace_impl((PyDateTime_DateTime *)self, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
1982
1983
0
exit:
1984
0
    return return_value;
1985
0
}
1986
1987
PyDoc_STRVAR(datetime_datetime_astimezone__doc__,
1988
"astimezone($self, /, tz=None)\n"
1989
"--\n"
1990
"\n"
1991
"Convert to local time in new timezone tz.");
1992
1993
#define DATETIME_DATETIME_ASTIMEZONE_METHODDEF    \
1994
    {"astimezone", _PyCFunction_CAST(datetime_datetime_astimezone), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_astimezone__doc__},
1995
1996
static PyObject *
1997
datetime_datetime_astimezone_impl(PyDateTime_DateTime *self,
1998
                                  PyObject *tzinfo);
1999
2000
static PyObject *
2001
datetime_datetime_astimezone(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2002
0
{
2003
0
    PyObject *return_value = NULL;
2004
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2005
2006
0
    #define NUM_KEYWORDS 1
2007
0
    static struct {
2008
0
        PyGC_Head _this_is_not_used;
2009
0
        PyObject_VAR_HEAD
2010
0
        Py_hash_t ob_hash;
2011
0
        PyObject *ob_item[NUM_KEYWORDS];
2012
0
    } _kwtuple = {
2013
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2014
0
        .ob_hash = -1,
2015
0
        .ob_item = { &_Py_ID(tz), },
2016
0
    };
2017
0
    #undef NUM_KEYWORDS
2018
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2019
2020
    #else  // !Py_BUILD_CORE
2021
    #  define KWTUPLE NULL
2022
    #endif  // !Py_BUILD_CORE
2023
2024
0
    static const char * const _keywords[] = {"tz", NULL};
2025
0
    static _PyArg_Parser _parser = {
2026
0
        .keywords = _keywords,
2027
0
        .fname = "astimezone",
2028
0
        .kwtuple = KWTUPLE,
2029
0
    };
2030
0
    #undef KWTUPLE
2031
0
    PyObject *argsbuf[1];
2032
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
2033
0
    PyObject *tzinfo = Py_None;
2034
2035
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2036
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2037
0
    if (!args) {
2038
0
        goto exit;
2039
0
    }
2040
0
    if (!noptargs) {
2041
0
        goto skip_optional_pos;
2042
0
    }
2043
0
    tzinfo = args[0];
2044
0
skip_optional_pos:
2045
0
    return_value = datetime_datetime_astimezone_impl((PyDateTime_DateTime *)self, tzinfo);
2046
2047
0
exit:
2048
0
    return return_value;
2049
0
}
2050
2051
PyDoc_STRVAR(datetime_datetime___reduce_ex____doc__,
2052
"__reduce_ex__($self, proto, /)\n"
2053
"--\n"
2054
"\n");
2055
2056
#define DATETIME_DATETIME___REDUCE_EX___METHODDEF    \
2057
    {"__reduce_ex__", (PyCFunction)datetime_datetime___reduce_ex__, METH_O, datetime_datetime___reduce_ex____doc__},
2058
2059
static PyObject *
2060
datetime_datetime___reduce_ex___impl(PyDateTime_DateTime *self, int proto);
2061
2062
static PyObject *
2063
datetime_datetime___reduce_ex__(PyObject *self, PyObject *arg)
2064
0
{
2065
0
    PyObject *return_value = NULL;
2066
0
    int proto;
2067
2068
0
    proto = PyLong_AsInt(arg);
2069
0
    if (proto == -1 && PyErr_Occurred()) {
2070
0
        goto exit;
2071
0
    }
2072
0
    return_value = datetime_datetime___reduce_ex___impl((PyDateTime_DateTime *)self, proto);
2073
2074
0
exit:
2075
0
    return return_value;
2076
0
}
2077
2078
PyDoc_STRVAR(datetime_datetime___reduce____doc__,
2079
"__reduce__($self, /)\n"
2080
"--\n"
2081
"\n");
2082
2083
#define DATETIME_DATETIME___REDUCE___METHODDEF    \
2084
    {"__reduce__", (PyCFunction)datetime_datetime___reduce__, METH_NOARGS, datetime_datetime___reduce____doc__},
2085
2086
static PyObject *
2087
datetime_datetime___reduce___impl(PyDateTime_DateTime *self);
2088
2089
static PyObject *
2090
datetime_datetime___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
2091
0
{
2092
0
    return datetime_datetime___reduce___impl((PyDateTime_DateTime *)self);
2093
0
}
2094
/*[clinic end generated code: output=8f63509398651723 input=a9049054013a1b77]*/