[New-bugs-announce] [issue26279] Possible bug in time library

Ioannis Aslanidis report at bugs.python.org
Wed Feb 3 11:02:51 EST 2016

New submission from Ioannis Aslanidis:

There seems to be a bug in the time library when performing the following conversion:

In [8]: mytime=time.strptime(str([2015, 53, 0]), '[%Y, %U, %w]')

In [9]: mytime
Out[9]: time.struct_time(tm_year=2016, tm_mon=1, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=368, tm_isdst=-1)

In [10]: time.strftime('%Y %U', mytime)
ValueError Traceback (most recent call last)
<ipython-input-10-c13538c08ea5> in <module>()
----> 1 time.strftime('%Y %U', mytime)

ValueError: day of year out of range 

As you can observe, tm_yday got a value of 368 instead of 3. It seems that the C function is not properly subtracting 365 or 366 days when converting from week 53 of a particular year which, according to ISO 8601 [1] and per python documentation [2]. Documentation explicitly says that: "The first week of the year is the week with the year's first Thursday in it".

[1] https://en.wikipedia.org/wiki/ISO_8601#Week_dates
[2] https://docs.python.org/2/library/time.html

components: Library (Lib)
messages: 259488
nosy: iaslan
priority: normal
severity: normal
status: open
title: Possible bug in time library
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list