{@inheritdoc}
Convert a string value into a DateTime object

@param string|int|null $value
@return \DateTime|null
346335
public function hydrate($value)
    {
        if ($this->nullable && $value === null) {
            return null;
        }

        if (is_string($value) || is_int($value)) {
            if ($dateTime = DateTime::createFromFormat($this->getFormat(), $value)) {
                return $dateTime;
            }

            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid format or value: format must be a string representing a valid \DateTime format, "%s" given;' .
                'value must be a string representing the time according to \DateTime::createFromFormat(), "%s" given.',
                $this->getFormat(),
                $value
            ));
        }

        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be a string or integer representing the time according to the format, "%s" given',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
855339
public function age($value)
    {
        if (!isset($value)) {
            return null;
        }
        
        $date = $this->valueToDateTime($value);
        
        return $date->diff(new \DateTime())->format('%y');
    }
678661
public function reverseTransform($value)
    {
        if ( $value['date'] && $value['time'] ) {
            return new \DateTime(sprintf(
                '%s %s',
                $value['date']->format('Y-m-d'),
                $value['time']->format('H:i:s')
            ));
        }
        if ( $value['date'] ) {
            return new \DateTime(sprintf(
                '%s',
                $value['date']->format('Y-m-d')
            ));
        }
        if ( $value['time'] ) {
            return new \DateTime(sprintf(
                '%s',
                $value['time']->format('H:i:s')
            ));
        }
        return null;
    }
687021
private function normaliseDateTime($value)
    {
        $value = trim($value);
        switch (true) {
            case (null === $value):
                return $value;
        }
        throw new \RuntimeException('Invalid DateTime default value: ' . $value);
    }
733751
private static function _parseDateTimeString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
906231
public function set($value = null)
	{
		$ts = sfDateTimeToolkit::getTS($value);
		
		$this->ts = $ts;
		if ($this->init === null)
		{
			$this->init = $ts;
		}
		
		return $this;
	}
490700
public function filter($value) {
        if($value === null)
            return null;

        try {
            $sourceDT = new DateTime($value);
            $targetTZ = new DateTimeZone($this->options["timezone"] ? $this->options["timezone"] : date_default_timezone_get());
            $targetDT = $sourceDT;
            $targetDT->setTimeZone($targetTZ);

            return $targetDT->format($this->options["format"]);
        }
        catch(Exception $e) {
            return false;
        }
    }
513984
private static function fromTimestamp($value)
    {
        $result = false;
        if (empty($value)) {
            return $result;
        }

        $result = new \DateTime($value);

        return $result->getTimestamp();
    }
455161
public function getDateTime(int $value): DateTime
    {
        if ($value > 9999999999) { // microseconds it is
            $value = floor($value / 1000000);
        }

        return DateTime::createFromFormat("U", $value);
    }
251886
public function datetime($name = null, $value = null) 
	{
		Argument::i()
			->test(1, 'string', 'null')
			->test(2, 'scalar', 'null');
			
		$field = Datetime::i();
		
		if(!is_null($name)) {
			$field->setName($name);
		}
		
		if(!is_null($value)) {
			$field->setValue($value);
		}
		
		return $field;
	}
1355491
public static function datetime($value, $format = 'Y-m-d H:i:s')
    {
        if (empty($value)) {
            return null;    
        }
        
        $datetime = new \DateTime($value);

        return $datetime->format($format);
    }
1238452
public function timestamp($value = null)
    {
        // Use now if no time was passed
        if ( ! $value) $value = $this->freshTimestamp();

        return $this->fromDateTime($value);
    }
1092700
protected function getDateTime($value)
    {
        try {
            if ($this->isTestingRelativeDateTime($value)) {
                return Date::parse($value);
            }

            return new DateTime($value);
        } catch (Exception $e) {
            //
        }
    }
838321
public static function createFromInput($value)
    {
        $timestamp = strtotime($value);

        try {
            // trim java ms
            $value = preg_replace('`(\\.[0-9]{3})\\+`', '+', $value);

            $datetime = self::createFromFormat(self::DATE_FORMAT, $value);

            if ($timestamp != $datetime->getTimestamp()) {
                throw new ResponseCode("Invalid datetime with value '$value'", 422);
            }
        } catch (\Exception $exception) {
            throw new ResponseCode("Invalid datetime format with value '$value'", 422);
        }

        return $datetime;
    }
396144
public function dateTime($value, $type = NULL)
    {
        $apend = "";
        switch ($type) {
            case 'time':
                    $apend = 'time';
                break;
            case 'timestamp':
                    $apend = 'timestamp';
                break;
            case 'date':
                    $apend = 'date';
                break;
            case 'datetime':
                    $apend = 'datetime';
                break;
            case 'year':
                    $apend = 'year(4)';
                break;
            default:
                    $apend = 'timestamp';
                break;
        }
        return $value . " " . $apend . " NOT NULL";
    }
999848
public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if (!$value || !is_string($value)) {
            return null;
        }

        $timepoint = self::getParsingClock()->fromString($value, 'Y-m-d H:i:s');

        if (!$timepoint) {
            throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
        }

        return $timepoint;
    }
387747
protected function handleDateParameter( $value )
    {
        $date = DateTime::createFromFormat(
            self::XML_RPC_ISO8601, (string)$value, new \DateTimeZone( 'UTC' )
        );

        // no separators, maybe, try again
        if ( $date instanceof DateTime )
        {
            $date->setTimezone( new DateTimeZone( date_default_timezone_get() ) );
            return $date;
        }

        $parts = explode( 'T', $value );

        if ( count( $parts ) != 2 )
            throw new UnexpectedValueException( "Invalid date $value" );
        if ( strlen( $parts[0] ) !== 8 || strlen( $parts[1] ) != 8)
            throw new UnexpectedValueException( "Invalid date $value" );

        $dateParts = array();
        sscanf( $parts[0], '%04d%02d%02d', $dateParts['year'], $dateParts['month'], $dateParts['day'] );
        sscanf( $parts[1], '%02d:%02d:%02d', $dateParts['hours'], $dateParts['minutes'], $dateParts['seconds'] );
        $iso8601date = sprintf(
            '%4d-%02d-%02dT%02d:%02d:%02d',
            $dateParts['year'], $dateParts['month'], $dateParts['day'],
            $dateParts['hours'], $dateParts['minutes'], $dateParts['seconds']
        );

        $date = DateTime::createFromFormat( self::XML_RPC_ISO8601, $iso8601date, new DateTimeZone( 'UTC' ) );
        if ( $date instanceof DateTime )
        {
            $date->setTimezone( new DateTimeZone( date_default_timezone_get() ) );
            return $date;
        }
        return $date;
    }