Jyxo\Time\Time::unserialize PHP Метод

unserialize() публичный Метод

Object deserialization.
public unserialize ( string $serialized )
$serialized string Serialized data
    public function unserialize($serialized)
    {
        try {
            $data = explode(' ', $serialized);
            if (count($data) != 3) {
                throw new \Exception('Serialized data have to be in the "Y-m-d H:i:s TimeZone" format');
            }
            if (preg_match('~([+-]\\d{2}):?([\\d]{2})~', $data[2], $matches)) {
                // Timezone defined by an UTC offset
                if ($matches[2] < 0 || $matches[2] > 59 || intval($matches[1] . $matches[2]) < -1200 || intval($matches[1] . $matches[2]) > 1200) {
                    // Invalid offset - minutes part is invalid or the whole offset is not <= 12:00 and >= -12:00
                    throw new \Exception(sprintf('Invalid time zone UTC offset definition: %s', $matches[0]));
                }
                $data[1] .= ' ' . $matches[1] . $matches[2];
                $this->dateTime = new \DateTime($data[0] . ' ' . $data[1]);
            } else {
                $this->dateTime = new \DateTime($data[0] . ' ' . $data[1], $this->createTimeZone($data[2]));
            }
        } catch (\Exception $e) {
            throw new \InvalidArgumentException('Deserialization error', 0, $e);
        }
    }