Skip to content
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

Incorrect totalSeconds after adding interval to CarbonInterval in v3 #2979

Closed
jamesRUS52 opened this issue Mar 27, 2024 · 1 comment · Fixed by #2981
Closed

Incorrect totalSeconds after adding interval to CarbonInterval in v3 #2979

jamesRUS52 opened this issue Mar 27, 2024 · 1 comment · Fixed by #2981
Assignees
Labels
Milestone

Comments

@jamesRUS52
Copy link

Hello,

I encountered an issue with the following code:

$t1 = now();
$t2 = now()->addMinutes(2);

$p = $t1->diffAsCarbonInterval($t2);
$p->addSeconds(10);

echo $p->locale('en_US')->forHumans();
echo PHP_EOL;
echo $p->totalSeconds;
// Carbon 3.1.1
//2 minutes 10 seconds
//120.000011

echo $p->locale('en_US')->forHumans();
echo PHP_EOL;
echo $p->totalSeconds;
// Carbon 2.71.0
//2 minutes 10 seconds
//130.000011

After adding additional interval to another one, it not calculated in totalSeconds,
but it correct in Human presentation. And it work well at Carbon v2

Carbon version: 3.1.1

PHP version: 8.3

I expected to get:

130

But I actually get:

120

Thanks!

@kylekatarnls kylekatarnls self-assigned this Mar 27, 2024
@kylekatarnls
Copy link
Collaborator

OK, I see the problem, the interval remember the start and end used to create it, but we need to forget them as soon as the interval is altered again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants