Coverage Report

Created: 2026-02-26 06:53

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
31
{
29
31
    PyObject *return_value = NULL;
30
31
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
31
32
31
    #define NUM_KEYWORDS 7
33
31
    static struct {
34
31
        PyGC_Head _this_is_not_used;
35
31
        PyObject_VAR_HEAD
36
31
        Py_hash_t ob_hash;
37
31
        PyObject *ob_item[NUM_KEYWORDS];
38
31
    } _kwtuple = {
39
31
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
40
31
        .ob_hash = -1,
41
31
        .ob_item = { &_Py_ID(days), &_Py_ID(seconds), &_Py_ID(microseconds), &_Py_ID(milliseconds), &_Py_ID(minutes), &_Py_ID(hours), &_Py_ID(weeks), },
42
31
    };
43
31
    #undef NUM_KEYWORDS
44
31
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
45
46
    #else  // !Py_BUILD_CORE
47
    #  define KWTUPLE NULL
48
    #endif  // !Py_BUILD_CORE
49
50
31
    static const char * const _keywords[] = {"days", "seconds", "microseconds", "milliseconds", "minutes", "hours", "weeks", NULL};
51
31
    static _PyArg_Parser _parser = {
52
31
        .keywords = _keywords,
53
31
        .fname = "timedelta",
54
31
        .kwtuple = KWTUPLE,
55
31
    };
56
31
    #undef KWTUPLE
57
31
    PyObject *argsbuf[7];
58
31
    PyObject * const *fastargs;
59
31
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
60
31
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
61
31
    PyObject *days = NULL;
62
31
    PyObject *seconds = NULL;
63
31
    PyObject *microseconds = NULL;
64
31
    PyObject *milliseconds = NULL;
65
31
    PyObject *minutes = NULL;
66
31
    PyObject *hours = NULL;
67
31
    PyObject *weeks = NULL;
68
69
31
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
70
31
            /*minpos*/ 0, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
71
31
    if (!fastargs) {
72
0
        goto exit;
73
0
    }
74
31
    if (!noptargs) {
75
0
        goto skip_optional_pos;
76
0
    }
77
31
    if (fastargs[0]) {
78
4
        days = fastargs[0];
79
4
        if (!--noptargs) {
80
4
            goto skip_optional_pos;
81
4
        }
82
4
    }
83
27
    if (fastargs[1]) {
84
25
        seconds = fastargs[1];
85
25
        if (!--noptargs) {
86
25
            goto skip_optional_pos;
87
25
        }
88
25
    }
89
2
    if (fastargs[2]) {
90
0
        microseconds = fastargs[2];
91
0
        if (!--noptargs) {
92
0
            goto skip_optional_pos;
93
0
        }
94
0
    }
95
2
    if (fastargs[3]) {
96
2
        milliseconds = fastargs[3];
97
2
        if (!--noptargs) {
98
2
            goto skip_optional_pos;
99
2
        }
100
2
    }
101
0
    if (fastargs[4]) {
102
0
        minutes = fastargs[4];
103
0
        if (!--noptargs) {
104
0
            goto skip_optional_pos;
105
0
        }
106
0
    }
107
0
    if (fastargs[5]) {
108
0
        hours = fastargs[5];
109
0
        if (!--noptargs) {
110
0
            goto skip_optional_pos;
111
0
        }
112
0
    }
113
0
    weeks = fastargs[6];
114
31
skip_optional_pos:
115
31
    return_value = delta_new_impl(type, days, seconds, microseconds, milliseconds, minutes, hours, weeks);
116
117
31
exit:
118
31
    return return_value;
119
31
}
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
131
{
133
131
    PyObject *return_value = NULL;
134
131
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
135
136
131
    #define NUM_KEYWORDS 3
137
131
    static struct {
138
131
        PyGC_Head _this_is_not_used;
139
131
        PyObject_VAR_HEAD
140
131
        Py_hash_t ob_hash;
141
131
        PyObject *ob_item[NUM_KEYWORDS];
142
131
    } _kwtuple = {
143
131
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
144
131
        .ob_hash = -1,
145
131
        .ob_item = { &_Py_ID(year), &_Py_ID(month), &_Py_ID(day), },
146
131
    };
147
131
    #undef NUM_KEYWORDS
148
131
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
149
150
    #else  // !Py_BUILD_CORE
151
    #  define KWTUPLE NULL
152
    #endif  // !Py_BUILD_CORE
153
154
131
    static const char * const _keywords[] = {"year", "month", "day", NULL};
155
131
    static _PyArg_Parser _parser = {
156
131
        .keywords = _keywords,
157
131
        .fname = "date",
158
131
        .kwtuple = KWTUPLE,
159
131
    };
160
131
    #undef KWTUPLE
161
131
    PyObject *argsbuf[3];
162
131
    PyObject * const *fastargs;
163
131
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
164
131
    int year;
165
131
    int month;
166
131
    int day;
167
168
131
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
169
131
            /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
170
131
    if (!fastargs) {
171
0
        goto exit;
172
0
    }
173
131
    year = PyLong_AsInt(fastargs[0]);
174
131
    if (year == -1 && PyErr_Occurred()) {
175
0
        goto exit;
176
0
    }
177
131
    month = PyLong_AsInt(fastargs[1]);
178
131
    if (month == -1 && PyErr_Occurred()) {
179
0
        goto exit;
180
0
    }
181
131
    day = PyLong_AsInt(fastargs[2]);
182
131
    if (day == -1 && PyErr_Occurred()) {
183
0
        goto exit;
184
0
    }
185
131
    return_value = datetime_date_impl(type, year, month, day);
186
187
131
exit:
188
131
    return return_value;
189
131
}
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 interpreted\n"
218
"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
96
{
432
96
    PyObject *return_value = NULL;
433
96
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
434
435
96
    #define NUM_KEYWORDS 1
436
96
    static struct {
437
96
        PyGC_Head _this_is_not_used;
438
96
        PyObject_VAR_HEAD
439
96
        Py_hash_t ob_hash;
440
96
        PyObject *ob_item[NUM_KEYWORDS];
441
96
    } _kwtuple = {
442
96
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
443
96
        .ob_hash = -1,
444
96
        .ob_item = { &_Py_ID(format), },
445
96
    };
446
96
    #undef NUM_KEYWORDS
447
96
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
448
449
    #else  // !Py_BUILD_CORE
450
    #  define KWTUPLE NULL
451
    #endif  // !Py_BUILD_CORE
452
453
96
    static const char * const _keywords[] = {"format", NULL};
454
96
    static _PyArg_Parser _parser = {
455
96
        .keywords = _keywords,
456
96
        .fname = "strftime",
457
96
        .kwtuple = KWTUPLE,
458
96
    };
459
96
    #undef KWTUPLE
460
96
    PyObject *argsbuf[1];
461
96
    PyObject *format;
462
463
96
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
464
96
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
465
96
    if (!args) {
466
0
        goto exit;
467
0
    }
468
96
    if (!PyUnicode_Check(args[0])) {
469
0
        _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]);
470
0
        goto exit;
471
0
    }
472
96
    format = args[0];
473
96
    return_value = datetime_date_strftime_impl(self, format);
474
475
96
exit:
476
96
    return return_value;
477
96
}
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
0
{
672
0
    PyObject *return_value = NULL;
673
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
674
675
0
    #define NUM_KEYWORDS 2
676
0
    static struct {
677
0
        PyGC_Head _this_is_not_used;
678
0
        PyObject_VAR_HEAD
679
0
        Py_hash_t ob_hash;
680
0
        PyObject *ob_item[NUM_KEYWORDS];
681
0
    } _kwtuple = {
682
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
683
0
        .ob_hash = -1,
684
0
        .ob_item = { &_Py_ID(offset), &_Py_ID(name), },
685
0
    };
686
0
    #undef NUM_KEYWORDS
687
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
688
689
    #else  // !Py_BUILD_CORE
690
    #  define KWTUPLE NULL
691
    #endif  // !Py_BUILD_CORE
692
693
0
    static const char * const _keywords[] = {"offset", "name", NULL};
694
0
    static _PyArg_Parser _parser = {
695
0
        .keywords = _keywords,
696
0
        .fname = "timezone",
697
0
        .kwtuple = KWTUPLE,
698
0
    };
699
0
    #undef KWTUPLE
700
0
    PyObject *argsbuf[2];
701
0
    PyObject * const *fastargs;
702
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
703
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
704
0
    PyObject *offset;
705
0
    PyObject *name = NULL;
706
707
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
708
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
709
0
    if (!fastargs) {
710
0
        goto exit;
711
0
    }
712
0
    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
0
    offset = fastargs[0];
717
0
    if (!noptargs) {
718
0
        goto skip_optional_pos;
719
0
    }
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
0
skip_optional_pos:
726
0
    return_value = timezone_new_impl(type, offset, name);
727
728
0
exit:
729
0
    return return_value;
730
0
}
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
135
{
748
135
    PyObject *return_value = NULL;
749
135
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
750
751
135
    #define NUM_KEYWORDS 6
752
135
    static struct {
753
135
        PyGC_Head _this_is_not_used;
754
135
        PyObject_VAR_HEAD
755
135
        Py_hash_t ob_hash;
756
135
        PyObject *ob_item[NUM_KEYWORDS];
757
135
    } _kwtuple = {
758
135
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
759
135
        .ob_hash = -1,
760
135
        .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
761
135
    };
762
135
    #undef NUM_KEYWORDS
763
135
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
764
765
    #else  // !Py_BUILD_CORE
766
    #  define KWTUPLE NULL
767
    #endif  // !Py_BUILD_CORE
768
769
135
    static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
770
135
    static _PyArg_Parser _parser = {
771
135
        .keywords = _keywords,
772
135
        .fname = "time",
773
135
        .kwtuple = KWTUPLE,
774
135
    };
775
135
    #undef KWTUPLE
776
135
    PyObject *argsbuf[6];
777
135
    PyObject * const *fastargs;
778
135
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
779
135
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
780
135
    int hour = 0;
781
135
    int minute = 0;
782
135
    int second = 0;
783
135
    int microsecond = 0;
784
135
    PyObject *tzinfo = Py_None;
785
135
    int fold = 0;
786
787
135
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
788
135
            /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
789
135
    if (!fastargs) {
790
0
        goto exit;
791
0
    }
792
135
    if (!noptargs) {
793
0
        goto skip_optional_pos;
794
0
    }
795
135
    if (fastargs[0]) {
796
135
        hour = PyLong_AsInt(fastargs[0]);
797
135
        if (hour == -1 && PyErr_Occurred()) {
798
0
            goto exit;
799
0
        }
800
135
        if (!--noptargs) {
801
0
            goto skip_optional_pos;
802
0
        }
803
135
    }
804
135
    if (fastargs[1]) {
805
135
        minute = PyLong_AsInt(fastargs[1]);
806
135
        if (minute == -1 && PyErr_Occurred()) {
807
0
            goto exit;
808
0
        }
809
135
        if (!--noptargs) {
810
0
            goto skip_optional_pos;
811
0
        }
812
135
    }
813
135
    if (fastargs[2]) {
814
135
        second = PyLong_AsInt(fastargs[2]);
815
135
        if (second == -1 && PyErr_Occurred()) {
816
0
            goto exit;
817
0
        }
818
135
        if (!--noptargs) {
819
0
            goto skip_optional_pos;
820
0
        }
821
135
    }
822
135
    if (fastargs[3]) {
823
135
        microsecond = PyLong_AsInt(fastargs[3]);
824
135
        if (microsecond == -1 && PyErr_Occurred()) {
825
0
            goto exit;
826
0
        }
827
135
        if (!--noptargs) {
828
135
            goto skip_optional_pos;
829
135
        }
830
135
    }
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
135
skip_optional_pos:
838
135
    if (!noptargs) {
839
135
        goto skip_optional_kwonly;
840
135
    }
841
0
    fold = PyLong_AsInt(fastargs[5]);
842
0
    if (fold == -1 && PyErr_Occurred()) {
843
0
        goto exit;
844
0
    }
845
135
skip_optional_kwonly:
846
135
    return_value = datetime_time_impl(type, hour, minute, second, microsecond, tzinfo, fold);
847
848
135
exit:
849
135
    return return_value;
850
135
}
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 fractional\n"
901
"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 not be used.\n"
983
"\n"
984
"For a list of supported format codes, see the documentation:\n"
985
"    https://docs.python.org/3/library/datetime.html#format-codes");
986
987
#define DATETIME_TIME_STRFTIME_METHODDEF    \
988
    {"strftime", _PyCFunction_CAST(datetime_time_strftime), METH_FASTCALL|METH_KEYWORDS, datetime_time_strftime__doc__},
989
990
static PyObject *
991
datetime_time_strftime_impl(PyDateTime_Time *self, PyObject *format);
992
993
static PyObject *
994
datetime_time_strftime(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
995
0
{
996
0
    PyObject *return_value = NULL;
997
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
998
999
0
    #define NUM_KEYWORDS 1
1000
0
    static struct {
1001
0
        PyGC_Head _this_is_not_used;
1002
0
        PyObject_VAR_HEAD
1003
0
        Py_hash_t ob_hash;
1004
0
        PyObject *ob_item[NUM_KEYWORDS];
1005
0
    } _kwtuple = {
1006
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1007
0
        .ob_hash = -1,
1008
0
        .ob_item = { &_Py_ID(format), },
1009
0
    };
1010
0
    #undef NUM_KEYWORDS
1011
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1012
1013
    #else  // !Py_BUILD_CORE
1014
    #  define KWTUPLE NULL
1015
    #endif  // !Py_BUILD_CORE
1016
1017
0
    static const char * const _keywords[] = {"format", NULL};
1018
0
    static _PyArg_Parser _parser = {
1019
0
        .keywords = _keywords,
1020
0
        .fname = "strftime",
1021
0
        .kwtuple = KWTUPLE,
1022
0
    };
1023
0
    #undef KWTUPLE
1024
0
    PyObject *argsbuf[1];
1025
0
    PyObject *format;
1026
1027
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1028
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1029
0
    if (!args) {
1030
0
        goto exit;
1031
0
    }
1032
0
    if (!PyUnicode_Check(args[0])) {
1033
0
        _PyArg_BadArgument("strftime", "argument 'format'", "str", args[0]);
1034
0
        goto exit;
1035
0
    }
1036
0
    format = args[0];
1037
0
    return_value = datetime_time_strftime_impl((PyDateTime_Time *)self, format);
1038
1039
0
exit:
1040
0
    return return_value;
1041
0
}
1042
1043
PyDoc_STRVAR(datetime_time___format____doc__,
1044
"__format__($self, format, /)\n"
1045
"--\n"
1046
"\n"
1047
"Formats self with strftime.");
1048
1049
#define DATETIME_TIME___FORMAT___METHODDEF    \
1050
    {"__format__", (PyCFunction)datetime_time___format__, METH_O, datetime_time___format____doc__},
1051
1052
static PyObject *
1053
datetime_time___format___impl(PyObject *self, PyObject *format);
1054
1055
static PyObject *
1056
datetime_time___format__(PyObject *self, PyObject *arg)
1057
0
{
1058
0
    PyObject *return_value = NULL;
1059
0
    PyObject *format;
1060
1061
0
    if (!PyUnicode_Check(arg)) {
1062
0
        _PyArg_BadArgument("__format__", "argument", "str", arg);
1063
0
        goto exit;
1064
0
    }
1065
0
    format = arg;
1066
0
    return_value = datetime_time___format___impl(self, format);
1067
1068
0
exit:
1069
0
    return return_value;
1070
0
}
1071
1072
PyDoc_STRVAR(datetime_time_replace__doc__,
1073
"replace($self, /, hour=unchanged, minute=unchanged, second=unchanged,\n"
1074
"        microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
1075
"--\n"
1076
"\n"
1077
"Return time with new specified fields.");
1078
1079
#define DATETIME_TIME_REPLACE_METHODDEF    \
1080
    {"replace", _PyCFunction_CAST(datetime_time_replace), METH_FASTCALL|METH_KEYWORDS, datetime_time_replace__doc__},
1081
1082
static PyObject *
1083
datetime_time_replace_impl(PyDateTime_Time *self, int hour, int minute,
1084
                           int second, int microsecond, PyObject *tzinfo,
1085
                           int fold);
1086
1087
static PyObject *
1088
datetime_time_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1089
0
{
1090
0
    PyObject *return_value = NULL;
1091
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1092
1093
0
    #define NUM_KEYWORDS 6
1094
0
    static struct {
1095
0
        PyGC_Head _this_is_not_used;
1096
0
        PyObject_VAR_HEAD
1097
0
        Py_hash_t ob_hash;
1098
0
        PyObject *ob_item[NUM_KEYWORDS];
1099
0
    } _kwtuple = {
1100
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1101
0
        .ob_hash = -1,
1102
0
        .ob_item = { &_Py_ID(hour), &_Py_ID(minute), &_Py_ID(second), &_Py_ID(microsecond), &_Py_ID(tzinfo), &_Py_ID(fold), },
1103
0
    };
1104
0
    #undef NUM_KEYWORDS
1105
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1106
1107
    #else  // !Py_BUILD_CORE
1108
    #  define KWTUPLE NULL
1109
    #endif  // !Py_BUILD_CORE
1110
1111
0
    static const char * const _keywords[] = {"hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1112
0
    static _PyArg_Parser _parser = {
1113
0
        .keywords = _keywords,
1114
0
        .fname = "replace",
1115
0
        .kwtuple = KWTUPLE,
1116
0
    };
1117
0
    #undef KWTUPLE
1118
0
    PyObject *argsbuf[6];
1119
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1120
0
    int hour = TIME_GET_HOUR(self);
1121
0
    int minute = TIME_GET_MINUTE(self);
1122
0
    int second = TIME_GET_SECOND(self);
1123
0
    int microsecond = TIME_GET_MICROSECOND(self);
1124
0
    PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_Time *)self)->tzinfo : Py_None;
1125
0
    int fold = TIME_GET_FOLD(self);
1126
1127
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1128
0
            /*minpos*/ 0, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1129
0
    if (!args) {
1130
0
        goto exit;
1131
0
    }
1132
0
    if (!noptargs) {
1133
0
        goto skip_optional_pos;
1134
0
    }
1135
0
    if (args[0]) {
1136
0
        hour = PyLong_AsInt(args[0]);
1137
0
        if (hour == -1 && PyErr_Occurred()) {
1138
0
            goto exit;
1139
0
        }
1140
0
        if (!--noptargs) {
1141
0
            goto skip_optional_pos;
1142
0
        }
1143
0
    }
1144
0
    if (args[1]) {
1145
0
        minute = PyLong_AsInt(args[1]);
1146
0
        if (minute == -1 && PyErr_Occurred()) {
1147
0
            goto exit;
1148
0
        }
1149
0
        if (!--noptargs) {
1150
0
            goto skip_optional_pos;
1151
0
        }
1152
0
    }
1153
0
    if (args[2]) {
1154
0
        second = PyLong_AsInt(args[2]);
1155
0
        if (second == -1 && PyErr_Occurred()) {
1156
0
            goto exit;
1157
0
        }
1158
0
        if (!--noptargs) {
1159
0
            goto skip_optional_pos;
1160
0
        }
1161
0
    }
1162
0
    if (args[3]) {
1163
0
        microsecond = PyLong_AsInt(args[3]);
1164
0
        if (microsecond == -1 && PyErr_Occurred()) {
1165
0
            goto exit;
1166
0
        }
1167
0
        if (!--noptargs) {
1168
0
            goto skip_optional_pos;
1169
0
        }
1170
0
    }
1171
0
    if (args[4]) {
1172
0
        tzinfo = args[4];
1173
0
        if (!--noptargs) {
1174
0
            goto skip_optional_pos;
1175
0
        }
1176
0
    }
1177
0
skip_optional_pos:
1178
0
    if (!noptargs) {
1179
0
        goto skip_optional_kwonly;
1180
0
    }
1181
0
    fold = PyLong_AsInt(args[5]);
1182
0
    if (fold == -1 && PyErr_Occurred()) {
1183
0
        goto exit;
1184
0
    }
1185
0
skip_optional_kwonly:
1186
0
    return_value = datetime_time_replace_impl((PyDateTime_Time *)self, hour, minute, second, microsecond, tzinfo, fold);
1187
1188
0
exit:
1189
0
    return return_value;
1190
0
}
1191
1192
PyDoc_STRVAR(datetime_time_fromisoformat__doc__,
1193
"fromisoformat($type, string, /)\n"
1194
"--\n"
1195
"\n"
1196
"Construct a time from a string in ISO 8601 format.");
1197
1198
#define DATETIME_TIME_FROMISOFORMAT_METHODDEF    \
1199
    {"fromisoformat", (PyCFunction)datetime_time_fromisoformat, METH_O|METH_CLASS, datetime_time_fromisoformat__doc__},
