[issue1436346] yday in datetime module
Alexander Belopolsky
report at bugs.python.org
Fri May 21 21:58:06 CEST 2010
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
On Thu, May 20, 2010 at 7:27 PM, Antoine Pitrou <report at bugs.python.org> wrote:
>
>> .. The OP's premise was that
>> t.timetuple()[7] was unreadable, but in the modern python, the same
>> can be written as t.timetuple().tm_yday.
>
> Could I suggest such example be added to the documentation, though?
The documentation for timetuple method [1, 2] already contains a
recipe for computing yday which is more efficient than
t.timetuple().tm_yday:
yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1
Maybe it can be improved by making it discoverable in searches for yday:
"""
... is equivalent to time.struct_time((d.year, d.month, d.day, d.hour,
d.minute, d.second, d.weekday(), yday, dst)), where yday =
d.toordinal() - date(d.year, 1, 1).toordinal() + 1 is the day number
of the year starting from 1 for January 1st.
"""
[1] http://docs.python.org/py3k/library/datetime.html#datetime.date.timetuple
[2] http://docs.python.org/py3k/library/datetime.html#datetime.datetime.timetuple
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1436346>
_______________________________________
More information about the Python-bugs-list
mailing list