Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed public interface of createFromFormat #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Utils/DateTime.php
Expand Up @@ -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);
}

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