def month_add(t1, months):
"""Adds a number of months to the given date.
Note
----
The decimal part of the value corresponds to the fraction of days of the
last month that will be added.
Parameters
----------
t1 : datetime object
months : float
Returns
-------
t2 : datetime object
"""
t2 = t1 + relativedelta(months=int(months // 1))
days_in_month = calendar.monthrange(t2.year, t2.month)[1]
t2 = t2 + datetime.timedelta(seconds=days_in_month * 86400 * (months % 1))
return t2
评论列表
文章目录