Description
Bug report
Bug description:
strftime() and strptime() Behavior section says "date, datetime, and time objects all support a strftime(format) method, to create a string representing the time under the control of an explicit format string.", it means these 3 methods behaves as the same, and there is %f directive in the directive list. Otherwise, in time.strftime(format[, t]) section, there is no mention about %f directive in the directive list.
Abuout CPython, datetime.datetime.strftime() and time.strftime() actually behave differently about %f directive.
>>> from datetime import datetime
>>> datetime.now().strftime('%Y-%m-%dT%T.%fZ')
'2023-09-27T19:43:12.168908Z'>>> import time
>>> time.strftime('%Y-%m-%dT%T.%fZ')
'2023-09-27T19:43:31.%fZ'Former interprets %f directive, latter doesn't.
I reproduced this issue in CPython 3.10.12 and main branch 2897142, on Ubuntu 22.04.2 LTS.
I'm not sure about this is a documentation issue or CPython implementation issue, or both.
About CPython implementation, it looks like date.strftime() and time.strftime() call wrap_strftime(), and it interprets %f directive, so I couldn't find the cause. I couldn't find a datetime.datetime.strftime() implementation, like datetime_strftime().
About test, there are two tests of time.strftime. One is test_strftime in datetimetester.py, another one is test_strftime.py.
Both don't have a test about %f directive.
I think it's better to fix time.strftime() to interpret %f directive, and duplicated documentations and tests will be merged.
CPython versions tested on:
3.10
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Projects
Status

