Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raising exception for outside scope with nth_of_month() #357

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,11 @@ def _nth_of_month(self, nth, day_of_week):
return self.first_of("month", day_of_week)

dt = self.first_of("month")
check = dt.format("%Y-%m")
check = dt.format("%Y-%M")
for i in range(nth - (1 if dt.day_of_week == day_of_week else 0)):
dt = dt.next(day_of_week)

if dt.format("%Y-%m") == check:
if dt.format("%Y-%M") == check:
return self.set(day=dt.day).start_of("day")

return False
Expand Down
2 changes: 1 addition & 1 deletion tests/date/test_day_of_week_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_last_friday_of_month():


def test_nth_of_month_outside_scope():
d = pendulum.date(1975, 12, 5)
d = pendulum.date(1975, 6, 5)

with pytest.raises(PendulumException):
d.nth_of("month", 6, pendulum.MONDAY)
Expand Down
2 changes: 1 addition & 1 deletion tests/datetime/test_day_of_week_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_last_friday_of_month():


def test_nth_of_month_outside_scope():
d = pendulum.datetime(1975, 12, 5)
d = pendulum.datetime(1975, 6, 5)

with pytest.raises(PendulumException):
d.nth_of("month", 6, pendulum.MONDAY)
Expand Down