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