datelib pythonification
alex goretoy
agoretoy at gmail.com
Sat Feb 20 20:37:54 EST 2010
hello all,
since I posted this last time, I've added a new function dates_diff and
modified the dates_dict function to set timedelta values returned by
dates_diff in the returned dict
def dates_dict(self,*targs,**dargs):
"""
dates_dict() - takes params same as prefs()
returns dict key/value pair of formatted/calculated dates
key is a date, value is timedelta enddate-startdate
"""
self.prefs(*targs,**dargs)
d={}
try:
if self.format!="":
d[self.startdate.strftime(self.format)]=self.dates_diff()
else:
d[self.startdate]=self.dates_diff()
except ValueError:
d["%s"%self.startdate]=self.dates_diff()
while self.startdate<self.enddate:
a=self.calc(*targs,**dargs)[0]
d[a]=self.dates_diff()
self.reset_dates()
return d
def dates_diff(self,*targs):
"""
dates_diff - return timedelta difference between startdata and
enddate
takes nothing, a tuple, a list or 2 date objects as params
return enddate - startdate timedelta
"""
start,end=(self.startdate,self.enddate)
if targs:
if(len(targs)==1):
if(type(targs[0])==type(()) or targs[0] == type([])):
if(len(targs[0])==2):
start,end=(targs[0][0],targs[0][1])
elif(len(targs)== 2):
if(type(targs[0])==type(date.today()) and targs[1] ==
type(date.today())):
start,end=(targs[0],targs[1])
return end-start
-Alex Goretoy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100220/7a52360a/attachment.html>
More information about the Python-list
mailing list