1200
1201
static PyObject *
1202
datetime_time_fromisoformat_impl(PyTypeObject *type, PyObject *string);
1203
1204
static PyObject *
1205
datetime_time_fromisoformat(PyObject *type, PyObject *arg)
1206
0
{
1207
0
    PyObject *return_value = NULL;
1208
0
    PyObject *string;
1209
1210
0
    if (!PyUnicode_Check(arg)) {
1211
0
        _PyArg_BadArgument("fromisoformat", "argument", "str", arg);
1212
0
        goto exit;
1213
0
    }
1214
0
    string = arg;
1215
0
    return_value = datetime_time_fromisoformat_impl((PyTypeObject *)type, string);
1216
1217
0
exit:
1218
0
    return return_value;
1219
0
}
1220
1221
PyDoc_STRVAR(datetime_time___reduce_ex____doc__,
1222
"__reduce_ex__($self, proto, /)\n"
1223
"--\n"
1224
"\n");
1225
1226
#define DATETIME_TIME___REDUCE_EX___METHODDEF    \
1227
    {"__reduce_ex__", (PyCFunction)datetime_time___reduce_ex__, METH_O, datetime_time___reduce_ex____doc__},
1228
1229
static PyObject *
1230
datetime_time___reduce_ex___impl(PyDateTime_Time *self, int proto);
1231
1232
static PyObject *
1233
datetime_time___reduce_ex__(PyObject *self, PyObject *arg)
1234
0
{
1235
0
    PyObject *return_value = NULL;
1236
0
    int proto;
1237
1238
0
    proto = PyLong_AsInt(arg);
1239
0
    if (proto == -1 && PyErr_Occurred()) {
1240
0
        goto exit;
1241
0
    }
1242
0
    return_value = datetime_time___reduce_ex___impl((PyDateTime_Time *)self, proto);
1243
1244
0
exit:
1245
0
    return return_value;
1246
0
}
1247
1248
PyDoc_STRVAR(datetime_time___reduce____doc__,
1249
"__reduce__($self, /)\n"
1250
"--\n"
1251
"\n");
1252
1253
#define DATETIME_TIME___REDUCE___METHODDEF    \
1254
    {"__reduce__", (PyCFunction)datetime_time___reduce__, METH_NOARGS, datetime_time___reduce____doc__},
1255
1256
static PyObject *
1257
datetime_time___reduce___impl(PyDateTime_Time *self);
1258
1259
static PyObject *
1260
datetime_time___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
1261
0
{
1262
0
    return datetime_time___reduce___impl((PyDateTime_Time *)self);
1263
0
}
1264
1265
PyDoc_STRVAR(datetime_datetime__doc__,
1266
"datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0,\n"
1267
"         tzinfo=None, *, fold=0)\n"
1268
"--\n"
1269
"\n"
1270
"A combination of a date and a time.\n"
1271
"\n"
1272
"The year, month and day arguments are required. tzinfo may be None, or an\n"
1273
"instance of a tzinfo subclass. The remaining arguments may be ints.");
1274
1275
static PyObject *
1276
datetime_datetime_impl(PyTypeObject *type, int year, int month, int day,
1277
                       int hour, int minute, int second, int microsecond,
1278
                       PyObject *tzinfo, int fold);
1279
1280
static PyObject *
1281
datetime_datetime(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1282
50
{
1283
50
    PyObject *return_value = NULL;
1284
50
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1285
1286
50
    #define NUM_KEYWORDS 9
1287
50
    static struct {
1288
50
        PyGC_Head _this_is_not_used;
1289
50
        PyObject_VAR_HEAD
1290
50
        Py_hash_t ob_hash;
1291
50
        PyObject *ob_item[NUM_KEYWORDS];
1292
50
    } _kwtuple = {
1293
50
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1294
50
        .ob_hash = -1,
1295
50
        .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), },
1296
50
    };
1297
50
    #undef NUM_KEYWORDS
1298
50
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1299
1300
    #else  // !Py_BUILD_CORE
1301
    #  define KWTUPLE NULL
1302
    #endif  // !Py_BUILD_CORE
1303
1304
50
    static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1305
50
    static _PyArg_Parser _parser = {
1306
50
        .keywords = _keywords,
1307
50
        .fname = "datetime",
1308
50
        .kwtuple = KWTUPLE,
1309
50
    };
1310
50
    #undef KWTUPLE
1311
50
    PyObject *argsbuf[9];
1312
50
    PyObject * const *fastargs;
1313
50
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1314
50
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 3;
1315
50
    int year;
1316
50
    int month;
1317
50
    int day;
1318
50
    int hour = 0;
1319
50
    int minute = 0;
1320
50
    int second = 0;
1321
50
    int microsecond = 0;
1322
50
    PyObject *tzinfo = Py_None;
1323
50
    int fold = 0;
1324
1325
50
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1326
50
            /*minpos*/ 3, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1327
50
    if (!fastargs) {
1328
0
        goto exit;
1329
0
    }
1330
50
    year = PyLong_AsInt(fastargs[0]);
1331
50
    if (year == -1 && PyErr_Occurred()) {
1332
0
        goto exit;
1333
0
    }
1334
50
    month = PyLong_AsInt(fastargs[1]);
1335
50
    if (month == -1 && PyErr_Occurred()) {
1336
0
        goto exit;
1337
0
    }
1338
50
    day = PyLong_AsInt(fastargs[2]);
1339
50
    if (day == -1 && PyErr_Occurred()) {
1340
0
        goto exit;
1341
0
    }
1342
50
    if (!noptargs) {
1343
13
        goto skip_optional_pos;
1344
13
    }
1345
37
    if (fastargs[3]) {
1346
37
        hour = PyLong_AsInt(fastargs[3]);
1347
37
        if (hour == -1 && PyErr_Occurred()) {
1348
0
            goto exit;
1349
0
        }
1350
37
        if (!--noptargs) {
1351
0
            goto skip_optional_pos;
1352
0
        }
1353
37
    }
1354
37
    if (fastargs[4]) {
1355
37
        minute = PyLong_AsInt(fastargs[4]);
1356
37
        if (minute == -1 && PyErr_Occurred()) {
1357
0
            goto exit;
1358
0
        }
1359
37
        if (!--noptargs) {
1360
0
            goto skip_optional_pos;
1361
0
        }
1362
37
    }
1363
37
    if (fastargs[5]) {
1364
37
        second = PyLong_AsInt(fastargs[5]);
1365
37
        if (second == -1 && PyErr_Occurred()) {
1366
0
            goto exit;
1367
0
        }
1368
37
        if (!--noptargs) {
1369
33
            goto skip_optional_pos;
1370
33
        }
1371
37
    }
1372
4
    if (fastargs[6]) {
1373
4
        microsecond = PyLong_AsInt(fastargs[6]);
1374
4
        if (microsecond == -1 && PyErr_Occurred()) {
1375
0
            goto exit;
1376
0
        }
1377
4
        if (!--noptargs) {
1378
0
            goto skip_optional_pos;
1379
0
        }
1380
4
    }
1381
4
    if (fastargs[7]) {
1382
4
        tzinfo = fastargs[7];
1383
4
        if (!--noptargs) {
1384
4
            goto skip_optional_pos;
1385
4
        }
1386
4
    }
1387
50
skip_optional_pos:
1388
50
    if (!noptargs) {
1389
50
        goto skip_optional_kwonly;
1390
50
    }
1391
0
    fold = PyLong_AsInt(fastargs[8]);
1392
0
    if (fold == -1 && PyErr_Occurred()) {
1393
0
        goto exit;
1394
0
    }
