Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside, the scope of the current quarter, then return False and no modifications are made. Use the supplied consts to indicate the desired day_o
(self, nth: int, day_of_week: WeekDay)
| 653 | return self.set(self.year, self.quarter * 3, 1).last_of("month", day_of_week) |
| 654 | |
| 655 | def _nth_of_quarter(self, nth: int, day_of_week: WeekDay) -> Self | None: |
| 656 | """ |
| 657 | Modify to the given occurrence of a given day of the week |
| 658 | in the current quarter. If the calculated occurrence is outside, |
| 659 | the scope of the current quarter, then return False and no |
| 660 | modifications are made. Use the supplied consts |
| 661 | to indicate the desired day_of_week, ex. pendulum.MONDAY. |
| 662 | """ |
| 663 | if nth == 1: |
| 664 | return self.first_of("quarter", day_of_week) |
| 665 | |
| 666 | dt = self.replace(self.year, self.quarter * 3, 1) |
| 667 | last_month = dt.month |
| 668 | year = dt.year |
| 669 | dt = dt.first_of("quarter") |
| 670 | for _ in range(nth - (1 if dt.day_of_week == day_of_week else 0)): |
| 671 | dt = dt.next(day_of_week) |
| 672 | |
| 673 | if last_month < dt.month or year != dt.year: |
| 674 | return None |
| 675 | |
| 676 | return self.set(self.year, dt.month, dt.day) |
| 677 | |
| 678 | def _first_of_year(self, day_of_week: WeekDay | None = None) -> Self: |
| 679 | """ |