From 21bcf9e257a8d6ea6915c9b7c0f288dd99bd51cd Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 29 May 2026 10:53:52 +0200 Subject: [PATCH 1/4] Add support for month and year parameters --- src/Modifiers/InMonth.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Modifiers/InMonth.php b/src/Modifiers/InMonth.php index c07c294..b5a9a6a 100755 --- a/src/Modifiers/InMonth.php +++ b/src/Modifiers/InMonth.php @@ -8,14 +8,11 @@ class InMonth extends Modifier { - public function index($value, $params, $context) + public function index($value, $params, $context): bool { - $month = parse_date( - Arr::get($context, 'get.month', CarbonImmutable::now()->englishMonth). - ' '. - Arr::get($context, 'get.year', CarbonImmutable::now()->year) - )->month; + $month = $params[0] ?? Arr::get($context, 'get.month') ?? CarbonImmutable::now()->englishMonth; + $year = $params[1] ?? Arr::get($context, 'get.year') ?? CarbonImmutable::now()->year; - return CarbonImmutable::parse($value)->month == $month; + return CarbonImmutable::parse($value)->month === parse_date("$month $year")->month; } } From 0c0321db10ed864dbf2eb7a5944340d0ea49964d Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 29 May 2026 11:01:24 +0200 Subject: [PATCH 2/4] Add tests for inMonth modifier --- tests/Modifiers/InMonthTest.php | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Modifiers/InMonthTest.php diff --git a/tests/Modifiers/InMonthTest.php b/tests/Modifiers/InMonthTest.php new file mode 100644 index 0000000..3de6629 --- /dev/null +++ b/tests/Modifiers/InMonthTest.php @@ -0,0 +1,55 @@ +toBeTrue(); +}); + +it('returns false when date is not in param month', function () { + expect(modify(value: '2026-04-15', params: ['May', '2026']))->toBeFalse(); +}); + +it('returns true for first day of month', function () { + expect(modify(value: '2026-05-01', params: ['May', '2026']))->toBeTrue(); +}); + +it('returns true for last day of month', function () { + expect(modify(value: '2026-05-31', params: ['May', '2026']))->toBeTrue(); +}); + +it('returns false for day before month', function () { + expect(modify(value: '2026-04-30', params: ['May', '2026']))->toBeFalse(); +}); + +it('returns false for day after month', function () { + expect(modify(value: '2026-06-01', params: ['May', '2026']))->toBeFalse(); +}); + +it('returns true when date matches month from context', function () { + expect(modify(value: '2026-05-15', context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeTrue(); +}); + +it('returns false when date does not match month from context', function () { + expect(modify(value: '2026-04-15', context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeFalse(); +}); + +it('param takes precedence over context', function () { + expect(modify(value: '2026-06-01', params: ['June', '2026'], context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeTrue(); +}); + +it('uses current month when no param or context given', function () { + CarbonImmutable::setTestNow('2026-05-15'); + + expect(modify(value: '2026-05-01'))->toBeTrue(); + expect(modify(value: '2026-04-30'))->toBeFalse(); + + CarbonImmutable::setTestNow(); +}); + + +function modify(string $value, array $params = [], array $context = []): bool +{ + return Modify::value($value)->context($context)->inMonth($params)->fetch(); +} From da9791bc4c55436e95672748d3fccd2f6d53be3e Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 29 May 2026 11:21:20 +0200 Subject: [PATCH 3/4] Drop unnecessary year --- src/Modifiers/InMonth.php | 2 +- tests/Modifiers/InMonthTest.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Modifiers/InMonth.php b/src/Modifiers/InMonth.php index b5a9a6a..e7a931f 100755 --- a/src/Modifiers/InMonth.php +++ b/src/Modifiers/InMonth.php @@ -11,7 +11,7 @@ class InMonth extends Modifier public function index($value, $params, $context): bool { $month = $params[0] ?? Arr::get($context, 'get.month') ?? CarbonImmutable::now()->englishMonth; - $year = $params[1] ?? Arr::get($context, 'get.year') ?? CarbonImmutable::now()->year; + $year = CarbonImmutable::now()->year; return CarbonImmutable::parse($value)->month === parse_date("$month $year")->month; } diff --git a/tests/Modifiers/InMonthTest.php b/tests/Modifiers/InMonthTest.php index 3de6629..8dfe14d 100644 --- a/tests/Modifiers/InMonthTest.php +++ b/tests/Modifiers/InMonthTest.php @@ -4,39 +4,39 @@ use Statamic\Modifiers\Modify; it('returns true when date is in param month', function () { - expect(modify(value: '2026-05-15', params: ['May', '2026']))->toBeTrue(); + expect(modify(value: '2026-05-15', params: ['May']))->toBeTrue(); }); it('returns false when date is not in param month', function () { - expect(modify(value: '2026-04-15', params: ['May', '2026']))->toBeFalse(); + expect(modify(value: '2026-04-15', params: ['May']))->toBeFalse(); }); it('returns true for first day of month', function () { - expect(modify(value: '2026-05-01', params: ['May', '2026']))->toBeTrue(); + expect(modify(value: '2026-05-01', params: ['May']))->toBeTrue(); }); it('returns true for last day of month', function () { - expect(modify(value: '2026-05-31', params: ['May', '2026']))->toBeTrue(); + expect(modify(value: '2026-05-31', params: ['May']))->toBeTrue(); }); it('returns false for day before month', function () { - expect(modify(value: '2026-04-30', params: ['May', '2026']))->toBeFalse(); + expect(modify(value: '2026-04-30', params: ['May']))->toBeFalse(); }); it('returns false for day after month', function () { - expect(modify(value: '2026-06-01', params: ['May', '2026']))->toBeFalse(); + expect(modify(value: '2026-06-01', params: ['May']))->toBeFalse(); }); it('returns true when date matches month from context', function () { - expect(modify(value: '2026-05-15', context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeTrue(); + expect(modify(value: '2026-05-15', context: ['get' => ['month' => 'May']]))->toBeTrue(); }); it('returns false when date does not match month from context', function () { - expect(modify(value: '2026-04-15', context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeFalse(); + expect(modify(value: '2026-04-15', context: ['get' => ['month' => 'May']]))->toBeFalse(); }); it('param takes precedence over context', function () { - expect(modify(value: '2026-06-01', params: ['June', '2026'], context: ['get' => ['month' => 'May', 'year' => '2026']]))->toBeTrue(); + expect(modify(value: '2026-06-01', params: ['June'], context: ['get' => ['month' => 'May']]))->toBeTrue(); }); it('uses current month when no param or context given', function () { From d837fcdd8d5588d89fcaeca493170467783b91fe Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 29 May 2026 21:19:51 +0200 Subject: [PATCH 4/4] Renaming the conflicting function and move on with my life (Erin is a wise man). --- tests/Modifiers/InMonthTest.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/Modifiers/InMonthTest.php b/tests/Modifiers/InMonthTest.php index 8dfe14d..03c8d19 100644 --- a/tests/Modifiers/InMonthTest.php +++ b/tests/Modifiers/InMonthTest.php @@ -4,52 +4,51 @@ use Statamic\Modifiers\Modify; it('returns true when date is in param month', function () { - expect(modify(value: '2026-05-15', params: ['May']))->toBeTrue(); + expect(modifyInMonth(value: '2026-05-15', params: ['May']))->toBeTrue(); }); it('returns false when date is not in param month', function () { - expect(modify(value: '2026-04-15', params: ['May']))->toBeFalse(); + expect(modifyInMonth(value: '2026-04-15', params: ['May']))->toBeFalse(); }); it('returns true for first day of month', function () { - expect(modify(value: '2026-05-01', params: ['May']))->toBeTrue(); + expect(modifyInMonth(value: '2026-05-01', params: ['May']))->toBeTrue(); }); it('returns true for last day of month', function () { - expect(modify(value: '2026-05-31', params: ['May']))->toBeTrue(); + expect(modifyInMonth(value: '2026-05-31', params: ['May']))->toBeTrue(); }); it('returns false for day before month', function () { - expect(modify(value: '2026-04-30', params: ['May']))->toBeFalse(); + expect(modifyInMonth(value: '2026-04-30', params: ['May']))->toBeFalse(); }); it('returns false for day after month', function () { - expect(modify(value: '2026-06-01', params: ['May']))->toBeFalse(); + expect(modifyInMonth(value: '2026-06-01', params: ['May']))->toBeFalse(); }); it('returns true when date matches month from context', function () { - expect(modify(value: '2026-05-15', context: ['get' => ['month' => 'May']]))->toBeTrue(); + expect(modifyInMonth(value: '2026-05-15', context: ['get' => ['month' => 'May']]))->toBeTrue(); }); it('returns false when date does not match month from context', function () { - expect(modify(value: '2026-04-15', context: ['get' => ['month' => 'May']]))->toBeFalse(); + expect(modifyInMonth(value: '2026-04-15', context: ['get' => ['month' => 'May']]))->toBeFalse(); }); it('param takes precedence over context', function () { - expect(modify(value: '2026-06-01', params: ['June'], context: ['get' => ['month' => 'May']]))->toBeTrue(); + expect(modifyInMonth(value: '2026-06-01', params: ['June'], context: ['get' => ['month' => 'May']]))->toBeTrue(); }); it('uses current month when no param or context given', function () { CarbonImmutable::setTestNow('2026-05-15'); - expect(modify(value: '2026-05-01'))->toBeTrue(); - expect(modify(value: '2026-04-30'))->toBeFalse(); + expect(modifyInMonth(value: '2026-05-01'))->toBeTrue(); + expect(modifyInMonth(value: '2026-04-30'))->toBeFalse(); CarbonImmutable::setTestNow(); }); - -function modify(string $value, array $params = [], array $context = []): bool +function modifyInMonth(string $value, array $params = [], array $context = []): bool { return Modify::value($value)->context($context)->inMonth($params)->fetch(); }