periods.py 文件源码

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

项目:beansoup 作者: fxtlabs 项目源码 文件源码
def next(date):
    """Add one month to the given date.

    Args:
      date (datetime.date): The starting date.

    Returns:
      datetime.date:  One month after the starting date unless the starting
      date falls on a day that is not in the next month; in that case, it
      returns the last day of the next month.

    Example:

      >>> import datetime
      >>> next(datetime.date(2016, 1, 31))
      datetime.date(2016, 2, 29)

    """
    year, month = (date.year, date.month + 1) if date.month < 12 else (date.year + 1, 1)
    _, length = calendar.monthrange(year, month)
    day = min(length, date.day)
    return datetime.date(year, month, day)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号