43 require_once
'XML/RPC2/Exception.php';
44 require_once
'XML/RPC2/Backend/Php/Value/Scalar.php';
81 if ((!is_int($nativeValue)) and (!is_float($nativeValue)) and (!is_string($nativeValue)) and (!is_object($nativeValue))) {
82 throw new XML_RPC2_InvalidTypeException(sprintf(
'Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
84 if ((is_object($nativeValue)) &&(strtolower(get_class($nativeValue)) ==
'stdclass') && (isset($nativeValue->xmlrpc_type))) {
85 $scalar = $nativeValue->scalar;
88 if ((is_int($nativeValue)) or (is_float($nativeValue))) {
91 } elseif (is_string($nativeValue)) {
92 $scalar= $nativeValue;
95 throw new XML_RPC2_InvalidTypeException(sprintf(
'Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
98 $tmp =
new stdclass();
99 $tmp->scalar = $scalar;
101 $tmp->xmlrpc_type =
'datetime';
116 if (!preg_match(
'/([0-9]{4})(-?([0-9]{2})(-?([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?/', $datetime, $matches)) {
120 $month = array_key_exists(3, $matches) ? $matches[3] : 1;
121 $day = array_key_exists(5, $matches) ? $matches[5] : 1;
122 $hour = array_key_exists(7, $matches) ? $matches[7] : 0;
123 $minutes = array_key_exists(8, $matches) ? $matches[8] : 0;
124 $seconds = array_key_exists(10, $matches) ? $matches[10] : 0;
125 $milliseconds = array_key_exists(12, $matches) ? ((double) (
'0.' . $matches[12])) : 0;
126 if (array_key_exists(13, $matches)) {
127 if ($matches[13] ==
'Z') {
130 $tmp = ($matches[15] ==
'-') ? -1 : 1;
131 $tzSeconds = $tmp * (((int) $matches[16]) * 3600 + ((int) $matches[17]) * 60);
136 $result = ((double) @mktime($hour, $minutes, $seconds, $month, $day, $year, 0)) +
137 ((
double) $milliseconds) -
138 ((
double) $tzSeconds);
139 if ($milliseconds==0)
return ((
int) $result);
154 return strftime(
'%Y%m%dT%H:%M:%S', (
int)
$timestamp);
169 $xml = simplexml_load_string($xml->asXML());
170 $value = $xml->xpath(
'/value/dateTime.iso8601/text()');
171 if (!array_key_exists(0, $value)) {
172 $value = $xml->xpath(
'/value/text()');
175 $result =
new stdclass();
176 $result->scalar = (string) $value[0];
178 $result->xmlrpc_type =
'datetime';
193 return '<dateTime.iso8601>' . $native->scalar .
'</dateTime.iso8601>';