From 6df9baf85806501e02d07b5e9b151271a8e7e43e Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Mon, 11 Mar 2019 17:33:16 -0400 Subject: [PATCH 1/2] Improve test_nth_of_month_outside_scope() test cases --- tests/date/test_day_of_week_modifiers.py | 2 +- tests/datetime/test_day_of_week_modifiers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/date/test_day_of_week_modifiers.py b/tests/date/test_day_of_week_modifiers.py index 0b12a98f..e65a13c0 100644 --- a/tests/date/test_day_of_week_modifiers.py +++ b/tests/date/test_day_of_week_modifiers.py @@ -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) diff --git a/tests/datetime/test_day_of_week_modifiers.py b/tests/datetime/test_day_of_week_modifiers.py index a1091022..7b476418 100644 --- a/tests/datetime/test_day_of_week_modifiers.py +++ b/tests/datetime/test_day_of_week_modifiers.py @@ -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) From 5f895d95fcbec85c2ad9ae12602c4713e450b6d4 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Mon, 11 Mar 2019 17:46:44 -0400 Subject: [PATCH 2/2] Correct minute comparison to month for DateTime.nth_of_month() --- pendulum/datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pendulum/datetime.py b/pendulum/datetime.py index abca24a8..6c423037 100644 --- a/pendulum/datetime.py +++ b/pendulum/datetime.py @@ -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