def get_month_range(start_date=None, next_month=False):
if start_date is None:
start_date = datetime.date.today()
month = start_date.month
year = start_date.year
if next_month:
month = 1 if start_date.month == 12 else start_date.month + 1
if month == 1:
year += 1
start_date = start_date.replace(day=1, month=month, year=year)
_, days_in_month = calendar.monthrange(year, month)
end_date = start_date + datetime.timedelta(days=days_in_month-1)
return (start_date, end_date)
评论列表
文章目录