* * 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:----N2tvNC3ao98UXDtd9IiZNciAfCePRBVyfSBjCX6kWS9B5OBhJwtzryF3Q8yoLPapAxQ08IEujl6HnqmNfZVaSgqOR+PC5Mrm2gHCPoKXWeT9PhWnIn5CutxlKZk+gjZNmP9nD7taWx+6wClvUzMeMa8Rl9x44ZeGPlvGDVkaYGV31tiF8efCNkWuT4LuzFHqF9kCG9viocf8Ku8FOmc3AYkII+GfOsOJh3q9W5vOTFkiH5M8yFDZVvMz10vjZmwdgR3EEzVDvFbKOWHU0TRzo6qcn1HA+xR+EGx+Ncm/IVulkq0agY99/94x/8lzYMKPMZvjndSCaZoSWtswfSHmbv+rVfwpw4z0FmBj61wZIxAqqSpc8cYFdmZNEDeYJ24I7WeO39jAGihrABhSULFu9QHrQBzEov/WC4IhSVgtc5iJwFBIud8h+csEa8Kxfj5pg4Ij4qLekNEkh9ZHEilShksb4XkDL6nifYqa0mNUwjeve92tktdkw9bI8msLQaxcgUpEi92p3iw7Z+nvhPCMpEOlLHXR2WHWS+SFV4ocrVmvX+P733XivGdcKYIKc53GHNFVv/YtU89mIXg43r5v4BFMcGNdFUtQL1u/fj+SNiftXMTtyiu/Bl4NJtoectYGIxyNvOvwQa/XKL0Zvlbwxbb64Xt/oO5i+rbdPk+tzuM=----ATTACHMENT:----NTI0Mjk2NzIyMzQ3MDkyMyAzNTE5NzY2NTI2NzYyMzUwIDgzMjA0ODEwMDIyNjA1NTg=