79481785

Date: 2025-03-03 18:13:52
Score: 1
Natty:
Report link

Yes, in Carbon 3.x, diffInSeconds() now returns a signed value, unlike Carbon 2.x, which always returned positive.

Fix:

Use abs() to get a positive value:

$duration_in_secs = abs($time_after->diffInSeconds($time_before));

Or swap the arguments:

$duration_in_secs = $time_before->diffInSeconds($time_after);
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Foysal Rahman