PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] Carbon DateTime package

 March 09, 2022     laravel, php, php-carbon     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing