3 namespace PhpXmlRpc\Helper
;
5 use PhpXmlRpc\PhpXmlRpc
;
8 * Helps to convert timestamps to the xml-rpc date format.
10 * Feature creep -- add support for custom TZs
15 * Given a timestamp, return the corresponding ISO8601 encoded string.
17 * Really, timezones ought to be supported but the XML-RPC spec says:
19 * "Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes
22 * This routine always encodes to local time unless $utc is set to 1, in which case UTC output is produced and an
23 * adjustment for the local timezone's offset is made
25 * @param int|\DateTimeInterface $timet timestamp or datetime
26 * @param bool|int $utc (0 or 1)
29 public static function iso8601Encode($timet, $utc = 0)
31 if (is_a($timet, 'DateTimeInterface') ||
is_a($timet, 'DateTime')) {
32 $timet = $timet->getTimestamp();
35 $t = date('Ymd\TH:i:s', $timet);
37 $t = gmdate('Ymd\TH:i:s', $timet);
44 * Given an ISO8601 date string, return a timestamp in the localtime, or UTC.
46 * @param string $idate
47 * @param bool|int $utc either 0 (assume date is in local time) or 1 (assume date is in UTC)
49 * @return int (timestamp) 0 if the source string does not match the xml-rpc dateTime format
51 public static function iso8601Decode($idate, $utc = 0)
54 if (preg_match(PhpXmlRpc
::$xmlrpc_datetime_format, $idate, $regs)) {
56 $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
58 $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);