* * 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:----rYWB2j0MNIOPVzn/wXFC+An95axQxm6RkgUtiVrQ6FsaQ8Z8FhqJnkxj8WgeVC2n2p4R7VUeFp8hk9RGTNEgH7TSvpizaGZj26MShrqgDShwBTLbn1og63jIyk20dInYUXa1YLKfEgq3XxKUSWnqOjNODiNjy361Lcqc7dYbr4e8CDHMkxf61RZ6CiWV4pQ7gXBStqU47ZvF/vsBYUF19FxSId61Drl0KupR2njA36XjhNzUugHOFYpCuXJxNEYdEI3i6BJgPVPLiw49/jhYR4JYFFVnmyJUVD5HxZmDaLAJVbY8DgI9/xwkLv2sz4h1gSWdW8CJNDH7mit5j/nzObq7/lB2dy9HZTuiCvHtdHnhCybg9b/lA/oFCAevcUjYQYpyY2kSFUoPwQhNED7MxNpecLZ5/zR3eEAt+P7rDFGyqkrn6/TykVaVW2FlNIhoLxt0Kkd4xCgGb+ehn5JEk7SDWJtsfVF0LA94GoE/TfzuNwe6Sc1E/S5ZjE6r5CLPAhCa+LMKqjPMZ5yqwa/LWYg7SszPxRho4mSWgx7qQUOnytDaHN93/dJCQVSVwVP5POFBD8kFZZtSgvCvplXMLgJFNpfnmMwJYb4OnCnv2vZ6RC+IFeE5H9qwDyQjMA6tT7WrH0maqJiKbxYdTD0dz0jWYZJ6q7eESb4rrCTRSrI=----ATTACHMENT:----MTI5NTMxNTczMTgxNTQyNiA0NTA1NzA4NzEzMDkyMjI2IDE4NzI2NTQxMjI4ODQxMTQ=