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

Method first_of

src/pendulum/datetime.py:966–979  ·  view source on GitHub ↗

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. DateTime.MONDAY. Supp

(self, unit: str, day_of_week: WeekDay | None = None)

Source from the content-addressed store, hash-verified

964 return dt
965
966 def first_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self:
967 """
968 Returns an instance set to the first occurrence
969 of a given day of the week in the current unit.
970 If no day_of_week is provided, modify to the first day of the unit.
971 Use the supplied consts to indicate the desired day_of_week,
972 ex. DateTime.MONDAY.
973
974 Supported units are month, quarter and year.
975 """
976 if unit not in ["month", "quarter", "year"]:
977 raise ValueError(f'Invalid unit "{unit}" for first_of()')
978
979 return cast("Self", getattr(self, f"_first_of_{unit}")(day_of_week))
980
981 def last_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self:
982 """

Callers 5

_nth_of_monthMethod · 0.95
_nth_of_quarterMethod · 0.95
_nth_of_yearMethod · 0.95
_first_of_quarterMethod · 0.45
_first_of_yearMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected