Skip to content

Commit f473323

Browse files
Apply Victor's usggestions
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent ddbcfe0 commit f473323

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎Doc/whatsnew/3.16.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ concurrent.futures
340340
(Contributed by xzmeng and Serhiy Storchaka in :gh:`108518`.)
341341

342342

343+
datetime
344+
--------
345+
346+
* Add the ``%Nf`` format code (where *N* is from 1 to 6) to
347+
:meth:`datetime.datetime.strftime`, :meth:`datetime.time.strftime`,
348+
:meth:`datetime.date.strftime`, :meth:`datetime.datetime.strptime` and
349+
:meth:`datetime.time.strptime`.
350+
(Contributed by Stan Ulbrych and Karoline Pauls in :gh:`157290`.)
351+
352+
343353
difflib
344354
-------
345355

‎Lib/_pydatetime.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def _wrap_strftime(object, format, timetuple):
242242
if freplace is None:
243243
freplace = '%06d' % getattr(object,
244244
'microsecond', 0)
245-
newformat.append(freplace[:int(ch)])
245+
precision = int(ch)
246+
newformat.append(freplace[:precision])
246247
elif ch == 'z':
247248
if zreplace is None:
248249
if hasattr(object, "utcoffset"):

‎Modules/_datetimemodule.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,8 +1983,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
19831983
goto Error;
19841984
}
19851985
start = i;
1986+
Py_ssize_t precision = ch - '0';
19861987
if (PyUnicodeWriter_WriteSubstring(writer, freplacement,
1987-
0, ch - '0') < 0)
1988+
0, precision) < 0)
19881989
{
19891990
goto Error;
19901991
}

0 commit comments

Comments
 (0)