You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, enough of your template. Let me explain. Someone in our company thought it works. And indeed it might work most of the time because noone is touching the to string format and php is smart enough to compare '2022-05-03' > '2021-05-03'. Also the documentation does not say it is save to use strings.
PHP itself also is very broken in this regard as the DateTime cannot be converted to string:
My suggestion is to check if the given parameter in the comparison methods is a DateTime object and if not call ::resolveCarbon($date) or directly call ::resolveCarbon($date). Another option would be to throw but that's a breaking change.
Thanks!
The text was updated successfully, but these errors were encountered:
tflori
changed the title
Comparisions show wrong date
Comparisons show wrong result
Jan 3, 2022
I agree. We should use resolveCarbon as we do with most of the methods. Here we want to get any string that parse() is able to handle and don't want to rely to setToStringFormat.
Meanwhile it get changed and released, I suggest to use instead:
Hello,
I encountered an issue with the following code:
Carbon version: 2.55.2
PHP version: PHP 8.0.13
I expected to get:
But I actually get:
Ok, enough of your template. Let me explain. Someone in our company thought it works. And indeed it might work most of the time because noone is touching the to string format and php is smart enough to compare
'2022-05-03' > '2021-05-03'
. Also the documentation does not say it is save to use strings.PHP itself also is very broken in this regard as the DateTime cannot be converted to string:
The comparisons with strings seem to work more accendtially than anything else. Nevertheless the inline documetnations tells us it is working with strings (see: https://github.com/briannesbitt/Carbon/blob/2.55.2/src/Carbon/Traits/Comparison.php#L147). But that is only true if you don't change the toStringFormat.
My suggestion is to check if the given parameter in the comparison methods is a
DateTime
object and if not call::resolveCarbon($date)
or directly call::resolveCarbon($date)
. Another option would be to throw but that's a breaking change.Thanks!
The text was updated successfully, but these errors were encountered: