utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:hdhp.py 作者: Networks-Learning 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号