in darabonba/date.py [0:0]
def add(self, unit, amount):
if unit in ["second", "seconds"]:
return Date((self.date + timedelta(seconds=amount)).isoformat())
elif unit in ["minute", "minutes"]:
return Date((self.date + timedelta(minutes=amount)).isoformat())
elif unit in ["hour", "hours"]:
return Date((self.date + timedelta(hours=amount)).isoformat())
elif unit in ["day", "days"]:
return Date((self.date + timedelta(days=amount)).isoformat())
elif unit in ["week", "weeks"]:
return Date((self.date + timedelta(weeks=amount)).isoformat())
elif unit in ["month", "months"]:
new_month = self.date.month + amount
new_year = self.date.year + (new_month - 1) // 12
new_month = (new_month - 1) % 12 + 1
if self.date.day > 28:
if new_month == 2:
new_day = min(self.date.day, 29)
if new_day == 29 and not (new_year % 4 == 0 and (new_year % 100 != 0 or new_year % 400 == 0)):
new_day = 28
else:
new_day = min(self.date.day, [31, 30][new_month % 2])
else:
new_day = self.date.day
new_date = self.date.replace(year=new_year, month=new_month, day=new_day)
return Date(new_date.isoformat())
elif unit in ["year", "years"]:
return Date((self.date.replace(year=self.date.year + amount)).isoformat())