Carbon producing inconsistent results

0

Correct

$datSuspensao   = Carbon::parse($objAlt->dat_inclusao)->addDays(8)->startOfDay();
$datNow         = Carbon::now()->startOfDay();
$diasRestantes  = $datNow->diffInDays($datSuspensao, false);
dd('($datNow ' . $datNow . ') - (' . '$datSuspensao ' .$datSuspensao . ') = ' . $diasRestantes);

//"($datNow 2018-10-23 00:00:00) - ($datSuspensao 2018-10-20 00:00:00) = -3"

Correct

$datSuspensao   = Carbon::parse($objAlt->dat_inclusao)->addDays(15)->startOfDay();
$datNow         = Carbon::now()->startOfDay();
$diasRestantes  = $datNow->diffInDays($datSuspensao, false);
dd('($datNow ' . $datNow . ') - (' . '$datSuspensao ' .$datSuspensao . ') = ' . $diasRestantes);

//"($datNow 2018-10-23 00:00:00) - ($datSuspensao 2018-10-27 00:00:00) = 4"

Inconsistent result

For some reason you are adding 1 hour to $datSuspensao when the number of additional days equals 9 . For this reason, the calculation is wrong.

$datSuspensao   = Carbon::parse($objAlt->dat_inclusao)->addDays(9)->startOfDay();
$datNow         = Carbon::now()->startOfDay();
$diasRestantes  = $datNow->diffInDays($datSuspensao, false);
dd('($datNow ' . $datNow . ') - (' . '$datSuspensao ' .$datSuspensao . ') = ' . $diasRestantes);

//Imprime: "($datNow 2018-10-23 00:00:00) - ($datSuspensao 2018-10-21 01:00:00) = -1"

How come from the bank (date_inclusion)     I should add n days to dat_inclusao as you can see up there.

$objAlt->dat_inclusao = date: 2018-10-12 18:40:11.0 America/Sao_Paulo (-03:00)
    
asked by anonymous 23.10.2018 / 17:54

0 answers