You are here

function iso8601_to_timestamp in Salesforce Suite 5.2

Same name in this branch
  1. 5.2 includes/nusoap.php \iso8601_to_timestamp()
  2. 5.2 includes/nusoap.orig.php \iso8601_to_timestamp()
Same name and namespace in other branches
  1. 5 includes/nusoap.php \iso8601_to_timestamp()
  2. 5 includes/nusoap.orig.php \iso8601_to_timestamp()

convert ISO 8601 compliant date string to unix timestamp

@access public

Parameters

string $datestr ISO 8601 compliant date string:

File

includes/nusoap.php, line 857

Code

function iso8601_to_timestamp($datestr) {
  $eregStr = '([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})?';

  // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
  if (ereg($eregStr, $datestr, $regs)) {

    // not utc
    if ($regs[8] != 'Z') {
      $op = substr($regs[8], 0, 1);
      $h = substr($regs[8], 1, 2);
      $m = substr($regs[8], strlen($regs[8]) - 2, 2);
      if ($op == '-') {
        $regs[4] = $regs[4] + $h;
        $regs[5] = $regs[5] + $m;
      }
      elseif ($op == '+') {
        $regs[4] = $regs[4] - $h;
        $regs[5] = $regs[5] - $m;
      }
    }
    return strtotime("{$regs[1]}-{$regs[2]}-{$regs[3]} {$regs[4]}:{$regs[5]}:{$regs[6]}Z");
  }
  else {
    return false;
  }
}