Carbon: Add day doesn't work for October 28 in Rome timezone

Created on 8 Jun 2018  路  6Comments  路  Source: briannesbitt/Carbon

While date is in timezone Europe/Rome, Carbon is not adding day to it if setTime is used along with it.
It works fine without using setTime

screen shot 2018-06-08 at 9 51 06 pm

EDIT: If I am trying to add 2 days to 28 oct 2018, it is adding only one

Most helpful comment

First the root cause is the DST: https://www.timeanddate.com/time/change/italy/rome?year=2018

Rome time change on October 28, with the UTC timezone it does not fail. You can already check our methods addHours/addRealHours while I see the exact problem and the better way to code it.

All 6 comments

What version of PHP and carbon are you using?
I can't replicate this.

First the root cause is the DST: https://www.timeanddate.com/time/change/italy/rome?year=2018

Rome time change on October 28, with the UTC timezone it does not fail. You can already check our methods addHours/addRealHours while I see the exact problem and the better way to code it.

i tried doing the same thing in PHP's DateTime and it works just fine in that case
screen shot 2018-06-09 at 11 02 45 am

<?php

namespace Carbon;

include __DIR__.'/vendor/autoload.php';

$date = new Carbon('2018-10-27 00:00:01', 'Europe/Rome');

echo $date->addDay()->setTime(0, 0, 1)."\n";

echo $date->addDay()->setTime(0, 0, 1)."\n";

echo $date->addDay()->setTime(0, 0, 1)."\n";

Output:

2018-10-28 00:00:01
2018-10-29 00:00:01
2018-10-30 00:00:01

It does not fail. You did not answer to @36864 and I think he suspects you use an old version of Carbon and I think it can explain your problem.

@avinash403 note that addDay() may not be the same thing as modify('+24 hours'), just because 2018-10-27 in Rome is actually 25 hours long due to an extra hour of daylight saving time change.

On top of that the native DateTime contains many bugs on its own, in fact way more than one would expect. Thus comparing to it is not always a good idea.

You can use composer show --latest nesbot/carbon in the console to see which version of Carbon you have installed and which version is the newest.

@imbrish @kylekatarnls @36864 yeah I am using the 1.22.1. Will update to 1.29.2. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kylekatarnls picture kylekatarnls  路  5Comments

scs-ben picture scs-ben  路  3Comments

dboyadzhiev picture dboyadzhiev  路  4Comments

yica00 picture yica00  路  4Comments

ssi-anik picture ssi-anik  路  4Comments