periods.py 文件源码

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

项目:beansoup 作者: fxtlabs 项目源码 文件源码
def lowest_end(date, first_day=1):
    """Compute the ending date of the monthly period containing the given date.

    More formally, given a monthly cycle starting on `first_day` day of the month,
    it computes the lowest ending date that is greater than or equal to the given
    `date`.  Note that the ending date is inclusive, i.e. it is included in the
    monthly period.

    Args:
      date (datetime.date): An arbitrary date.
      first_day (int): The first day of the monthly cycle. It must fall
        in the interval [1,28].

    Returns:
      datetime.date: The ending date of the monthly period containing the given date.
    """
    start = greatest_start(date, first_day=first_day)
    _, length = calendar.monthrange(start.year, start.month)
    return start + datetime.timedelta(days=length-1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号