This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mwtoews
Recipients
Date 2006-02-22.02:58:43
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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
History
Date User Action Args
2008-01-20 09:59:44adminlinkissue1436346 messages
2008-01-20 09:59:44admincreate