Carbon DateTime package

Viewed 60

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.

1 Answers
Related