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)
| 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 | """ |