Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof \DateTime) {
         return $value;
     }
     $val = \DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
     }
     return $val;
 }
 /**
  * @param \DateTimeImmutable|string|null $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return \DateTimeImmutable|null
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof DateTimeImmutable) {
         return $value;
     }
     $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value);
     if ($dateTime === false) {
         throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
     }
     return $dateTime;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $val = \DateTime::createFromFormat($platform->getTimeFormatString() . '|', $value, self::$utc ? self::$utc : (self::$utc = new \DateTimeZone('UTC')));
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this->getName());
     }
     $errors = $val->getLastErrors();
     // date was parsed to completely not valid value
     if ($errors['warning_count'] > 0 && (int) $val->format('Y') < 0) {
         return null;
     }
     return $val;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  *
  * @override
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     return $value !== null ? \DateTime::createFromFormat($platform->getTimeFormatString(), $value) : null;
 }