Skip to content

Commit

Permalink
Allow plus prefix fr numeric timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Apr 14, 2022
1 parent e06036c commit e97fe3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Carbon/CarbonTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected static function parseNumericTimezone($timezone)
throw new InvalidTimeZoneException('Absolute timezone offset cannot be greater than 100.');
}

return ($timezone >= 0 ? '+' : '').$timezone.':00';
return ($timezone >= 0 ? '+' : '').ltrim($timezone, '+').':00';
}

protected static function getDateTimeZoneNameFromMixed($timezone)
Expand Down
16 changes: 16 additions & 0 deletions tests/CarbonTimeZone/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public function testCreate()
$tz = CarbonTimeZone::create(6);

$this->assertSame('+06:00', $tz->getName());

$tz = CarbonTimeZone::create('+01');

$this->assertSame('+01:00', $tz->getName());

$tz = new CarbonTimeZone('+01');

$this->assertSame('+01:00', $tz->getName());

$tz = CarbonTimeZone::create('-01');

$this->assertSame('-01:00', $tz->getName());

$tz = new CarbonTimeZone('-01');

$this->assertSame('-01:00', $tz->getName());
}

public function testInstance()
Expand Down

0 comments on commit e97fe3f

Please sign in to comment.