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

Method _nth_of_month

src/pendulum/date.py:614–633  ·  view source on GitHub ↗

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

(self, nth: int, day_of_week: WeekDay)

Source from the content-addressed store, hash-verified

612 return dt.set(day=day_of_month)
613
614 def _nth_of_month(self, nth: int, day_of_week: WeekDay) -> Self | None:
615 """
616 Modify to the given occurrence of a given day of the week
617 in the current month. If the calculated occurrence is outside,
618 the scope of the current month, then return False and no
619 modifications are made. Use the supplied consts
620 to indicate the desired day_of_week, ex. pendulum.MONDAY.
621 """
622 if nth == 1:
623 return self.first_of("month", day_of_week)
624
625 dt = self.first_of("month")
626 check = dt.format("YYYY-MM")
627 for _ in range(nth - (1 if dt.day_of_week == day_of_week else 0)):
628 dt = dt.next(day_of_week)
629
630 if dt.format("YYYY-MM") == check:
631 return self.set(day=dt.day)
632
633 return None
634
635 def _first_of_quarter(self, day_of_week: WeekDay | None = None) -> Self:
636 """

Callers

nothing calls this directly

Calls 4

first_ofMethod · 0.95
setMethod · 0.95
formatMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected