-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Strange behavior with parse() when chaining addHours() and addMinutes() #1075
Comments
I can't reproduce it (I have php 7.1.11 on the windows though). Could you write the unit test with date_default_timezone_set() with your current timezone like this? Does it fail? <?php
namespace Tests\Carbon;
use Carbon\Carbon;
use Tests\AbstractTestCase;
class issue1705Test extends AbstractTestCase
{
public function testIssue() {
date_default_timezone_set('America/New_York');
$d = Carbon::parse('2018-01-23T03:30:45-5:00');
$d->addHours(1)->addMinutes(1);
$this->assertEquals('2018-01-23T04:31:45-05:00', $d->format('c'));
}
} |
My default TZ is UTC, but if I change it to America/New_York it functions as expected. Also I just tried this in another environment, where PHP is at 7.1.7, and I couldn't reproduce the issue. |
So, this test failed in your environment, didn't it? <?php
namespace Tests\Carbon;
use Carbon\Carbon;
use Tests\AbstractTestCase;
class issue1705Test extends AbstractTestCase
{
public function testIssue() {
date_default_timezone_set('UTC');
$d = Carbon::parse('2018-01-23T03:30:45-5:00');
$d->addHours(1)->addMinutes(1);
$this->assertEquals('2018-01-23T04:31:45-05:00', $d->format('c'));
}
} |
Default TZ should have no saying here, since you already have TZ info in the string. See note on
@toddstoker: this is a very strange bug. Are you sure you are not doing anything else with |
It might be because changed |
We will fix that modify method ASAP. |
Btw, I already made pull-request for that a quite time ago: #1070 |
True, but we must first fix travis and styleci, and then you should rebase, and if all goes well, we shall merge. Bear with us :) |
I'm experiencing some strange behavior. When using Carbon::parse() on an atom formatted string (e.g. '2018-01-23T03:30:45-5:00'), if addHours() and addMinutes() are chained then you will receive an erroneous result.
Edit: Carbon 1.22.1, PHP 7.1.2
The text was updated successfully, but these errors were encountered: