in visualizeConnectData/lambdas/modifyCTR/isodate/duration.py [0:0]
def __add__(self, other):
'''
Durations can be added with Duration, timedelta, date and datetime
objects.
'''
if isinstance(other, Duration):
newduration = Duration(years=self.years + other.years,
months=self.months + other.months)
newduration.tdelta = self.tdelta + other.tdelta
return newduration
try:
# try anything that looks like a date or datetime
# 'other' has attributes year, month, day
# and relies on 'timedelta + other' being implemented
if (not(float(self.years).is_integer() and
float(self.months).is_integer())):
raise ValueError('fractional years or months not supported'
' for date calculations')
newmonth = other.month + self.months
carry, newmonth = fquotmod(newmonth, 1, 13)
newyear = other.year + self.years + carry
maxdays = max_days_in_month(newyear, newmonth)
if other.day > maxdays:
newday = maxdays
else:
newday = other.day
newdt = other.replace(year=newyear, month=newmonth, day=newday)
# does a timedelta + date/datetime
return self.tdelta + newdt
except AttributeError:
# other probably was not a date/datetime compatible object
pass
try:
# try if other is a timedelta
# relies on timedelta + timedelta supported
newduration = Duration(years=self.years, months=self.months)
newduration.tdelta = self.tdelta + other
return newduration
except AttributeError:
# ignore ... other probably was not a timedelta compatible object
pass
# we have tried everything .... return a NotImplemented
return NotImplemented