Skip to content

Commit 280ad6d

Browse files
committed
Fix issue with is month check
Fix #3032
1 parent e6f622c commit 280ad6d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Carbon/Traits/Comparison.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,13 @@ public function is(string $tester): bool
881881
return $this->year === (int) $tester;
882882
}
883883

884+
if (preg_match('/^(?:Jan|January|Feb|February|Mar|March|Apr|April|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)$/i', $tester)) {
885+
return $this->isSameMonth(
886+
$this->transmitFactory(static fn () => static::parse($tester)),
887+
false,
888+
);
889+
}
890+
884891
if (preg_match('/^\d{3,}-\d{1,2}$/', $tester)) {
885892
return $this->isSameMonth(
886893
$this->transmitFactory(static fn () => static::parse($tester)),

tests/Carbon/IsTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,9 @@ public function testIs()
10321032
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('Sunday'));
10331033
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('Monday'));
10341034
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('June'));
1035+
$this->assertTrue(Carbon::parse('2019-05-31 12:23:45')->is('May'));
1036+
$this->assertTrue(Carbon::parse('2019-05-31 12:23:45')->is('mAy'));
1037+
$this->assertFalse(Carbon::parse('2019-05-31 12:23:45')->is('April'));
10351038
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('May'));
10361039
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('12:23'));
10371040
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('12:26'));

0 commit comments

Comments
 (0)