Skip to content

Commit 9fd3d2d

Browse files
committed
pythongh-120713: use "%04ld" instead of "%04d" to avoid unnecessary int conversion
1 parent 2c3252f commit 9fd3d2d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Modules/_datetimemodule.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,13 +1942,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
19421942
#ifdef NORMALIZE_CENTURY
19431943
else if (ch == 'Y') {
19441944
/* 0-pad year with century on platforms that do not do so */
1945-
PyObject *year = PyObject_GetAttrString(object, "year");
1946-
if (year == NULL)
1947-
goto Done;
19481945
char formatted[5];
1949-
ntoappend = sprintf(formatted, "%04d", (int)PyLong_AsLong(year));
1946+
ntoappend = sprintf(formatted, "%04ld",
1947+
PyLong_AsLong(PyTuple_GET_ITEM(timetuple, 0)));
19501948
ptoappend = formatted;
1951-
Py_DECREF(year);
19521949
}
19531950
#endif
19541951
else {

0 commit comments

Comments
 (0)