Issue
Trying to format a timestamp with Carbon diffForHumans(), passing in the following params, so it reads as:
$new_format = $old_format->diffForHumans(['parts' => 1, 'options' => Carbon::CEIL]);
When it attempts to format a date ~1 month ago, it leads to an "undefined offset -1" error.
echo Carbon::parse('2022-01-11 15:36:29')->diffForHumans(['parts' => 1, 'options' => Carbon::CEIL]);
echo Carbon::parse('2022-01-10 16:57:38')->diffForHumans(['parts' => 1, 'options' => Carbon::CEIL]);
The examples above, the top run works, where as the bottom one errors. Is there an explanation, why it breaks with these params, or better yet a solution that would give me the same result? Changing to Carbon::FLOOR or ROUND works fine, but aren't viable for what I need.
Thanks.
Solution
This bug is fixed in version 2.57.0. Thanks for the report.
https://github.com/briannesbitt/Carbon/pull/2547
You can test it using composer update nesbot/carbon
Answered By - KyleK
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.