Coverage Report

Created: 2025-08-26 06:26

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