Skip to content

Commit

Permalink
Fix #1503 (PHP bug 77007) handle negative microseconds (#1505)
Browse files Browse the repository at this point in the history
* Fix #1503 (PHP bug 77007) handle negative microseconds
  • Loading branch information
kylekatarnls authored Nov 12, 2018
1 parent 3474982 commit 6689b51
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3976,7 +3976,7 @@ public function diffInSeconds($date = null, $absolute = true)
$value = $diff->days * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE +
$diff->h * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE +
$diff->i * static::SECONDS_PER_MINUTE +
$diff->s;
$diff->s - (property_exists($diff, 'f') && $diff->f < 0 ? 1 : 0);

return $absolute || !$diff->invert ? $value : -$value;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Carbon/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ public function testDiffInHoursWithTimezones()
$this->assertSame(3, $dtVancouver->diffInHours($dtToronto), 'Midnight in Toronto is 3 hours from midnight in Vancouver');

$dtToronto = Carbon::createFromDate(2012, 1, 1, 'America/Toronto');
sleep(2);
$dtVancouver = Carbon::createFromDate(2012, 1, 1, 'America/Vancouver');

$this->assertSame(0, $dtVancouver->diffInHours($dtToronto) % 24);
Expand Down

0 comments on commit 6689b51

Please sign in to comment.