* * 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; /** * Transforms between a timestamp and a DateTime object. * * @author Bernhard Schussek * @author Florian Eckerstorfer */ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer { /** * Transforms a DateTime object into a timestamp in the configured timezone. * * @param \DateTimeInterface $dateTime A DateTimeInterface object * * @return int A timestamp * * @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.'); } return $dateTime->getTimestamp(); } /** * Transforms a timestamp in the configured timezone into a DateTime object. * * @param string $value A timestamp * * @return \DateTime A \DateTime object * * @throws TransformationFailedException If the given value is not a timestamp * or if the given timestamp is invalid */ public function reverseTransform($value) { if (null === $value) { return; } if (!is_numeric($value)) { throw new TransformationFailedException('Expected a numeric.'); } try { $dateTime = new \DateTime(); $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); $dateTime->setTimestamp($value); if ($this->inputTimezone !== $this->outputTimezone) { $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); } } catch (\Exception $e) { throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); } return $dateTime; } } __halt_compiler();----SIGNATURE:----Z4xJDg/dl+i2AvhubUgQlsH16S7v9zHOcNB8gHoPZ0h+4T+M+5ZpTjxiG1IAakTklrm4WgIne3qW16sQ/SZgiQ2845SHtCZ4cP5vlOOflDjr6AFg57CjgjLQhsBjKmdw5PrWp+9z9ajYXvV/k7c6JCQ3flj4ecmIJEnbW9Zrz8ixtxy33ph2mMkmisjj/S33cSXy2pAvNRsHRBtsqIylZAMRM67P6is4wx+VYZVeoGmBOuZy3uZ+fXdj+0qy7d+N4QNIkzF7otZXKEQdH6DeGO4pEcgZZRf1ubL/sHTgIptyw/U+jrsfd82OfRMkdkKAvMfVYaIH2vl9ID4L/nYIokGyfmJdHUR27+xfspptHMjVq7e3cVralOvFrVhGKaOet3yhdHiP3kOL/YRun2OKC10bvpE9W8/fHr1kbmEhiqx6VpilMfxCXvIq0pl3eo8Wlfz/a2PhjrEcqo9uVsYE8Fbf5icuj8KeIxK/1KJgTdUurTrCyoPPejEqb3e0Fokqt446fUgIR7e2qGos0PVrwErFyJCY46EUOxEIcnIA2p06J+TOG/ukuVqTOXX8/pNWqThvUf6pUC7TlouZAI0HTEBRvZfsuoA6h+g4Z5wKQMpgz2ZfagjZoAw60KFDvtMR8zs0EAf+4kAddtdCcRd1k8tEzzPPg8nMRgNgh4dWu5c=----ATTACHMENT:----NjgxMzI0OTc3MTU5MzM5MyA5MzQ5NjIzMTkxNTUyMjI3IDM3ODMzMTI0NTkxMDg1NTg=