ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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. More...
 
 encode ()
 Encode the instance into XML, for transport. More...
 
- Public Member Functions inherited from XML_RPC2_Backend_Php_Value
 getNativeValue ()
 nativeValue property getter More...
 

Static Public Member Functions

static decode ($xml)
 Decode transport XML and set the instance value accordingly. More...
 
- 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. More...
 
static createFromDecode ($simpleXML)
 Decode an encoded value and build the applicable XML_RPC2_Value subclass. More...
 
- Static Public Member Functions inherited from XML_RPC2_Value
static createFromNative ($value, $explicitType=null)
 Factory method that constructs the appropriate XML-RPC encoded type value. More...
 

Static Private Member Functions

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

Additional Inherited Members

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

Detailed Description

Definition at line 65 of file Datetime.php.

Constructor & Destructor Documentation

◆ __construct()

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().

80  {
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)));
83  }
84  if ((is_object($nativeValue)) &&(strtolower(get_class($nativeValue)) == 'stdclass') && (isset($nativeValue->xmlrpc_type))) {
85  $scalar = $nativeValue->scalar;
86  $timestamp = $nativeValue->timestamp;
87  } else {
88  if ((is_int($nativeValue)) or (is_float($nativeValue))) {
90  $timestamp = (int) $nativeValue;
91  } elseif (is_string($nativeValue)) {
92  $scalar= $nativeValue;
94  } else {
95  throw new XML_RPC2_InvalidTypeException(sprintf('Cannot create XML_RPC2_Backend_Php_Value_Datetime from type \'%s\'.', gettype($nativeValue)));
96  }
97  }
98  $tmp = new stdclass();
99  $tmp->scalar = $scalar;
100  $tmp->timestamp = $timestamp;
101  $tmp->xmlrpc_type = 'datetime';
102  $this->setNativeValue($tmp);
103  }
static _timestampToIso8601($timestamp)
Convert a timestamp into an iso8601 datetime.
Definition: Datetime.php:152
static _iso8601ToTimestamp($datetime)
Convert a iso8601 datetime string into timestamp.
Definition: Datetime.php:114
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
setNativeValue($value)
nativeValue setter
Definition: Value.php:89
+ Here is the call graph for this function:

Member Function Documentation

◆ _iso8601ToTimestamp()

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().

115  {
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)) {
117  throw new XML_RPC2_InvalidDateFormatException(sprintf('Provided date \'%s\' is not ISO-8601.', $datetime));
118  }
119  $year = $matches[1];
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') {
128  $tzSeconds = 0;
129  } else {
130  $tmp = ($matches[15] == '-') ? -1 : 1;
131  $tzSeconds = $tmp * (((int) $matches[16]) * 3600 + ((int) $matches[17]) * 60);
132  }
133  } else {
134  $tzSeconds = 0;
135  }
136  $result = ((double) @mktime($hour, $minutes, $seconds, $month, $day, $year, 0)) +
137  ((double) $milliseconds) -
138  ((double) $tzSeconds);
139  if ($milliseconds==0) return ((int) $result);
140  return $result;
141  }
$result
+ Here is the caller graph for this function:

◆ _timestampToIso8601()

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().

153  {
154  return strftime('%Y%m%dT%H:%M:%S', (int) $timestamp);
155  }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
+ Here is the caller graph for this function:

◆ decode()

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().

166  {
167  // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
168  // xpath is used both in an element and in one of its children
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()');
173  }
174  // Emulate xmlrpcext results (to be able to switch from a backend to another)
175  $result = new stdclass();
176  $result->scalar = (string) $value[0];
177  $result->timestamp = (int) XML_RPC2_Backend_Php_Value_Datetime::_iso8601ToTimestamp((string) $value[0]);
178  $result->xmlrpc_type = 'datetime';
179  return $result;
180  }
$result
static _iso8601ToTimestamp($datetime)
Convert a iso8601 datetime string into timestamp.
Definition: Datetime.php:114
+ Here is the call graph for this function:

◆ encode()

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().

191  {
192  $native = $this->getNativeValue();
193  return '<dateTime.iso8601>' . $native->scalar . '</dateTime.iso8601>';
194  }
getNativeValue()
nativeValue property getter
Definition: Value.php:76
+ Here is the call graph for this function:

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