safer casting of datetime

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-03-14 14:12:40 +01:00
parent ef14dc671f
commit e392d02d80
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
1 changed files with 5 additions and 1 deletions

View File

@ -262,7 +262,11 @@ class FileSearchBackend implements ISearchBackend {
case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
return 0 + $value;
case SearchPropertyDefinition::DATATYPE_DATETIME:
return \DateTime::createFromFormat(\DateTime::ATOM, $value)->getTimestamp();
if (is_numeric($value)) {
return 0 + $value;
}
$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
default:
return $value;
}