/** * iCal spec represents date in ISO 8601 format followed by "T" then the time * a "Z at the end means the time is UTC and not local time zone * * TODO make sure if time is UTC we take account of system time offset properly * */ function unixTime($ical_date, $tz = false) { jimport("joomla.utilities.date"); static $offset = null; if (is_null($offset)) { $config =& JFactory::getConfig(); $offset = $config->getValue('config.offset', 0); } if (!is_numeric($ical_date)) { $t = JevDate::strtotime($ical_date); if (JString::strpos($ical_date, "Z") > 0) { if (is_callable("date_default_timezone_set")) { $timezone = date_default_timezone_get(); // See http://www.php.net/manual/en/timezones.php $params = JComponentHelper::getParams(JEV_COM_COMPONENT); // server offset tiemzone if ($params->get("icaltimezone", "") != "") { date_default_timezone_set($params->get("icaltimezone", "")); } // server offset PARAMS $serveroffset1 = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S', $t)) - JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ', $t))) / 3600; // server offset SERVER date_default_timezone_set($timezone); $serveroffset2 = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S', $t)) - JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ', $t))) / 3600; $t = new JevDate($ical_date, $serveroffset1 - $serveroffset2); //$t = new JevDate($ical_date ); date_default_timezone_set($timezone); echo "icaldate = " . $ical_date . " imported date=" . $t->toMySQL() . "<br/>"; } else { // Summer Time adjustment list($y, $m, $d, $h, $min, $s) = explode(":", JevDate::strftime('%Y:%m:%d:%H:%M:%S', $t)); $dst = (JevDate::mktime($h, $min, $s, $m, $d, $y, 0) - JevDate::mktime($h, $min, $s, $m, $d, $y, -1)) / 3600; // server offset including DST $serveroffset = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S', $t)) - JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ', $t))) / 3600; $serveroffset += $dst; $t = new JevDate($ical_date, -($serveroffset + $offset)); } /* echo "<h3>SET TIMEZONE</h3>"; $timezone= date_default_timezone_get(); date_default_timezone_set('America/New_York'); $tempIcal = "20091020T163000Z"; echo $tempIcal."<br/>"; $temp = JevDate::strtotime($tempIcal); list($y,$m,$d,$h,$min,$s) = explode(":", JevDate::strftime('%Y:%m:%d:%H:%M:%S',$temp)); echo "$y,$m,$d,$h,$min,$s<br/>"; $dst = (JevDate::mktime($h,$min,$s,$m,$d,$y,0)-JevDate::mktime($h,$min,$s,$m,$d,$y,-1))/3600; $so = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S',$temp))-JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ',$temp)))/3600; echo " dst=".$dst." serverforoffset=".$so."<br/>"; $so += $dst; $t = new JevDate($tempIcal); echo $t->toMySQL()."<br><br/>"; $tempIcal = "20091029T163000Z"; echo $tempIcal."<br/>"; $temp = JevDate::strtotime($tempIcal); list($y,$m,$d,$h,$min,$s) = explode(":", JevDate::strftime('%Y:%m:%d:%H:%M:%S',$temp)); echo "$y,$m,$d,$h,$min,$s<br/>"; $dst = (JevDate::mktime($h,$min,$s,$m,$d,$y,0)-JevDate::mktime($h,$min,$s,$m,$d,$y,-1))/3600; $so = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S',$temp))-JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ',$temp)))/3600; echo " dst=".$dst." serverforoffset=".$so."<br/>"; $so += $dst; $t = new JevDate($tempIcal ); echo $t->toMySQL()."<br><br/>"; $tempIcal = "20091103T163000Z"; echo $tempIcal."<br/>"; $temp = JevDate::strtotime($tempIcal); list($y,$m,$d,$h,$min,$s) = explode(":", JevDate::strftime('%Y:%m:%d:%H:%M:%S',$temp)); echo "$y,$m,$d,$h,$min,$s<br/>"; $dst = (JevDate::mktime($h,$min,$s,$m,$d,$y,0)-JevDate::mktime($h,$min,$s,$m,$d,$y,-1))/3600; $so = (JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%S',$temp))-JevDate::strtotime(JevDate::strftime('%Y%m%dT%H%M%SZ',$temp)))/3600; echo " dst=".$dst." serverforoffset=".$so."<br/>"; $so += $dst; $t = new JevDate($tempIcal); echo $t->toMySQL()."<br>"; */ } else { if ($tz != false && $tz != "") { // really should use the timezone of the inputted date $tz = new DateTimeZone($tz); $t = new JevDate($ical_date, $tz); echo "icaldate = " . $ical_date . " imported date=" . $t->toMySQL() . "<br/>"; } else { $compparams = JComponentHelper::getParams(JEV_COM_COMPONENT); $jtz = $compparams->get("icaltimezonelive", ""); if ($jtz) { $t = new JevDate($ical_date, $jtz); } else { $t = new JevDate($ical_date); } } } //$result = $t->toMySQL(); $result = $t->toUnix(); return $result; } $isUTC = false; if (JString::strpos($ical_date, "Z") !== false) { $isUTC = true; } // strip "T" and "Z" from the string $ical_date = str_replace('T', '', $ical_date); $ical_date = str_replace('Z', '', $ical_date); // split it out intyo YYYY MM DD HH MM SS preg_match("#([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})([0-9]{0,2})#", $ical_date, $date); list($temp, $y, $m, $d, $h, $min, $s) = $date; if (!$min) { $min = 0; } if (!$h) { $h = 0; } if (!$d) { $d = 0; } if (!$s) { $s = 0; } // Trap unix dated beofre 1970 $y = max($y, 1970); if ($isUTC) { $t = gmJevDate::mktime($h, $min, $s, $m, $d, $y) + 3600 * $offset; $result = JevDate::strtotime(gmdate('Y-m-d H:i:s', $t)); } else { $result = JevDate::mktime($h, $min, $s, $m, $d, $y); } // double check!! //list($y1,$m1,$d1,$h1,$min1,$s1)=explode(":",JevDate::strftime('%Y:%m:%d:%H:%M:%S',$result)); return $result; }