def _last_of_month(self, day_of_week=None):
"""
Modify to the last occurrence of a given day of the week
in the current month. If no day_of_week is provided,
modify to the last day of the month. Use the supplied consts
to indicate the desired day_of_week, ex. Pendulum.MONDAY.
:type day_of_week: int or None
:rtype: Pendulum
"""
dt = self.start_of('day')
if day_of_week is None:
return dt.day_(self.days_in_month)
month = calendar.monthcalendar(dt.year, dt.month)
calendar_day = (day_of_week - 1) % 7
if month[-1][calendar_day] > 0:
day_of_month = month[-1][calendar_day]
else:
day_of_month = month[-2][calendar_day]
return dt.day_(day_of_month)
评论列表
文章目录