[ python-Feature Requests-1436346 ] yday in datetime module
SourceForge.net
noreply at sourceforge.net
Wed Feb 22 03:58:43 CET 2006
Feature Requests item #1436346, was opened at 2006-02-21 18:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1436346&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Toews (mwtoews)
Assigned to: Nobody/Anonymous (nobody)
Summary: yday in datetime module
Initial Comment:
My first request is relatively simple: add a 'yday'
method to datetime.date and datetime.datetime.
Thus I could do:
>>> from datetime import *
>>> t = date.today()
>>> t.yday()
52
# rather than the less readable:
>>> t.timetuple()[7]
52
# or worse:
>>> int(t.strftime('%j'))
52
The second request is to have more alternate
constructors for date or datetime objects. There are
currently:
* date(year,month,day)
* date.fromtimestamp(timestamp)
* date.fromordinal(ordinal)
* date.today()
I would like to have:
* date.fromtimetuple(9-item time tuple structure)
* date.strptime(data_string,format)
As well, it would be nice to change:
* date(year,month=None,day=None,yday=None)
e.g.,:
>>> date(2006,2,21) == date(2006,yday=52)
True
Here, a date can be formed from a year, month and day
or from just the year and the day of the year,
otherwise I have to convert using:
>>> import time
>>> year = 2006
>>> yday = 52
>>> t = time.strptime(`year`+'-'+`yday`,'%Y-%j')
>>> datetime.date(t.tm_year,t.tm_mon,t.tm_mday)
datetime.date(2006, 2, 21)
If a safer approach is desired (as to not change the
class constructor too much), then please offer an
alternate, say:
* date.fromyday(year,yday)
or something like that.
Thanks.
+mt
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1436346&group_id=5470
More information about the Python-bugs-list
mailing list