Skip to content

Commit 3216bbf

Browse files
committed
convert datetime.date.isoformat() to AC
1 parent 6847dcc commit 3216bbf

File tree

2 files changed

+87
-17
lines changed

2 files changed

+87
-17
lines changed

Modules/_datetimemodule.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,16 +3595,21 @@ date_repr(PyObject *op)
35953595
GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
35963596
}
35973597

3598+
/*[clinic input]
3599+
datetime.date.isoformat
3600+
3601+
basic: bool = False
3602+
3603+
Return string in ISO 8601 format, YYYY-MM-DD.
3604+
3605+
If basic is true, uses the basic format, YYYYMMDD.
3606+
[clinic start generated code]*/
3607+
35983608
static PyObject *
3599-
date_isoformat(PyObject *op, PyObject *args, PyObject *kw)
3609+
datetime_date_isoformat_impl(PyDateTime_Date *self, int basic)
3610+
/*[clinic end generated code: output=c458fbf6d05e16f2 input=1bd448614fd107d0]*/
36003611
{
3601-
int basic = 0;
3602-
static char *keywords[] = {"basic", NULL};
3603-
if (!PyArg_ParseTupleAndKeywords(args, kw, "|p:isoformat", keywords, &basic)) {
3604-
return NULL;
3605-
}
36063612
const char *format = basic ? "%04d%02d%02d" : "%04d-%02d-%02d";
3607-
PyDateTime_Date *self = PyDate_CAST(op);
36083613
return PyUnicode_FromFormat(format, GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
36093614
}
36103615

@@ -3997,9 +4002,7 @@ static PyMethodDef date_methods[] = {
39974002
PyDoc_STR("Return a named tuple containing ISO year, week number, and "
39984003
"weekday.")},
39994004

4000-
{"isoformat", _PyCFunction_CAST(date_isoformat), METH_VARARGS | METH_KEYWORDS,
4001-
PyDoc_STR("Return string in ISO 8601 format, YYYY-MM-DD.\n"
4002-
"If basic is true, uses the basic format, YYYYMMDD.")},
4005+
DATETIME_DATE_ISOFORMAT_METHODDEF
40034006

40044007
{"isoweekday", date_isoweekday, METH_NOARGS,
40054008
PyDoc_STR("Return the day of the week represented by the date.\n"
@@ -4863,8 +4866,7 @@ datetime_time_isoformat_impl(PyDateTime_Time *self, const char *timespec,
48634866

48644867
PyObject *result;
48654868
int us = TIME_GET_MICROSECOND(self);
4866-
4867-
static const char * const specs_extended[][2] = {
4869+
static const char *const specs_extended[][2] = {
48684870
{"hours", "%02d"},
48694871
{"minutes", "%02d:%02d"},
48704872
{"seconds", "%02d:%02d:%02d"},
@@ -4879,7 +4881,7 @@ datetime_time_isoformat_impl(PyDateTime_Time *self, const char *timespec,
48794881
{"microseconds", "%02d%02d%02d.%06d"},
48804882
};
48814883

4882-
const char *(*specs)[2] = basic ? specs_basic : specs_extended;
4884+
const char *const (*specs)[2] = basic ? specs_basic : specs_extended;
48834885
// due to array decaying, Py_ARRAY_LENGTH(specs) would return 0
48844886
size_t specs_count = basic ? Py_ARRAY_LENGTH(specs_basic) : Py_ARRAY_LENGTH(specs_extended);
48854887
size_t given_spec;
@@ -6444,22 +6446,22 @@ datetime_datetime_isoformat_impl(PyDateTime_DateTime *self, int sep,
64446446

64456447
PyObject *result = NULL;
64466448
int us = DATE_GET_MICROSECOND(self);
6447-
static const char * const specs_extended[][2] = {
6449+
static const char *const specs_extended[][2] = {
64486450
{"hours", "%04d-%02d-%02d%c%02d"},
64496451
{"minutes", "%04d-%02d-%02d%c%02d:%02d"},
64506452
{"seconds", "%04d-%02d-%02d%c%02d:%02d:%02d"},
64516453
{"milliseconds", "%04d-%02d-%02d%c%02d:%02d:%02d.%03d"},
64526454
{"microseconds", "%04d-%02d-%02d%c%02d:%02d:%02d.%06d"},
64536455
};
6454-
static const char * const specs_basic[][2] = {
6456+
static const char *const specs_basic[][2] = {
64556457
{"hours", "%04d%02d%02d%c%02d"},
64566458
{"minutes", "%04d%02d%02d%c%02d%02d"},
64576459
{"seconds", "%04d%02d%02d%c%02d%02d%02d"},
64586460
{"milliseconds", "%04d%02d%02d%c%02d%02d%02d.%03d"},
64596461
{"microseconds", "%04d%02d%02d%c%02d%02d%02d.%06d"},
64606462
};
64616463

6462-
const char *(*specs)[2] = basic ? specs_basic : specs_extended;
6464+
const char *const(*specs)[2] = basic ? specs_basic : specs_extended;
64636465
// due to array decaying, Py_ARRAY_LENGTH(specs) would return 0
64646466
size_t specs_count = basic ? Py_ARRAY_LENGTH(specs_basic) : Py_ARRAY_LENGTH(specs_extended);
64656467
size_t given_spec;

Modules/clinic/_datetimemodule.c.h

Lines changed: 69 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)