Skip to content
Permalink
Browse files

DateTime::from(null) fixed [Closes #211]

  • Loading branch information
dg committed Jan 7, 2020
1 parent a9bdd20 commit 25d50ad54866acebd1e72c0f172e3caedc0c8a33
Showing with 3 additions and 1 deletion.
  1. +1 −1 src/Utils/DateTime.php
  2. +2 −0 tests/Utils/DateTime.from.phpt
@@ -55,7 +55,7 @@ public static function from($time)
return (new static('@' . $time))->setTimezone(new \DateTimeZone(date_default_timezone_get()));

} else { // textual or null
return new static($time);
return new static((string) $time);
}
}

@@ -24,6 +24,8 @@ Assert::same(is_int(2544000000) ? 2544000000 : '2544000000', DateTime::from(2544

Assert::same('1978-05-05 00:00:00', (string) DateTime::from('1978-05-05'));

Assert::same((new \Datetime)->format('Y-m-d H:i:s'), (string) DateTime::from(null));

Assert::type(DateTime::class, DateTime::from(new \DateTime('1978-05-05')));

Assert::same('1978-05-05 12:00:00.123450', DateTime::from(new DateTime('1978-05-05 12:00:00.12345'))->format('Y-m-d H:i:s.u'));

0 comments on commit 25d50ad

Please sign in to comment.
You can’t perform that action at this time.