Returns an instance set to the first occurrence of a given day of the week in the current unit. If no day_of_week is provided, modify to the first day of the unit. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY. Supp
(self, unit: str, day_of_week: WeekDay | None = None)
| 500 | return dt |
| 501 | |
| 502 | def first_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self: |
| 503 | """ |
| 504 | Returns an instance set to the first occurrence |
| 505 | of a given day of the week in the current unit. |
| 506 | If no day_of_week is provided, modify to the first day of the unit. |
| 507 | Use the supplied consts to indicate the desired day_of_week, |
| 508 | ex. pendulum.MONDAY. |
| 509 | |
| 510 | Supported units are month, quarter and year. |
| 511 | |
| 512 | :param unit: The unit to use |
| 513 | :param day_of_week: The day of week to reset to. |
| 514 | """ |
| 515 | if unit not in ["month", "quarter", "year"]: |
| 516 | raise ValueError(f'Invalid unit "{unit}" for first_of()') |
| 517 | |
| 518 | return cast("Self", getattr(self, f"_first_of_{unit}")(day_of_week)) |
| 519 | |
| 520 | def last_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self: |
| 521 | """ |
no outgoing calls