-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createFromFormat
throw an exception for a format from which hasFormat
returned true
#2831
Comments
createFromFormat
throw a exception for a format hasFormat
returned true
createFromFormat
throw an exception for a format from which hasFormat
returned true
That's a pity that It's a bit unfortunate IMO that PHP have a constraint on the number of digits in Documentation of
|
Funny enough, > 4 digits does not work but less is OK: |
Side note, meanwhile you can use: Carbon::canBeCreatedFromFormat('20223-08-03', 'Y-m-d') Or use a try-catch. |
Edit : ohh I check on the wrong page, Anyway thanks for the consideration on aligning
I've fixed my code with a try catch before making this issue but I might use |
Okay, this might seems weird but I'd like you to reconsider "fixing"
The real "fix" should be to align What's your pov ? |
Indeed changing So we already make a commitment for 2.x on what I see that PHP 8.2 introduced Else, yeah But even A |
Fun fact If you wrap |
Hello,
I encountered an issue with the following code:
Carbon version: 2.68.1
PHP version: 8.1.21
I expected to get:
A carbon instance from
createFromFormat
OR
false
fromhasFormat
.But I actually get:
hasFormat
returntrue
for theY
format "flag" with a 5 digits year butcreateFromFormat
throw an exception (when in strict mode) for the same flag with a 5 digits year (eg. "22002").It happens because of the regex in
src/Carbon/Traits/Options.php:84
is([1-9]?[0-9]{4})
which allow 5 characters.Either
hasFormat
should accept only 4 digits for theY
flag orcreateFromFormat
should support 5 digits year, although I'm not sure this is possible ascreateFromFormat
use the base function from theDatetime
class ?Or I missed something in the doc about this case (which is totally possible ^^)
Thanks for your help!
The text was updated successfully, but these errors were encountered: