time.strftime question on 0 as argument

David Raymond David.Raymond at tomtom.com
Mon Jan 28 14:27:05 EST 2019


https://docs.python.org/3.7/library/time.html#time.strftime

In the docs there is
"0 is a legal argument for any position in the time tuple; if it is normally illegal the value is forced to a correct one."

and yet if given 0 for the year/first item in the tuple it raises a ValueError.

Is that a bug in the code, the documentation, or my understanding?


Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%b", (0, 1, 0, 0, 0, 0, 0, 0, 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: strftime() requires year in [1; 9999]
>>>


Looks like it works in 2, so maybe an incorrect documentation carryover?

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%b", (0, 1, 0, 0, 0, 0, 0, 0, 0))
'Jan'
>>>


More information about the Python-list mailing list