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

Method previous

src/pendulum/date.py:481–500  ·  view source on GitHub ↗

Modify to the previous occurrence of a given day of the week. If no day_of_week is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY. :param day_of_we

(self, day_of_week: WeekDay | None = None)

Source from the content-addressed store, hash-verified

479 return dt
480
481 def previous(self, day_of_week: WeekDay | None = None) -> Self:
482 """
483 Modify to the previous occurrence of a given day of the week.
484 If no day_of_week is provided, modify to the previous occurrence
485 of the current day of the week. Use the supplied consts
486 to indicate the desired day_of_week, ex. pendulum.MONDAY.
487
488 :param day_of_week: The previous day of week to reset to.
489 """
490 if day_of_week is None:
491 day_of_week = self.day_of_week
492
493 if day_of_week < WeekDay.MONDAY or day_of_week > WeekDay.SUNDAY:
494 raise ValueError("Invalid day of week")
495
496 dt = self.subtract(days=1)
497 while dt.day_of_week != day_of_week:
498 dt = dt.subtract(days=1)
499
500 return dt
501
502 def first_of(self, unit: str, day_of_week: WeekDay | None = None) -> Self:
503 """

Callers 10

_start_of_weekMethod · 0.95
test_previousFunction · 0.45
test_previous_mondayFunction · 0.45
test_previous_saturdayFunction · 0.45
test_previous_keep_timeFunction · 0.45
test_previous_invalidFunction · 0.45
test_previousFunction · 0.45
test_previous_mondayFunction · 0.45
test_previous_saturdayFunction · 0.45
test_previous_invalidFunction · 0.45

Calls 1

subtractMethod · 0.95

Tested by 9

test_previousFunction · 0.36
test_previous_mondayFunction · 0.36
test_previous_saturdayFunction · 0.36
test_previous_keep_timeFunction · 0.36
test_previous_invalidFunction · 0.36
test_previousFunction · 0.36
test_previous_mondayFunction · 0.36
test_previous_saturdayFunction · 0.36
test_previous_invalidFunction · 0.36