/** * Set the value of a dateTime.iso8601 native type * * The value is in iso8601 format, minus any timezone information or dashes * * @param mixed $value Integer of the unix timestamp or any string that can be parsed * to a unix timestamp using the PHP strtotime() function */ public function __construct($value) { $this->_type = self::XMLRPC_TYPE_DATETIME; if ($value instanceof \DateTime) { $this->_value = $value->format($this->_phpFormatString); } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer $this->_value = date($this->_phpFormatString, (int) $value); } else { try { $dateTime = new \DateTime($value); } catch (\Exception $e) { throw new Exception\ValueException($e->getMessage(), $e->getCode(), $e); } $this->_value = $dateTime->format($this->_phpFormatString); // Convert the DateTime to iso8601 format } }
/** * @group ZF-10776 */ public function testGetValueDatetime() { $expectedValue = '20100101T00:00:00'; $phpDatetime = new DateTime('20100101T00:00:00'); $phpDateNative = '20100101T00:00:00'; $xmlRpcValueDateTime = new Value\DateTime($phpDatetime); $this->assertEquals($expectedValue, $xmlRpcValueDateTime->getValue()); $xmlRpcValueDateTime = new Value\DateTime($phpDateNative); $this->assertEquals($expectedValue, $xmlRpcValueDateTime->getValue()); }