Repository: briannesbitt/Carbon (php)

Issue:
`is` month check fails on the 31st
The `is` check for month fails when the current date is the 31st of a month.

```php
var_dump(new DateTime());                                                                                                                                                                                                               
# class DateTime#1 (3) {                                                                                                                                                                                                                        
#   public $date =>                                                                                                                                                                                                                             
#   string(26) "2025-03-31 12:00:00.000000"                                                                                                                                                                                                     
#   public $timezone_type =>                                                                                                                                                                                                                    
#   int(3)                                                                                                                                                                                                                                      
#   public $timezone =>                                                                                                                                                                                                                         
#   string(3) "UTC"                                                                                                                                                                                                                             
# }

$c = \Carbon\Carbon::parse('2019-06-02 12:23:45');
print $c;
# 2019-06-02 12:23:45
var_dump($c->is("June"));
# bool(false)
```

This is probably inherited from `DateTime`; it fails to deliver "June" when called on the 31st because June 31 doesn't exist and overflows into July:

```php
var_dump(new DateTime("June"));
# class DateTime#4 (3) {
#   public $date =>
#   string(26) "2025-07-01 00:00:00.000000"
#   public $timezone_type =>
#   int(3)
#   public $timezone =>
#   string(3) "UTC"
# }
```

Observed in Carbon version 2.72.6.

Pull request description:
Fix overflow issue for is-month
Fix #3167

Patch:
diff --git a/src/Carbon/Traits/Comparison.php b/src/Carbon/Traits/Comparison.php
index 6590c5a9..1b5ef99c 100644
--- a/src/Carbon/Traits/Comparison.php
+++ b/src/Carbon/Traits/Comparison.php
@@ -1272,7 +1272,7 @@ trait Comparison
 
         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)),
+                $this->transmitFactory(static fn () => static::parse("$tester 1st")),
                 false,
             );
         }


Test patch:
diff --git a/tests/Carbon/IsTest.php b/tests/Carbon/IsTest.php
index 7f84bccf..d296a986 100644
--- a/tests/Carbon/IsTest.php
+++ b/tests/Carbon/IsTest.php
@@ -22,6 +22,7 @@ use Carbon\WeekDay;
 use DateInterval;
 use DateTime;
 use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\TestWith;
 use stdClass;
 use Tests\AbstractTestCase;
 use TypeError;
@@ -1399,8 +1400,12 @@ class IsTest extends AbstractTestCase
         $date->isCurrentFoobar();
     }
 
-    public function testIs()
+    #[TestWith([null])]
+    #[TestWith(['2025-03-31 12:00'])]
+    public function testIs(?string $testNow)
     {
+        Carbon::setTestNow($testNow);
+
         $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019'));
         $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2018'));
         $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06'));
@@ -1434,6 +1439,8 @@ class IsTest extends AbstractTestCase
         $this->assertTrue(Carbon::parse('2019-06-02 15:23:45')->is('3pm'));
         $this->assertFalse(Carbon::parse('2019-06-02 15:23:45')->is('4pm'));
         $this->assertFalse(Carbon::parse('2019-06-02 15:23:45')->is('3am'));
+        $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06'));
+        $this->assertTrue(Carbon::parse('2019-05-31 12:23:45')->is('2019-05'));
         $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02 12:23'));
         $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-03 12:23'));
         $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02 15:23'));