Skip to content

Commit

Permalink
Fix issue with is month check
Browse files Browse the repository at this point in the history
Fix #3032

(cherry picked from commit 280ad6d)
  • Loading branch information
kylekatarnls committed Jun 3, 2024
1 parent ae20e2b commit 117671b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Carbon/Traits/Comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,13 @@ public function is(string $tester)
return $this->year === (int) $tester;
}

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)) {
return $this->isSameMonth(
$this->transmitFactory(static fn () => static::parse($tester)),
false,
);
}

if (preg_match('/^\d{3,}-\d{1,2}$/', $tester)) {
return $this->isSameMonth(static::parse($tester));
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Carbon/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ public function testIs()
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('Sunday'));
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('Monday'));
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('June'));
$this->assertTrue(Carbon::parse('2019-05-31 12:23:45')->is('May'));
$this->assertTrue(Carbon::parse('2019-05-31 12:23:45')->is('mAy'));
$this->assertFalse(Carbon::parse('2019-05-31 12:23:45')->is('April'));
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('May'));
$this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('12:23'));
$this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('12:26'));
Expand Down

0 comments on commit 117671b

Please sign in to comment.