diff --git a/src/Carbon/Traits/Creator.php b/src/Carbon/Traits/Creator.php index 35fa5ec359..7adf61adde 100644 --- a/src/Carbon/Traits/Creator.php +++ b/src/Carbon/Traits/Creator.php @@ -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); } @@ -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; } diff --git a/tests/Carbon/CreateSafeTest.php b/tests/Carbon/CreateSafeTest.php index 374a19fb5a..7d34bf9d36 100644 --- a/tests/Carbon/CreateSafeTest.php +++ b/tests/Carbon/CreateSafeTest.php @@ -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); } @@ -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); }