Skip to content

Commit

Permalink
Fix null handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed May 27, 2021
1 parent 0bd295d commit 4ce48f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Carbon/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public static function create($year = 0, $month = 1, $day = 1, $hour = 0, $minut
$second = ($second < 10 ? '0' : '').number_format($second, 6);
$instance = static::rawCreateFromFormat('!Y-n-j G:i:s.u', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz);

if ($fixYear !== null) {
if ($instance && $fixYear !== null) {
$instance = $instance->addYears($fixYear);
}

Expand Down Expand Up @@ -563,7 +563,7 @@ private static function createFromFormatAndTimezone(string $format, string $time

$tz = static::safeCreateDateTimeZone($tz, $originalTz);

if ($tz === false) {
if ($tz === null) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Carbon/CreateSafeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testCreateSafeThrowsExceptionForSecondLowerThanZero()
public function testCreateSafeThrowsExceptionForSecondLowerThanZeroInStrictMode()
{
Carbon::useStrictMode(false);
$this->assertFalse(Carbon::createSafe(null, null, null, null, null, -1));
$this->assertNull(Carbon::createSafe(null, null, null, null, null, -1));
Carbon::useStrictMode(true);
}

Expand Down Expand Up @@ -187,7 +187,7 @@ public function testCreateSafeThrowsExceptionForInvalidDayForFebruaryInLeapYear(
public function testCreateSafeThrowsExceptionForInvalidDayForFebruaryInLeapYearInStrictMode()
{
Carbon::useStrictMode(false);
$this->assertFalse(Carbon::createSafe(2016, 2, 30, 17, 16, 15));
$this->assertNull(Carbon::createSafe(2016, 2, 30, 17, 16, 15));
Carbon::useStrictMode(true);
}

Expand Down

0 comments on commit 4ce48f4

Please sign in to comment.