Last active
December 17, 2015 05:18
-
-
Save davidwindell/5556527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Handle various type conversions that should be supported natively by Doctrine (like DateTime) | |
* | |
* @param mixed $value | |
* @param string $typeOfField | |
* @return DateTime | |
*/ | |
protected function handleTypeConversions($value, $typeOfField) | |
{ | |
switch($typeOfField) { | |
case 'datetime': | |
case 'time': | |
case 'date': | |
if ($value === '') { | |
return null; | |
} | |
if (is_int($value)) { | |
$dateTime = new DateTime(); | |
$dateTime->setTimestamp($value); | |
$value = $dateTime; | |
} elseif (is_string($value)) { | |
$value = new DateTime($value); | |
} | |
break; | |
default: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment