def increment(self, when):
"""
Takes a datetime object and if it is in the past compared to the present it will
add the defined interval of time to it till it is in the future
"""
while not self.is_in_future(when):
n = now()
if self.interval == 'daily':
when = when + timedelta(days=1)
elif self.interval == 'weekly':
when = when + timedelta(days=7)
elif self.interval == 'monthly':
when = when + timedelta(days=monthrange(n.year, n.month)[1])
elif self.interval == 'yearly':
if isleap(n.year) and self.is_in_future(datetime(year=n.year, month=2, day=29)):
when = when + timedelta(days=366)
else:
when = when + timedelta(days=365)
return when
评论列表
文章目录