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

Method _nth_of_quarter

src/pendulum/datetime.py:1107–1130  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1105 return self.on(self.year, self.quarter * 3, 1).last_of("month", day_of_week)
1106
1107 def _nth_of_quarter(
1108 self, nth: int, day_of_week: WeekDay | None = None
1109 ) -> Self | None:
1110 """
1111 Modify to the given occurrence of a given day of the week
1112 in the current quarter. If the calculated occurrence is outside,
1113 the scope of the current quarter, then return False and no
1114 modifications are made. Use the supplied consts
1115 to indicate the desired day_of_week, ex. DateTime.MONDAY.
1116 """
1117 if nth == 1:
1118 return self.first_of("quarter", day_of_week)
1119
1120 dt = self.set(day=1, month=self.quarter * 3)
1121 last_month = dt.month
1122 year = dt.year
1123 dt = dt.first_of("quarter")
1124 for _ in range(nth - (1 if dt.day_of_week == day_of_week else 0)):
1125 dt = dt.next(day_of_week)
1126
1127 if last_month < dt.month or year != dt.year:
1128 return None
1129
1130 return self.on(self.year, dt.month, dt.day).start_of("day")
1131
1132 def _first_of_year(self, day_of_week: WeekDay | None = None) -> Self:
1133 """

Callers

nothing calls this directly

Calls 5

first_ofMethod · 0.95
setMethod · 0.95
onMethod · 0.95
nextMethod · 0.45
start_ofMethod · 0.45

Tested by

no test coverage detected