Repository: briannesbitt/Carbon (PHP)

Issue:
canBeCreatedFromFormat wrongly returns false
<!--
    🛑 DON'T REMOVE ME.
    This issue template apply to all
      - bug reports,
      - feature proposals,
      - and documentation requests

    Having all those informations will allow us to know exactly
    what you expect and answer you faster and precisely (answer
    that matches your Carbon version, PHP version and usage).
    
    Note: Comments between <!- - and - -> won't appear in the final
    issue (See [Preview] tab).
-->
Hello,

I encountered an issue with the following code:
```php
$date = '2021-05-03T00:00:00+02:00';
Carbon::canBeCreatedFromFormat($date, 'Y-m-d\TH:i:sp');
```

Carbon version: **2.46.0**

PHP version: **8.0.3**

<!--
    Run the command `composer show nesbot/carbon`
    to get "versions"
    Use `echo phpversion();`
    to get PHP version.

    Some issues can depends on your context, settings,
    macros, timezone, language. So to be sure the code
    you give is enough to reproduce your bug, try it
    first in:
    https://try-carbon.herokuapp.com/?theme=xcode&export&embed

    You can use the [Options] button to change the version
    then when you get the bug with this editor, you can use
    the [Export] button, copy the link of the opened tab,
    then paste it in the issue. Then we can immediatly get
    your issue.
-->


I expected to get:

```
true
```

<!--
    Always give your expectations. Each use has their owns.
    You may want daylight saving time to be taken into account,
    someone else want it to be ignored. You may want timezone
    to be used in comparisons, someone else may not, etc.
-->

But I actually get:

```
false
```
<!--
    If you did not succeed to get the same result in
    https://try-carbon.herokuapp.com/ then precise the
    result you get.
-->

Moreover, if I try to "reformat" the `$date` variable to the format used in the check, it returns exactly the same string. So it seems the format of the `$date` variable is fine...
```php
Carbon::parse($date)->format('Y-m-d\TH:i:sp') === $date;

// true
```

Thanks!



Discussion:
Hello,

`p` is missing in the list, meanwhile you can use `P` instead.
Fixed for 2.48.0 release.
Thanks for your quick response!



Patch:
diff --git a/src/Carbon/Traits/Options.php b/src/Carbon/Traits/Options.php
index e89e4da35d..872d131404 100644
--- a/src/Carbon/Traits/Options.php
+++ b/src/Carbon/Traits/Options.php
@@ -97,6 +97,7 @@ trait Options
         'I' => '(0|1)',
         'O' => '([+-](1[012]|0[0-9])[0134][05])',
         'P' => '([+-](1[012]|0[0-9]):[0134][05])',
+        'p' => '(Z|[+-](1[012]|0[0-9]):[0134][05])',
         'T' => '([a-zA-Z]{1,5})',
         'Z' => '(-?[1-5]?[0-9]{1,4})',
         'U' => '([0-9]*)',


Test patch:
diff --git a/tests/Carbon/IsTest.php b/tests/Carbon/IsTest.php
index cb6ea09684..cf39ff088d 100644
--- a/tests/Carbon/IsTest.php
+++ b/tests/Carbon/IsTest.php
@@ -907,6 +907,9 @@ public function testHasFormat()
 
     public function testHasFormatWithModifiers()
     {
+        $this->assertTrue(Carbon::hasFormatWithModifiers('2021-05-03T00:00:00+02:00', 'Y-m-d\TH:i:sp'));
+        $this->assertTrue(Carbon::hasFormatWithModifiers('2021-05-03T00:00:00+02:00', 'Y-m-d\TH:i:sP'));
+        $this->assertTrue(Carbon::hasFormatWithModifiers('2021-05-03T00:00:00Z', 'Y-m-d\TH:i:sp'));
         $this->assertTrue(Carbon::hasFormatWithModifiers('1975-05-01', 'Y-m-d!'));
         $this->assertTrue(Carbon::hasFormatWithModifiers('1975-05-01', 'Y-m-d|'));
         $this->assertTrue(Carbon::hasFormatWithModifiers('1975-05-01', 'Y-*-d'));
@@ -914,6 +917,7 @@ public function testHasFormatWithModifiers()
         $this->assertTrue(Carbon::hasFormatWithModifiers('1975-05-01', 'Y#m#d'));
         $this->assertTrue(Carbon::hasFormatWithModifiers('1975/05/31', 'Y#m#d'));
 
+        $this->assertFalse(Carbon::hasFormatWithModifiers('2021-05-03T00:00:00Z', 'Y-m-d\TH:i:sP'));
         $this->assertFalse(Carbon::hasFormatWithModifiers('1975/31/05', 'Y#m#d'));
         $this->assertFalse(Carbon::hasFormatWithModifiers('1975-05-01', 'Y-?-d|'));
         $this->assertFalse(Carbon::hasFormatWithModifiers('1975--01', 'Y-*-d'));