ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
XML_RPC2_Backend_Php_Value_Datetime Class Reference
+ Inheritance diagram for XML_RPC2_Backend_Php_Value_Datetime:
+ Collaboration diagram for XML_RPC2_Backend_Php_Value_Datetime:

Public Member Functions

 __construct ($nativeValue)
 Constructor.
 encode ()
 Encode the instance into XML, for transport.
- Public Member Functions inherited from XML_RPC2_Backend_Php_Value
 getNativeValue ()
 nativeValue property getter

Static Public Member Functions

static decode ($xml)
 Decode transport XML and set the instance value accordingly.
- Static Public Member Functions inherited from XML_RPC2_Backend_Php_Value
static createFromNative ($nativeValue, $explicitType=null)
 Choose a XML_RPC2_Value subclass appropriate for the given value and create it.
static createFromDecode ($simpleXML)
 Decode an encoded value and build the applicable XML_RPC2_Value subclass.

Static Private Member Functions

static _iso8601ToTimestamp ($datetime)
 Convert a iso8601 datetime string into timestamp.
static _timestampToIso8601 ($timestamp)
 Convert a timestamp into an iso8601 datetime.

Additional Inherited Members

- Protected Member Functions inherited from XML_RPC2_Backend_Php_Value
 setNativeValue ($value)
 nativeValue setter

Detailed Description

Definition at line 65 of file Datetime.php.

Constructor & Destructor Documentation

XML_RPC2_Backend_Php_Value_Datetime::__construct (   $nativeValue)

Constructor.

Will build a new XML_RPC2_Backend_Php_Value_Datetime with the given value

The provided value can be an int, which will be interpreted as a Unix timestamp, or a string in iso8601 format, or a "stdclass native value"

Parameters
mixed$nativeValuea timestamp, an iso8601 date or a "stdclass native value"
See Also
http://www.w3.org/TR/NOTE-datetime

Definition at line 79 of file Datetime.php.

References $timestamp, _iso8601ToTimestamp(), _timestampToIso8601(), and XML_RPC2_Backend_Php_Value\setNativeValue().

{
if ((!is_int($nativeValue)) and (!is_float($nativeValue)) and (!is_string($nativeValue)) and (!is_object($nativeValue))) {
throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
}
if ((is_object($nativeValue)) &&(strtolower(get_class($nativeValue)) == 'stdclass') && (isset($nativeValue->xmlrpc_type))) {
$scalar = $nativeValue->scalar;
$timestamp = $nativeValue->timestamp;
} else {
if ((is_int($nativeValue)) or (is_float($nativeValue))) {
$timestamp = (int) $nativeValue;
} elseif (is_string($nativeValue)) {
$scalar= $nativeValue;
} else {
throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
}
}
$tmp = new stdclass();
$tmp->scalar = $scalar;
$tmp->timestamp = $timestamp;
$tmp->xmlrpc_type = 'datetime';
$this->setNativeValue($tmp);
}

+ Here is the call graph for this function:

Member Function Documentation

static XML_RPC2_Backend_Php_Value_Datetime::_iso8601ToTimestamp (   $datetime)
staticprivate

Convert a iso8601 datetime string into timestamp.

Parameters
string$datetimeiso8601 datetime
Returns
int corresponding timestamp

Definition at line 114 of file Datetime.php.

References $result.

Referenced by __construct(), and decode().

{
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)) {
throw new XML_RPC2_InvalidDateFormatException(sprintf('Provided date \'%s\' is not ISO-8601.', $datetime));
}
$year = $matches[1];
$month = array_key_exists(3, $matches) ? $matches[3] : 1;
$day = array_key_exists(5, $matches) ? $matches[5] : 1;
$hour = array_key_exists(7, $matches) ? $matches[7] : 0;
$minutes = array_key_exists(8, $matches) ? $matches[8] : 0;
$seconds = array_key_exists(10, $matches) ? $matches[10] : 0;
$milliseconds = array_key_exists(12, $matches) ? ((double) ('0.' . $matches[12])) : 0;
if (array_key_exists(13, $matches)) {
if ($matches[13] == 'Z') {
$tzSeconds = 0;
} else {
$tmp = ($matches[15] == '-') ? -1 : 1;
$tzSeconds = $tmp * (((int) $matches[16]) * 3600 + ((int) $matches[17]) * 60);
}
} else {
$tzSeconds = 0;
}
$result = ((double) @mktime($hour, $minutes, $seconds, $month, $day, $year, 0)) +
((double) $milliseconds) -
((double) $tzSeconds);
if ($milliseconds==0) return ((int) $result);
return $result;
}

+ Here is the caller graph for this function:

static XML_RPC2_Backend_Php_Value_Datetime::_timestampToIso8601 (   $timestamp)
staticprivate

Convert a timestamp into an iso8601 datetime.

Parameters
int$timestamptimestamp
Returns
string iso8601 datetim

Definition at line 152 of file Datetime.php.

References $timestamp.

Referenced by __construct().

{
return strftime('%Y%m%dT%H:%M:%S', (int) $timestamp);
}

+ Here is the caller graph for this function:

static XML_RPC2_Backend_Php_Value_Datetime::decode (   $xml)
static

Decode transport XML and set the instance value accordingly.

Parameters
mixedThe encoded XML-RPC value,

Definition at line 165 of file Datetime.php.

References $result, and _iso8601ToTimestamp().

{
// TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
// xpath is used both in an element and in one of its children
$xml = simplexml_load_string($xml->asXML());
$value = $xml->xpath('/value/dateTime.iso8601/text()');
if (!array_key_exists(0, $value)) {
$value = $xml->xpath('/value/text()');
}
// Emulate xmlrpcext results (to be able to switch from a backend to another)
$result = new stdclass();
$result->scalar = (string) $value[0];
$result->timestamp = (int) XML_RPC2_Backend_Php_Value_Datetime::_iso8601ToTimestamp((string) $value[0]);
$result->xmlrpc_type = 'datetime';
return $result;
}

+ Here is the call graph for this function:

XML_RPC2_Backend_Php_Value_Datetime::encode ( )

Encode the instance into XML, for transport.

Returns
string The encoded XML-RPC value,

Definition at line 190 of file Datetime.php.

References XML_RPC2_Backend_Php_Value\getNativeValue().

{
$native = $this->getNativeValue();
return '<dateTime.iso8601>' . $native->scalar . '</dateTime.iso8601>';
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: