DatatypeNormalizer/DateTimeNormalizer.php
public function denormalize($data, $class, $format = null, array $context = array())
    {
        $value = $data;

        if (is_array($data)) {
            if (!isset($data['@value']) || !isset($data['@type'])) {
                throw new RuntimeException(
                    "Cannot denormalize the data as it isn't a valid JSON-LD typed value: " .
                    var_export($data, true)
                );
            }

            if (self::XSD_DATETIME_IRI !== $data['@type']) {
                throw new RuntimeException(
                    "Cannot denormalize the data as it isn't a XSD dateTime value: " .
                    var_export($data, true)
                );
            }

            $value = $data['@value'];
        } elseif (!is_string($data)) {
            throw new RuntimeException(
                "Cannot denormalize the data into a DateTime object: " .
                var_export($data, true)
            );
        }

        try {
            $date = new \DateTime($value);

            return $date;
        } catch(Exception $e) {
            throw new RuntimeException(
                "Cannot denormalize the data as the value is invalid: " . var_export($data, true),
                0,
                $e
            );
        }
    }
public function denormalize($data, $class, $format = null, array $context = array())
    {
        $value = $data;

        if (is_array($data)) {
            if (!isset($data['@value']) || !isset($data['@type'])) {
                throw new RuntimeException(
                    "Cannot denormalize the data as it isn't a valid JSON-LD typed value: " .
                    var_export($data, true)
                );
            }

            if (self::XSD_DATETIME_IRI !== $data['@type']) {
                throw new RuntimeException(
                    "Cannot denormalize the data as it isn't a XSD dateTime value: " .
                    var_export($data, true)
                );
            }

            $value = $data['@value'];
        } elseif (!is_string($data)) {
            throw new RuntimeException(
                "Cannot denormalize the data into a DateTime object: " .
                var_export($data, true)
            );
        }

        try {
            $date = new \DateTime($value);

            return $date;
        } catch(Exception $e) {
            throw new RuntimeException(
                "Cannot denormalize the data as the value is invalid: " . var_export($data, true),
                0,
                $e
            );
        }
    }
public function denormalize ( $ data , $ class , $ format = null , array $ context = array ( ) ) { $ value = $ data ; if ( is_array ( $ data ) ) { if ( ! isset ( $ data [ '@value' ] ) || ! isset ( $ data [ '@type' ] ) ) { throw new RuntimeException ( "Cannot denormalize the data as it isn't a valid JSON-LD typed value: " . var_export ( $ data , true ) ) ; } if ( self :: XSD_DATETIME_IRI !== $ data [ '@type' ] ) { throw new RuntimeException ( "Cannot denormalize the data as it isn't a XSD dateTime value: " . var_export ( $ data , true ) ) ; } $ value = $ data [ '@value' ] ; } elseif ( ! is_string ( $ data ) ) { throw new RuntimeException ( "Cannot denormalize the data into a DateTime object: " . var_export ( $ data , true ) ) ; } try { $ date = new \ DateTime ( $ value ) ; return $ date ; } catch ( Exception $ e ) { throw new RuntimeException ( "Cannot denormalize the data as the value is invalid: " . var_export ( $ data , true ) , 0 , $ e ) ; } }
Denormalizes data back into an object of the given class

@param mixed  $data   data to restore
@param string $class  the expected class to instantiate
@param string $format format the given data was extracted from
@param array  $context options available to the denormalizer

@return DateTime

@throws RuntimeException If the data can't be denormalized
Denormalizes data back into an object of the given class