
Galmok - 2009-05-11 15:06:43 -
In reply to message 11 from Protung Dragos
In case anyone is looking for datetime support, I got this to work:
/**
* getCurrentDate: returns dateTime
*
* @return DateTime $datetime
*/
function getCurrentDate() {
return new SoapVar(time(), XSD_DATETIME);
}
This will take the unix timestamp and return the date and time correctly.
Receiving datetime from a client is more difficult and I did it this way (php 5.2.9):
server:
/**
* Set date and time
*
* @param datetime $datetime
* @return DateTime $datetime
*/
function setDateTime($datetime) {
if ($datetime) {
try {
$dt = new SOAP_Type_dateTime($datetime);
$dt_u=$dt->toUnixtime();
// $dt_u is -1 if the string can't be converted
return new SoapVar($dt_u, XSD_DATETIME);
}
catch(Exception $ex) {
throw new SoapFault("Server", "Error: " . $ex);
}
} else {
throw new SoapFault("Server", "No time was given");
}
}
client:
$t=time();
$dt = new SoapVar($t, XSD_DATETIME);
$par = new SoapParam($dt, "datetime");
print($client->setDateTime($par));
Next adventure: Sending and receiving of nested arrays... (no idea so far)