You are here

function xmlrpc_date in xmlrpc 8

Converts a PHP or ISO date/time to an XML-RPC object.

Parameters

int|string $time: A PHP timestamp or an ISO date-time string.

Return value

object An XML-RPC time/date object.

3 calls to xmlrpc_date()
XmlRpcValidatorTest::testValidator in src/Tests/XmlRpcValidatorTest.php
Run validator1 tests.
xmlrpc_message_tag_close in ./xmlrpc.inc
Handles closing tags for XML parsing in xmlrpc_message_parse().
xmlrpc_test_many_types_test in tests/modules/xmlrpc_test/xmlrpc_test.module
Test function accepting multiple parameters of different types.

File

./xmlrpc.inc, line 490
Drupal XML-RPC library.

Code

function xmlrpc_date($time) {
  $xmlrpc_date = new stdClass();
  $xmlrpc_date->is_date = TRUE;

  // $time can be a PHP timestamp or an ISO one.
  if (is_numeric($time)) {
    $xmlrpc_date->year = gmdate('Y', $time);
    $xmlrpc_date->month = gmdate('m', $time);
    $xmlrpc_date->day = gmdate('d', $time);
    $xmlrpc_date->hour = gmdate('H', $time);
    $xmlrpc_date->minute = gmdate('i', $time);
    $xmlrpc_date->second = gmdate('s', $time);
    $xmlrpc_date->iso8601 = gmdate('Ymd\\TH:i:s', $time);
  }
  else {
    $xmlrpc_date->iso8601 = $time;
    $time = str_replace([
      '-',
      ':',
    ], '', $time);
    $xmlrpc_date->year = substr($time, 0, 4);
    $xmlrpc_date->month = substr($time, 4, 2);
    $xmlrpc_date->day = substr($time, 6, 2);
    $xmlrpc_date->hour = substr($time, 9, 2);
    $xmlrpc_date->minute = substr($time, 11, 2);
    $xmlrpc_date->second = substr($time, 13, 2);
  }
  return $xmlrpc_date;
}