Skip to content

Commit

Permalink
DateTime::from(null) fixed [Closes #211]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 14, 2020
1 parent e3cea97 commit a27c1ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/DateTime.php
Expand Up @@ -55,7 +55,7 @@ public static function from($time)
return (new static('@' . $time))->setTimezone(new \DateTimeZone(date_default_timezone_get())); return (new static('@' . $time))->setTimezone(new \DateTimeZone(date_default_timezone_get()));


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


Expand Down
2 changes: 2 additions & 0 deletions tests/Utils/DateTime.from.phpt
Expand Up @@ -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('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::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')); 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 a27c1ea

Please sign in to comment.