3 namespace PhpXmlRpc\Helper;
8 * Given a timestamp, return the corresponding ISO8601 encoded string.
10 * Really, timezones ought to be supported but the XML-RPC spec says:
12 * "Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes
15 * These routines always assume localtime unless $utc is set to 1, in which case UTC is assumed and an adjustment
16 * for locale is made when encoding
18 * @param int $timet (timestamp)
19 * @param int $utc (0 or 1)
23 public static function iso8601Encode($timet, $utc = 0)
26 $t = strftime("%Y%m%dT%H:%M:%S", $timet);
28 if (function_exists('gmstrftime')) {
29 // gmstrftime doesn't exist in some versions of PHP
30 $t = gmstrftime("%Y%m%dT%H:%M:%S", $timet);
32 $t = strftime("%Y%m%dT%H:%M:%S", $timet - date('Z'));
40 * Given an ISO8601 date string, return a timet in the localtime, or UTC.
42 * @param string $idate
43 * @param int $utc either 0 or 1
45 * @return int (datetime)
47 public static function iso8601Decode($idate, $utc = 0)
50 if (preg_match('/([0-9]{4})([0-1][0-9])([0-3][0-9])T([0-2][0-9]):([0-5][0-9]):([0-5][0-9])/', $idate, $regs)) {
52 $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
54 $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);