From acfb4a1a2952808f9d2739bc80e5ed82863cc416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20S=CC=8Ctekl?= Date: Thu, 9 Oct 2014 16:19:41 +0200 Subject: [PATCH] Fixed public interface of createFromFormat --- src/Utils/DateTime.php | 7 ++++++- tests/Utils/DateTime.createFromFormat.phpt | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Utils/DateTime.php b/src/Utils/DateTime.php index f25148c79..9a255c068 100644 --- a/src/Utils/DateTime.php +++ b/src/Utils/DateTime.php @@ -106,7 +106,12 @@ public static function createFromFormat($format, $time, $timezone = NULL) throw new Nette\InvalidArgumentException('Invalid timezone given'); } - return static::from(parent::createFromFormat($format, $time, $timezone)); + $dateTime = parent::createFromFormat($format, $time, $timezone); + if ($dateTime === FALSE) { + return FALSE; + } + + return static::from($dateTime); } } diff --git a/tests/Utils/DateTime.createFromFormat.phpt b/tests/Utils/DateTime.createFromFormat.phpt index 33dff0207..d4e792dc9 100644 --- a/tests/Utils/DateTime.createFromFormat.phpt +++ b/tests/Utils/DateTime.createFromFormat.phpt @@ -23,3 +23,5 @@ Assert::same( 'Europe/Bratislava', DateTime::createFromFormat('Y', '2050', 'Euro Assert::error(function(){ DateTime::createFromFormat('Y-m-d H:i:s', '2050-08-13 11:40:00', 5); }, 'Nette\InvalidArgumentException', 'Invalid timezone given' ); + +Assert::false(DateTime::createFromFormat('Y-m-d', '2014-10'));