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

Method _nth_of_month

src/pendulum/datetime.py:1064–1085  ·  view source on GitHub ↗

Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside, the scope of the current month, then return False and no modifications are made. Use the supplied consts to indicate the desired day_of_we

(
        self, nth: int, day_of_week: WeekDay | None = None
    )

Source from the content-addressed store, hash-verified

1062 return dt.set(day=day_of_month)
1063
1064 def _nth_of_month(
1065 self, nth: int, day_of_week: WeekDay | None = None
1066 ) -> Self | None:
1067 """
1068 Modify to the given occurrence of a given day of the week
1069 in the current month. If the calculated occurrence is outside,
1070 the scope of the current month, then return False and no
1071 modifications are made. Use the supplied consts
1072 to indicate the desired day_of_week, ex. DateTime.MONDAY.
1073 """
1074 if nth == 1:
1075 return self.first_of("month", day_of_week)
1076
1077 dt = self.first_of("month")
1078 check = dt.format("%Y-%M")
1079 for _ in range(nth - (1 if dt.day_of_week == day_of_week else 0)):
1080 dt = dt.next(day_of_week)
1081
1082 if dt.format("%Y-%M") == check:
1083 return self.set(day=dt.day).start_of("day")
1084
1085 return None
1086
1087 def _first_of_quarter(self, day_of_week: WeekDay | None = None) -> Self:
1088 """

Callers

nothing calls this directly

Calls 5

first_ofMethod · 0.95
setMethod · 0.95
formatMethod · 0.45
nextMethod · 0.45
start_ofMethod · 0.45

Tested by

no test coverage detected