Modify to the previous occurrence of a given day of the week. If no day_of_week is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY. :param day_of_we
(self, day_of_week: WeekDay | None = None)
| 479 | return dt |
| 480 | |
| 481 | def previous(self, day_of_week: WeekDay | None = None) -> Self: |
| 482 | """ |
| 483 | Modify to the previous occurrence of a given day of the week. |
| 484 | If no day_of_week is provided, modify to the previous occurrence |
| 485 | of the current day of the week. Use the supplied consts |
| 486 | to indicate the desired day_of_week, ex. pendulum.MONDAY. |
| 487 | |
| 488 | :param day_of_week: The previous day of week to reset to. |
| 489 | """ |
| 490 | if day_of_week is None: |
| 491 | day_of_week = self.day_of_week |
| 492 | |
| 493 | if day_of_week < WeekDay.MONDAY or day_of_week > WeekDay.SUNDAY: |
| 494 | raise ValueError("Invalid day of week") |
| 495 | |
| 496 | dt = self.subtract(days=1) |
| 497 | while dt.day_of_week != day_of_week: |
| 498 | dt = dt.subtract(days=1) |
| 499 | |
| 500 | return dt |
| 501 | |
| 502 | def first_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self: |
| 503 | """ |