Message61219
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 |
|
Date |
User |
Action |
Args |
2008-01-20 09:59:44 | admin | link | issue1436346 messages |
2008-01-20 09:59:44 | admin | create | |
|