MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / _nth_of_year

Method _nth_of_year

src/pendulum/date.py:696–715  ·  view source on GitHub ↗

Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside, the scope of the current year, then return False and no modifications are made. Use the supplied consts to indicate the desired day_of_week

(self, nth: int, day_of_week: WeekDay)

Source from the content-addressed store, hash-verified

694 return self.set(month=MONTHS_PER_YEAR).last_of("month", day_of_week)
695
696 def _nth_of_year(self, nth: int, day_of_week: WeekDay) -> Self | None:
697 """
698 Modify to the given occurrence of a given day of the week
699 in the current year. If the calculated occurrence is outside,
700 the scope of the current year, then return False and no
701 modifications are made. Use the supplied consts
702 to indicate the desired day_of_week, ex. pendulum.MONDAY.
703 """
704 if nth == 1:
705 return self.first_of("year", day_of_week)
706
707 dt = self.first_of("year")
708 year = dt.year
709 for _ in range(nth - (1 if dt.day_of_week == day_of_week else 0)):
710 dt = dt.next(day_of_week)
711
712 if year != dt.year:
713 return None
714
715 return self.set(self.year, dt.month, dt.day)
716
717 def average(self, dt: date | None = None) -> Self:
718 """

Callers

nothing calls this directly

Calls 3

first_ofMethod · 0.95
setMethod · 0.95
nextMethod · 0.45

Tested by

no test coverage detected