Carbon producing inconsistent results

Asked

Viewed 56 times

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’re adding 1 hour to $datSuspensao where the number of additional days is equal to 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 it comes from the bank (dat_inclusion) I must add n days on dat_inclusao as you can see up there.

$objAlt->dat_inclusao = date: 2018-10-12 18:40:11.0 America/Sao_Paulo (-03:00)
  • It won’t be because your watch is wrong?

  • I removed the tag [tag: Carbon has no relation to the Framework, it is only a library used by it.

  • The date format that is coming from the bank is date: 2018-10-12 18:40:11.0 America/Sao_Paulo (-03:00)

  • @Can wallacemaxters be something related to daylight saving time? day 21 Several devices changed by themselves. @Erloncharles I gave a Carbon::parse on this date before

  • @carlos sure can. My server here was adding the logs an hour longer. Linux updated itself. I noticed this yesterday and modified the date of the server, not to have more errors.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.