12 namespace fpoirotte\XRL\Types;
25 return $this->value->format(static::XMLRPC_FORMAT);
32 throw new \InvalidArgumentException(
'Expected date-time value');
38 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
43 $date = new \DateTime(
'@'.$this->value->format(
'U'), $timezone);
44 if (strpos(static::XMLRPC_TYPE,
'}') !==
false) {
45 list($ns, $tagName) = explode(
'}', static::XMLRPC_TYPE, 2);
46 $ns = (string) substr($ns, 1);
47 return $writer->writeElementNS(
'ex', $tagName, $ns, $date->format(static::XMLRPC_FORMAT));
49 return $writer->writeElement(static::XMLRPC_TYPE, $date->format(static::XMLRPC_FORMAT));
53 protected static function parse(
$value, \DateTimeZone $timezone = null)
55 if ($timezone === null) {
56 $timezone = new \DateTimeZone(@date_default_timezone_get());
59 $result = \DateTime::createFromFormat(static::XMLRPC_FORMAT,
$value, $timezone);
61 if (strcasecmp(
$value, $result->format(static::XMLRPC_FORMAT))) {
62 throw new \InvalidArgumentException(
'Invalid date/time');
static parse($value,\DateTimeZone $timezone=null)
Abstract class for various "date-time" types.
The XML-RPC "dateTime" type.
$value
Current value associated with this object.
write(\XMLWriter $writer,\DateTimeZone $timezone, $stringTag)
A class representing an abstract XML-RPC type.