Add parse date function to abstract Search

This commit is contained in:
2015-01-06 15:31:00 +01:00
parent c584ea2c7c
commit 5289ad9c2c
2 changed files with 76 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
namespace Chill\MainBundle\Search;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Search\ParsingException;
/**
* This class implements abstract search with most common responses.
@@ -34,5 +35,21 @@ use Chill\MainBundle\Search\SearchInterface;
*/
abstract class AbstractSearch implements SearchInterface
{
/**
*
* @param type $string
* @return \DateTime
* @throws ParsingException if the date is not parseable
*/
public function parseDate($string)
{
try {
return new \DateTime($string);
} catch (ParsingException $ex) {
$exception = new ParsingException('The date is '
. 'not parsable', 0, $ex);
throw $exception;
}
}
}