-
-
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
createFromTime() fails when seconds parameter > 99 #1731
Comments
Test: >>> Carbon\Carbon::createFromTime(0,0,1)->toTimeString();
=> "00:00:01"
>>> Carbon\Carbon::createFromTime(0,0,99)->toTimeString();
=> "00:01:39"
>>> Carbon\Carbon::createFromTime(0,0,100)->toTimeString();
InvalidArgumentException with message 'The separation symbol could not be found
Trailing data' |
The above function may not have been designed to provide that kind of functionality and if that's the case I think a more detailed exception should be thrown. In retrospect, Carbon\Carbon::createFromTimeStamp(100)->toTimeString(); Works just as well when needing only the time string. |
Hello, This is in fact due to the echo DateTime::createFromFormat('H:i:s', '00:00:01')->format('H:i:s'); // "00:00:01"
echo DateTime::createFromFormat('H:i:s', '00:00:99')->format('H:i:s'); // "00:01:39"
echo DateTime::createFromFormat('H:i:s', '00:00:100')->format('H:i:s'); // fails as "s" format accepts only 2 digits. That means, if we change something here, it would be for a more strict validation (error if $seconds > 59) but we won't accept 100, as I was about to suggest what you commented meanwhile. Using |
I kept the limits to [0; 99] but added specific exceptions messages for the next release. |
Hello,
Anytime that the seconds parameter is greater than 99 the function fails. However, 99 and below works properly.
I encountered an issue with the following code:
Carbon version: nesbot/carbon v2.17.1
PHP version: v7.1.23
I expected to get:
But I actually get:
Try here
https://try-carbon.herokuapp.com/?embed&theme=xcode&border=silver&options-color=rgba(120,120,120,0.5)&input=Carbon%3A%3AcreateFromTime(0%2C0%2C100)-%3EtoTimeString()%3B
Thanks!
The text was updated successfully, but these errors were encountered: