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)
评论列表
文章目录