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

Method first_of

src/pendulum/date.py:502–518  ·  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. pendulum.MONDAY. Supp

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

Source from the content-addressed store, hash-verified

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

Callers 15

week_of_monthMethod · 0.95
_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
test_first_day_of_monthFunction · 0.45

Calls

no outgoing calls