Skip to content

Commit

Permalink
Merge branch '356-altendky-nth_of_month_outside_scope' of https://git…
Browse files Browse the repository at this point in the history
…hub.com/altendky/pendulum into altendky-356-altendky-nth_of_month_outside_scope
  • Loading branch information
Sébastien Eustace committed Mar 6, 2020
2 parents 8839568 + df4d10f commit 979c26f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,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

0 comments on commit 979c26f

Please sign in to comment.