realestateconz / MssqlBundle

Symfony 2 Microsoft SQL Server Bundle
37 stars 63 forks source link

Incorrectly converted to date DateTimeType.php #26

Open valenman opened 8 years ago

valenman commented 8 years ago

In this situation date '1900-01-01 08:58:03.000' will not converted right. because condition don't have "else" block and always overwrites $val `

    $timestamp = strtotime($value);
    if($timestamp === false)
    {
        $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);

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

        $val = new \DateTime();
        $val->setTimestamp($timestamp);
    `

I think u need use this fix `

    $timestamp = strtotime($value);
    if($timestamp === false)
    {
        $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);

        if (!$val) {
            throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
        }
    } else {
        $val = new \DateTime();
        $val->setTimestamp($timestamp);
    }`