From 8433adb5dc40a2564c8e3a46ba6429d44e1c1496 Mon Sep 17 00:00:00 2001 From: Arifur Rahman Date: Tue, 19 Sep 2023 20:49:37 +0600 Subject: [PATCH] [4.x] Fix single digit month not working on whereMonth (#8697) --- src/Stache/Query/Builder.php | 2 +- tests/Data/Entries/EntryQueryBuilderTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Stache/Query/Builder.php b/src/Stache/Query/Builder.php index 73e4a44972..139d5553d7 100644 --- a/src/Stache/Query/Builder.php +++ b/src/Stache/Query/Builder.php @@ -190,7 +190,7 @@ protected function filterWhereMonth($values, $where) return false; } - return $this->{$method}($value->format('m'), $where['value']); + return $this->{$method}($value->format('m'), sprintf('%02d', $where['value'])); }); } diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 3e4077338f..b1149a640d 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -117,6 +117,11 @@ public function entries_are_found_using_where_month() $this->assertCount(3, $entries); $this->assertEquals(['Post 1', 'Post 2', 'Post 3'], $entries->map->title->all()); + $entries = Entry::query()->whereMonth('test_date', 9)->get(); + + $this->assertCount(1, $entries); + $this->assertEquals(['Post 4'], $entries->map->title->all()); + $entries = Entry::query()->whereMonth('test_date', '<', 11)->get(); $this->assertCount(1, $entries);