1395
50
skip_optional_kwonly:
1396
50
    return_value = datetime_datetime_impl(type, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
1397
1398
50
exit:
1399
50
    return return_value;
1400
50
}
1401
1402
PyDoc_STRVAR(datetime_datetime_now__doc__,
1403
"now($type, /, tz=None)\n"
1404
"--\n"
1405
"\n"
1406
"Returns new datetime object representing current time local to tz.\n"
1407
"\n"
1408
"  tz\n"
1409
"    Timezone object.\n"
1410
"\n"
1411
"If no tz is specified, uses local timezone.");
1412
1413
#define DATETIME_DATETIME_NOW_METHODDEF    \
1414
    {"now", _PyCFunction_CAST(datetime_datetime_now), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__},
1415
1416
static PyObject *
1417
datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz);
1418
1419
static PyObject *
1420
datetime_datetime_now(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1421
0
{
1422
0
    PyObject *return_value = NULL;
1423
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1424
1425
0
    #define NUM_KEYWORDS 1
1426
0
    static struct {
1427
0
        PyGC_Head _this_is_not_used;
1428
0
        PyObject_VAR_HEAD
1429
0
        Py_hash_t ob_hash;
1430
0
        PyObject *ob_item[NUM_KEYWORDS];
1431
0
    } _kwtuple = {
1432
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1433
0
        .ob_hash = -1,
1434
0
        .ob_item = { &_Py_ID(tz), },
1435
0
    };
1436
0
    #undef NUM_KEYWORDS
1437
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1438
1439
    #else  // !Py_BUILD_CORE
1440
    #  define KWTUPLE NULL
1441
    #endif  // !Py_BUILD_CORE
1442
1443
0
    static const char * const _keywords[] = {"tz", NULL};
1444
0
    static _PyArg_Parser _parser = {
1445
0
        .keywords = _keywords,
1446
0
        .fname = "now",
1447
0
        .kwtuple = KWTUPLE,
1448
0
    };
1449
0
    #undef KWTUPLE
1450
0
    PyObject *argsbuf[1];
1451
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1452
0
    PyObject *tz = Py_None;
1453
1454
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1455
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1456
0
    if (!args) {
1457
0
        goto exit;
1458
0
    }
1459
0
    if (!noptargs) {
1460
0
        goto skip_optional_pos;
1461
0
    }
1462
0
    tz = args[0];
1463
0
skip_optional_pos:
1464
0
    return_value = datetime_datetime_now_impl((PyTypeObject *)type, tz);
1465
1466
0
exit:
1467
0
    return return_value;
1468
0
}
1469
1470
PyDoc_STRVAR(datetime_datetime_utcnow__doc__,
1471
"utcnow($type, /)\n"
1472
"--\n"
1473
"\n"
1474
"Return a new datetime representing UTC day and time.");
1475
1476
#define DATETIME_DATETIME_UTCNOW_METHODDEF    \
1477
    {"utcnow", (PyCFunction)datetime_datetime_utcnow, METH_NOARGS|METH_CLASS, datetime_datetime_utcnow__doc__},
1478
1479
static PyObject *
1480
datetime_datetime_utcnow_impl(PyTypeObject *type);
1481
1482
static PyObject *
1483
datetime_datetime_utcnow(PyObject *type, PyObject *Py_UNUSED(ignored))
1484
0
{
1485
0
    return datetime_datetime_utcnow_impl((PyTypeObject *)type);
1486
0
}
1487
1488
PyDoc_STRVAR(datetime_datetime_fromtimestamp__doc__,
1489
"fromtimestamp($type, /, timestamp, tz=None)\n"
1490
"--\n"
1491
"\n"
1492
"Create a datetime from a POSIX timestamp.\n"
1493
"\n"
1494
"The timestamp is a number, e.g. created via time.time(), that is interpreted\n"
1495
"as local time.");
1496
1497
#define DATETIME_DATETIME_FROMTIMESTAMP_METHODDEF    \
1498
    {"fromtimestamp", _PyCFunction_CAST(datetime_datetime_fromtimestamp), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_fromtimestamp__doc__},
1499
1500
static PyObject *
1501
datetime_datetime_fromtimestamp_impl(PyTypeObject *type, PyObject *timestamp,
1502
                                     PyObject *tzinfo);
1503
1504
static PyObject *
1505
datetime_datetime_fromtimestamp(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1506
0
{
1507
0
    PyObject *return_value = NULL;
1508
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1509
1510
0
    #define NUM_KEYWORDS 2
1511
0
    static struct {
1512
0
        PyGC_Head _this_is_not_used;
1513
0
        PyObject_VAR_HEAD
1514
0
        Py_hash_t ob_hash;
1515
0
        PyObject *ob_item[NUM_KEYWORDS];
1516
0
    } _kwtuple = {
1517
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1518
0
        .ob_hash = -1,
1519
0
        .ob_item = { &_Py_ID(timestamp), &_Py_ID(tz), },
1520
0
    };
1521
0
    #undef NUM_KEYWORDS
1522
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1523
1524
    #else  // !Py_BUILD_CORE
1525
    #  define KWTUPLE NULL
1526
    #endif  // !Py_BUILD_CORE
1527
1528
0
    static const char * const _keywords[] = {"timestamp", "tz", NULL};
1529
0
    static _PyArg_Parser _parser = {
1530
0
        .keywords = _keywords,
1531
0
        .fname = "fromtimestamp",
1532
0
        .kwtuple = KWTUPLE,
1533
0
    };
1534
0
    #undef KWTUPLE
1535
0
    PyObject *argsbuf[2];
1536
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1537
0
    PyObject *timestamp;
1538
0
    PyObject *tzinfo = Py_None;
1539
1540
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1541
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1542
0
    if (!args) {
1543
0
        goto exit;
1544
0
    }
1545
0
    timestamp = args[0];
1546
0
    if (!noptargs) {
1547
0
        goto skip_optional_pos;
1548
0
    }
1549
0
    tzinfo = args[1];
1550
0
skip_optional_pos:
1551
0
    return_value = datetime_datetime_fromtimestamp_impl((PyTypeObject *)type, timestamp, tzinfo);
1552
1553
0
exit:
1554
0
    return return_value;
1555
0
}
1556
1557
PyDoc_STRVAR(datetime_datetime_utcfromtimestamp__doc__,
1558
"utcfromtimestamp($type, timestamp, /)\n"
1559
"--\n"
1560
"\n"
1561
"Create a naive UTC datetime from a POSIX timestamp.");
1562
1563
#define DATETIME_DATETIME_UTCFROMTIMESTAMP_METHODDEF    \
1564
    {"utcfromtimestamp", (PyCFunction)datetime_datetime_utcfromtimestamp, METH_O|METH_CLASS, datetime_datetime_utcfromtimestamp__doc__},
1565
1566
static PyObject *
1567
datetime_datetime_utcfromtimestamp_impl(PyTypeObject *type,
1568
                                        PyObject *timestamp);
1569
1570
static PyObject *
1571
datetime_datetime_utcfromtimestamp(PyObject *type, PyObject *timestamp)
1572
0
{
1573
0
    PyObject *return_value = NULL;
1574
1575
0
    return_value = datetime_datetime_utcfromtimestamp_impl((PyTypeObject *)type, timestamp);
1576
1577
0
    return return_value;
1578
0
}
1579
1580
PyDoc_STRVAR(datetime_datetime_strptime__doc__,
1581
"strptime($type, string, format, /)\n"
1582
"--\n"
1583
"\n"
1584
"Parse string according to the given date and time format (like time.strptime()).\n"
1585
"\n"
1586
"For a list of supported format codes, see the documentation:\n"
1587
"    https://docs.python.org/3/library/datetime.html#format-codes");
1588
1589
#define DATETIME_DATETIME_STRPTIME_METHODDEF    \
1590
    {"strptime", _PyCFunction_CAST(datetime_datetime_strptime), METH_FASTCALL|METH_CLASS, datetime_datetime_strptime__doc__},
1591
1592
static PyObject *
1593
datetime_datetime_strptime_impl(PyTypeObject *type, PyObject *string,
1594
                                PyObject *format);
1595
1596
static PyObject *
1597
datetime_datetime_strptime(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
1598
0
{
1599
0
    PyObject *return_value = NULL;
1600
0
    PyObject *string;
1601
0
    PyObject *format;
1602
1603
0
    if (!_PyArg_CheckPositional("strptime", nargs, 2, 2)) {
1604
0
        goto exit;
1605
0
    }
1606
0
    if (!PyUnicode_Check(args[0])) {
1607
0
        _PyArg_BadArgument("strptime", "argument 1", "str", args[0]);
1608
0
        goto exit;
1609
0
    }
1610
0
    string = args[0];
1611
0
    if (!PyUnicode_Check(args[1])) {
1612
0
        _PyArg_BadArgument("strptime", "argument 2", "str", args[1]);
1613
0
        goto exit;
1614
0
    }
1615
0
    format = args[1];
1616
0
    return_value = datetime_datetime_strptime_impl((PyTypeObject *)type, string, format);
1617
1618
0
exit:
1619
0
    return return_value;
1620
0
}
1621
1622
PyDoc_STRVAR(datetime_datetime_combine__doc__,
1623
"combine($type, /, date, time, tzinfo=<unrepresentable>)\n"
1624
"--\n"
1625
"\n"
1626
"Construct a datetime from a given date and a given time.");
1627
1628
#define DATETIME_DATETIME_COMBINE_METHODDEF    \
1629
    {"combine", _PyCFunction_CAST(datetime_datetime_combine), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_datetime_combine__doc__},
1630
1631
static PyObject *
1632
datetime_datetime_combine_impl(PyTypeObject *type, PyObject *date,
1633
                               PyObject *time, PyObject *tzinfo);
1634
1635
static PyObject *
1636
datetime_datetime_combine(PyObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1637
0
{
1638
0
    PyObject *return_value = NULL;
1639
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1640
1641
0
    #define NUM_KEYWORDS 3
1642
0
    static struct {
1643
0
        PyGC_Head _this_is_not_used;
1644
0
        PyObject_VAR_HEAD
1645
0
        Py_hash_t ob_hash;
1646
0
        PyObject *ob_item[NUM_KEYWORDS];
1647
0
    } _kwtuple = {
1648
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1649
0
        .ob_hash = -1,
1650
0
        .ob_item = { &_Py_ID(date), &_Py_ID(time), &_Py_ID(tzinfo), },
1651
0
    };
1652
0
    #undef NUM_KEYWORDS
1653
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1654
1655
    #else  // !Py_BUILD_CORE
1656
    #  define KWTUPLE NULL
1657
    #endif  // !Py_BUILD_CORE
1658
1659
0
    static const char * const _keywords[] = {"date", "time", "tzinfo", NULL};
1660
0
    static _PyArg_Parser _parser = {
1661
0
        .keywords = _keywords,
1662
0
        .fname = "combine",
1663
0
        .kwtuple = KWTUPLE,
1664
0
    };
1665
0
    #undef KWTUPLE
1666
0
    PyObject *argsbuf[3];
1667
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1668
0
    PyObject *date;
1669
0
    PyObject *time;
1670
0
    PyObject *tzinfo = NULL;
1671
1672
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1673
0
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1674
0
    if (!args) {
1675
0
        goto exit;
1676
0
    }
1677
0
    if (!PyObject_TypeCheck(args[0], DATE_TYPE(NO_STATE))) {
1678
0
        _PyArg_BadArgument("combine", "argument 'date'", (DATE_TYPE(NO_STATE))->tp_name, args[0]);
1679
0
        goto exit;
1680
0
    }
1681
0
    date = args[0];
1682
0
    if (!PyObject_TypeCheck(args[1], TIME_TYPE(NO_STATE))) {
1683
0
        _PyArg_BadArgument("combine", "argument 'time'", (TIME_TYPE(NO_STATE))->tp_name, args[1]);
1684
0
        goto exit;
1685
0
    }
1686
0
    time = args[1];
1687
0
    if (!noptargs) {
1688
0
        goto skip_optional_pos;
1689
0
    }
1690
0
    tzinfo = args[2];
1691
0
skip_optional_pos:
1692
0
    return_value = datetime_datetime_combine_impl((PyTypeObject *)type, date, time, tzinfo);
1693
1694
0
exit:
1695
0
    return return_value;
1696
0
}
1697
1698
PyDoc_STRVAR(datetime_datetime_fromisoformat__doc__,
1699
"fromisoformat($type, string, /)\n"
1700
"--\n"
1701
"\n"
1702
"Construct a date from a string in ISO 8601 format.");
1703
1704
#define DATETIME_DATETIME_FROMISOFORMAT_METHODDEF    \
1705
    {"fromisoformat", (PyCFunction)datetime_datetime_fromisoformat, METH_O|METH_CLASS, datetime_datetime_fromisoformat__doc__},
1706
1707
static PyObject *
1708
datetime_datetime_fromisoformat_impl(PyTypeObject *type, PyObject *string);
1709
1710
static PyObject *
1711
datetime_datetime_fromisoformat(PyObject *type, PyObject *arg)
1712
0
{
1713
0
    PyObject *return_value = NULL;
1714
0
    PyObject *string;
1715
1716
0
    if (!PyUnicode_Check(arg)) {
1717
0
        _PyArg_BadArgument("fromisoformat", "argument", "str", arg);
1718
0
        goto exit;
1719
0
    }
1720
0
    string = arg;
1721
0
    return_value = datetime_datetime_fromisoformat_impl((PyTypeObject *)type, string);
1722
1723
0
exit:
1724
0
    return return_value;
1725
0
}
1726
1727
PyDoc_STRVAR(datetime_datetime_isoformat__doc__,
1728
"isoformat($self, /, sep=\'T\', timespec=\'auto\')\n"
1729
"--\n"
1730
"\n"
1731
"Return the time formatted according to ISO.\n"
1732
"\n"
1733
"The full format looks like \'YYYY-MM-DD HH:MM:SS.mmmmmm\'.\n"
1734
"By default, the fractional part is omitted if self.microsecond == 0.\n"
1735
"\n"
1736
"If self.tzinfo is not None, the UTC offset is also attached, giving\n"
1737
"a full format of \'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM\'.\n"
1738
"\n"
1739
"Optional argument sep specifies the separator between date and\n"
1740
"time, default \'T\'.\n"
1741
"\n"
1742
"The optional argument timespec specifies the number of additional\n"
1743
"terms of the time to include. Valid options are \'auto\', \'hours\',\n"
1744
"\'minutes\', \'seconds\', \'milliseconds\' and \'microseconds\'.");
1745
1746
#define DATETIME_DATETIME_ISOFORMAT_METHODDEF    \
1747
    {"isoformat", _PyCFunction_CAST(datetime_datetime_isoformat), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_isoformat__doc__},
1748
1749
static PyObject *
1750
datetime_datetime_isoformat_impl(PyDateTime_DateTime *self, int sep,
1751
                                 const char *timespec);
1752
1753
static PyObject *
1754
datetime_datetime_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1755
0
{
1756
0
    PyObject *return_value = NULL;
1757
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1758
1759
0
    #define NUM_KEYWORDS 2
1760
0
    static struct {
1761
0
        PyGC_Head _this_is_not_used;
1762
0
        PyObject_VAR_HEAD
1763
0
        Py_hash_t ob_hash;
1764
0
        PyObject *ob_item[NUM_KEYWORDS];
1765
0
    } _kwtuple = {
1766
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1767
0
        .ob_hash = -1,
1768
0
        .ob_item = { &_Py_ID(sep), &_Py_ID(timespec), },
1769
0
    };
1770
0
    #undef NUM_KEYWORDS
1771
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1772
1773
    #else  // !Py_BUILD_CORE
1774
    #  define KWTUPLE NULL
1775
    #endif  // !Py_BUILD_CORE
1776
1777
0
    static const char * const _keywords[] = {"sep", "timespec", NULL};
1778
0
    static _PyArg_Parser _parser = {
1779
0
        .keywords = _keywords,
1780
0
        .fname = "isoformat",
1781
0
        .kwtuple = KWTUPLE,
1782
0
    };
1783
0
    #undef KWTUPLE
1784
0
    PyObject *argsbuf[2];
1785
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1786
0
    int sep = 'T';
1787
0
    const char *timespec = NULL;
1788
1789
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1790
0
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1791
0
    if (!args) {
1792
0
        goto exit;
1793
0
    }
1794
0
    if (!noptargs) {
1795
0
        goto skip_optional_pos;
1796
0
    }
1797
0
    if (args[0]) {
1798
0
        if (!PyUnicode_Check(args[0])) {
1799
0
            _PyArg_BadArgument("isoformat", "argument 'sep'", "a unicode character", args[0]);
1800
0
            goto exit;
1801
0
        }
1802
0
        if (PyUnicode_GET_LENGTH(args[0]) != 1) {
1803
0
            PyErr_Format(PyExc_TypeError,
1804
0
                "isoformat(): argument 'sep' must be a unicode character, "
1805
0
                "not a string of length %zd",
1806
0
                PyUnicode_GET_LENGTH(args[0]));
1807
0
            goto exit;
1808
0
        }
1809
0
        sep = PyUnicode_READ_CHAR(args[0], 0);
1810
0
        if (!--noptargs) {
1811
0
            goto skip_optional_pos;
1812
0
        }
1813
0
    }
1814
0
    if (!PyUnicode_Check(args[1])) {
1815
0
        _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[1]);
1816
0
        goto exit;
1817
0
    }
1818
0
    Py_ssize_t timespec_length;
1819
0
    timespec = PyUnicode_AsUTF8AndSize(args[1], &timespec_length);
1820
0
    if (timespec == NULL) {
1821
0
        goto exit;
1822
0
    }
1823
0
    if (strlen(timespec) != (size_t)timespec_length) {
1824
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
1825
0
        goto exit;
1826
0
    }
1827
0
skip_optional_pos:
1828
0
    return_value = datetime_datetime_isoformat_impl((PyDateTime_DateTime *)self, sep, timespec);
1829
1830
0
exit:
1831
0
    return return_value;
1832
0
}
1833
1834
PyDoc_STRVAR(datetime_datetime_replace__doc__,
1835
"replace($self, /, year=unchanged, month=unchanged, day=unchanged,\n"
1836
"        hour=unchanged, minute=unchanged, second=unchanged,\n"
1837
"        microsecond=unchanged, tzinfo=unchanged, *, fold=unchanged)\n"
1838
"--\n"
1839
"\n"
1840
"Return datetime with new specified fields.");
1841
1842
#define DATETIME_DATETIME_REPLACE_METHODDEF    \
1843
    {"replace", _PyCFunction_CAST(datetime_datetime_replace), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_replace__doc__},
1844
1845
static PyObject *
1846
datetime_datetime_replace_impl(PyDateTime_DateTime *self, int year,
1847
                               int month, int day, int hour, int minute,
1848
                               int second, int microsecond, PyObject *tzinfo,
1849
                               int fold);
1850
1851
static PyObject *
1852
datetime_datetime_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1853
0
{
1854
0
    PyObject *return_value = NULL;
1855
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1856
1857
0
    #define NUM_KEYWORDS 9
1858
0
    static struct {
1859
0
        PyGC_Head _this_is_not_used;
1860
0
        PyObject_VAR_HEAD
1861
0
        Py_hash_t ob_hash;
1862
0
        PyObject *ob_item[NUM_KEYWORDS];
1863
0
    } _kwtuple = {
1864
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1865
0
        .ob_hash = -1,
1866
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), },
1867
0
    };
1868
0
    #undef NUM_KEYWORDS
1869
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1870
1871
    #else  // !Py_BUILD_CORE
1872
    #  define KWTUPLE NULL
1873
    #endif  // !Py_BUILD_CORE
1874
1875
0
    static const char * const _keywords[] = {"year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo", "fold", NULL};
1876
0
    static _PyArg_Parser _parser = {
1877
0
        .keywords = _keywords,
1878
0
        .fname = "replace",
1879
0
        .kwtuple = KWTUPLE,
1880
0
    };
1881
0
    #undef KWTUPLE
1882
0
    PyObject *argsbuf[9];
1883
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1884
0
    int year = GET_YEAR(self);
1885
0
    int month = GET_MONTH(self);
1886
0
    int day = GET_DAY(self);
1887
0
    int hour = DATE_GET_HOUR(self);
1888
0
    int minute = DATE_GET_MINUTE(self);
1889
0
    int second = DATE_GET_SECOND(self);
1890
0
    int microsecond = DATE_GET_MICROSECOND(self);
1891
0
    PyObject *tzinfo = HASTZINFO(self) ? ((PyDateTime_DateTime *)self)->tzinfo : Py_None;
1892
0
    int fold = DATE_GET_FOLD(self);
1893
1894
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1895
0
            /*minpos*/ 0, /*maxpos*/ 8, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1896
0
    if (!args) {
1897
0
        goto exit;
1898
0
    }
1899
0
    if (!noptargs) {
1900
0
        goto skip_optional_pos;
1901
0
    }
1902
0
    if (args[0]) {
1903
0
        year = PyLong_AsInt(args[0]);
1904
0
        if (year == -1 && PyErr_Occurred()) {
1905
0
            goto exit;
1906
0
        }
1907
0
        if (!--noptargs) {
1908
0
            goto skip_optional_pos;
1909
0
        }
1910
0
    }
1911
0
    if (args[1]) {
1912
0
        month = PyLong_AsInt(args[1]);
1913
0
        if (month == -1 && PyErr_Occurred()) {
1914
0
            goto exit;
1915
0
        }
1916
0
        if (!--noptargs) {
1917
0
            goto skip_optional_pos;
1918
0
        }
1919
0
    }
1920
0
    if (args[2]) {
1921
0
        day = PyLong_AsInt(args[2]);
1922
0
        if (day == -1 && PyErr_Occurred()) {
1923
0
            goto exit;
1924
0
        }
1925
0
        if (!--noptargs) {
1926
0
            goto skip_optional_pos;
1927
0
        }
1928
0
    }
1929
0
    if (args[3]) {
1930
0
        hour = PyLong_AsInt(args[3]);
1931
0
        if (hour == -1 && PyErr_Occurred()) {
1932
0
            goto exit;
1933
0
        }
1934
0
        if (!--noptargs) {
1935
0
            goto skip_optional_pos;
1936
0
        }
1937
0
    }
1938
0
    if (args[4]) {
1939
0
        minute = PyLong_AsInt(args[4]);
1940
0
        if (minute == -1 && PyErr_Occurred()) {
1941
0
            goto exit;
1942
0
        }
1943
0
        if (!--noptargs) {
1944
0
            goto skip_optional_pos;
1945
0
        }
1946
0
    }
1947
0
    if (args[5]) {
1948
0
        second = PyLong_AsInt(args[5]);
1949
0
        if (second == -1 && PyErr_Occurred()) {
1950
0
            goto exit;
1951
0
        }
1952
0
        if (!--noptargs) {
1953
0
            goto skip_optional_pos;
1954
0
        }
1955
0
    }
1956
0
    if (args[6]) {
1957
0
        microsecond = PyLong_AsInt(args[6]);
1958
0
        if (microsecond == -1 && PyErr_Occurred()) {
1959
0
            goto exit;
1960
0
        }
1961
0
        if (!--noptargs) {
1962
0
            goto skip_optional_pos;
1963
0
        }
1964
0
    }
1965
0
    if (args[7]) {
1966
0
        tzinfo = args[7];
1967
0
        if (!--noptargs) {
1968
0
            goto skip_optional_pos;
1969
0
        }
1970
0
    }
1971
0
skip_optional_pos:
1972
0
    if (!noptargs) {
1973
0
        goto skip_optional_kwonly;
1974
0
    }
1975
0
    fold = PyLong_AsInt(args[8]);
1976
0
    if (fold == -1 && PyErr_Occurred()) {
1977
0
        goto exit;
1978
0
    }
1979
0
skip_optional_kwonly:
1980
0
    return_value = datetime_datetime_replace_impl((PyDateTime_DateTime *)self, year, month, day, hour, minute, second, microsecond, tzinfo, fold);
1981
1982
0
exit:
1983
0
    return return_value;
1984
0
}
1985
1986
PyDoc_STRVAR(datetime_datetime_astimezone__doc__,
1987
"astimezone($self, /, tz=None)\n"
1988
"--\n"
1989
"\n"
1990
"Convert to local time in new timezone tz.");
1991
1992
#define DATETIME_DATETIME_ASTIMEZONE_METHODDEF    \
1993
    {"astimezone", _PyCFunction_CAST(datetime_datetime_astimezone), METH_FASTCALL|METH_KEYWORDS, datetime_datetime_astimezone__doc__},
1994
1995
static PyObject *
1996
datetime_datetime_astimezone_impl(PyDateTime_DateTime *self,
1997
                                  PyObject *tzinfo);
1998
1999
static PyObject *
2000
datetime_datetime_astimezone(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2001
0
{
2002
0
    PyObject *return_value = NULL;
2003
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2004
2005
0
    #define NUM_KEYWORDS 1
2006
0
    static struct {
2007
0
        PyGC_Head _this_is_not_used;
2008
0
        PyObject_VAR_HEAD
2009
0
        Py_hash_t ob_hash;
2010
0
        PyObject *ob_item[NUM_KEYWORDS];
2011
0
    } _kwtuple = {
2012
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2013
0
        .ob_hash = -1,
2014
0
        .ob_item = { &_Py_ID(tz), },
2015
0
    };
2016
0
    #undef NUM_KEYWORDS
2017
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2018
2019
    #else  // !Py_BUILD_CORE
2020
    #  define KWTUPLE NULL
2021
    #endif  // !Py_BUILD_CORE
2022
2023
0
    static const char * const _keywords[] = {"tz", NULL};
2024
0
    static _PyArg_Parser _parser = {
2025
0
        .keywords = _keywords,
2026
0
        .fname = "astimezone",
2027
0
        .kwtuple = KWTUPLE,
2028
0
    };
2029
0
    #undef KWTUPLE
2030
0
    PyObject *argsbuf[1];
2031
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
2032
0
    PyObject *tzinfo = Py_None;
2033
2034
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2035
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2036
0
    if (!args) {
2037
0
        goto exit;
2038
0
    }
2039
0
    if (!noptargs) {
2040
0
        goto skip_optional_pos;
2041
0
    }
2042
0
    tzinfo = args[0];
2043
0
skip_optional_pos:
2044
0
    return_value = datetime_datetime_astimezone_impl((PyDateTime_DateTime *)self, tzinfo);
2045
2046
0
exit:
2047
0
    return return_value;
2048
0
}
2049
2050
PyDoc_STRVAR(datetime_datetime___reduce_ex____doc__,
2051
"__reduce_ex__($self, proto, /)\n"
2052
"--\n"
2053
"\n");
2054
2055
#define DATETIME_DATETIME___REDUCE_EX___METHODDEF    \
2056
    {"__reduce_ex__", (PyCFunction)datetime_datetime___reduce_ex__, METH_O, datetime_datetime___reduce_ex____doc__},
2057
2058
static PyObject *
2059
datetime_datetime___reduce_ex___impl(PyDateTime_DateTime *self, int proto);
2060
2061
static PyObject *
2062
datetime_datetime___reduce_ex__(PyObject *self, PyObject *arg)
2063
0
{
2064
0
    PyObject *return_value = NULL;
2065
0
    int proto;
2066
2067
0
    proto = PyLong_AsInt(arg);
2068
0
    if (proto == -1 && PyErr_Occurred()) {
2069
0
        goto exit;
2070
0
    }
2071
0
    return_value = datetime_datetime___reduce_ex___impl((PyDateTime_DateTime *)self, proto);
2072
2073
0
exit:
2074
0
    return return_value;
2075
0
}
2076
2077
PyDoc_STRVAR(datetime_datetime___reduce____doc__,
2078
"__reduce__($self, /)\n"
2079
"--\n"
2080
"\n");
2081
2082
#define DATETIME_DATETIME___REDUCE___METHODDEF    \
2083
    {"__reduce__", (PyCFunction)datetime_datetime___reduce__, METH_NOARGS, datetime_datetime___reduce____doc__},
2084
2085
static PyObject *
2086
datetime_datetime___reduce___impl(PyDateTime_DateTime *self);
2087
2088
static PyObject *
2089
datetime_datetime___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
2090
0
{
2091
0
    return datetime_datetime___reduce___impl((PyDateTime_DateTime *)self);
2092
0
}
2093
/*[clinic end generated code: output=69658acff6a43ac4 input=a9049054013a1b77]*/