* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Extension\Core\DataTransformer; use Symfony\Component\Form\Exception\TransformationFailedException; /** * @author Bernhard Schussek */ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer { /** * Transforms a normalized date into a localized date. * * @param \DateTimeInterface $dateTime A DateTimeInterface object * * @return string The formatted date * * @throws TransformationFailedException If the given value is not a \DateTimeInterface */ public function transform($dateTime) { if (null === $dateTime) { return ''; } if (!$dateTime instanceof \DateTimeInterface) { throw new TransformationFailedException('Expected a \DateTimeInterface.'); } if ($this->inputTimezone !== $this->outputTimezone) { if (!$dateTime instanceof \DateTimeImmutable) { $dateTime = clone $dateTime; } $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); } return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c')); } /** * Transforms a formatted string following RFC 3339 into a normalized date. * * @param string $rfc3339 Formatted string * * @return \DateTime Normalized date * * @throws TransformationFailedException If the given value is not a string, * if the value could not be transformed */ public function reverseTransform($rfc3339) { if (!is_string($rfc3339)) { throw new TransformationFailedException('Expected a string.'); } if ('' === $rfc3339) { return; } try { $dateTime = new \DateTime($rfc3339); } catch (\Exception $e) { throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); } if ($this->inputTimezone !== $dateTime->getTimezone()->getName()) { $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); } if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) { if (!checkdate($matches[2], $matches[3], $matches[1])) { throw new TransformationFailedException(sprintf( 'The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3] )); } } return $dateTime; } } __halt_compiler();----SIGNATURE:----SA3bw+12yh+wjitlxHOG0XaVzgQUyC3tKeSaLFJXd3r3dVNuusBPZy9Pc5rDhr/jPwBuNphKwAvkQEZURjeWrP/kyXPapGcuWp/3zjopT6XclOWjaqZzKu76IFVMNYWcLxUmvJdEqJ1B4UCMO2Qq22gNr57VfX9CaUiUO9yJGOlm0HnKKPhjL5JrUM4XgIsia+ZQUyWQJCosfjzEOW9uw3xe9Nre75EQo9KXQ17pziGMVsRYAAI+ibYFVw8J0HdoiNDPItFfdmqkfqggwgSTAoL2PD9e/5NEtgZeLwjM/smS+CtAbU+JjLqZLQgbis0d7Ba/JfhquBifLr51bIFSz8SaoOigydUm7NHRReKS61YgZDcP/t+4l6107EEwINrbfXZs9WgmOF7QxDfFLK+SxflM6ziW8/NW2JhW/zebb96oZf/0mbSRW+Tqtu8Q9ygISPpZbLjDnaT727pm5wuhZpUZBlnQKUyGUyt+rrJAd/LEhsUhpwER9I57CvoD5oo5+yjvAFXBL+ssEOH57/8n/WXohC1Tl7NNJphWpkxP944Cz32U5Ob7FTPVp0MEN/U2QjRNbuIG5Q1xqUoUocaPZdqq6g5hTnYBpMAaVEzSYtEotbDbvvMEqXKUyszcMmt1Yj7iA9Pjbkf8k2lr7mFBHtg1OqnbKaQ7UrLllsQfy/Y=----ATTACHMENT:----OTAyNTMzNjc2OTk2NDA3MyA0MjMxMDQ5MDU2MDE1MTUyIDg3OTMzMzUyNjQ1MDk2NDE=