/** * transforms a dateTime from a timezone to another using PHP DateTime and DateTimeZone class (PHP >= PHP 5.2.0) * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.11.14 - 2012-01-24 * @param mixed $date, date to alter * @param string $tzFrom, PHP valid old timezone * @param string $tzTo, PHP valid new timezone, default 'UTC' * @param string $format, date output format, default 'Ymd\THis' * @return bool */ public static function transformDateTime(&$date, $tzFrom, $tzTo = 'UTC', $format = 'Ymd\\THis') { if (!class_exists('DateTime') || !class_exists('DateTimeZone')) { return FALSE; } if (is_array($date) && isset($date['timestamp'])) { $timestamp = $date['timestamp']; } elseif (iCalUtilityFunctions::_isArrayDate($date)) { if (isset($date['tz'])) { unset($date['tz']); } $date = iCalUtilityFunctions::_format_date_time(iCalUtilityFunctions::_date_time_array($date)); if ('Z' == substr($date, -1)) { $date = substr($date, 0, strlen($date) - 2); } if (FALSE === ($timestamp = strtotime($date))) { return FALSE; } } elseif (FALSE === ($timestamp = @strtotime($date))) { return FALSE; } try { $d = new DateTime(date('Y-m-d H:i:s', $timestamp), new DateTimeZone($tzFrom)); $d->setTimezone(new DateTimeZone($tzTo)); } catch (Exception $e) { return FALSE; } $date = $d->format($format); return TRUE; }
/** * creates formatted output for calendar component property data value type recur * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.4.8 - 2008-10-22 * @param array $recurlabel * @param array $recurdata * @return string */ function _format_recur($recurlabel, $recurdata) { $output = null; foreach ($recurdata as $therule) { if (empty($therule['value'])) { if ($this->getConfig('allowEmpty')) { $output .= $this->_createElement($recurlabel); } continue; } $attributes = isset($therule['params']) ? $this->_createParams($therule['params']) : null; $content1 = $content2 = null; foreach ($therule['value'] as $rulelabel => $rulevalue) { switch ($rulelabel) { case 'FREQ': $content1 .= "FREQ={$rulevalue}"; break; case 'UNTIL': $content2 .= ";UNTIL="; $content2 .= iCalUtilityFunctions::_format_date_time($rulevalue); break; case 'COUNT': case 'INTERVAL': case 'WKST': $content2 .= ";{$rulelabel}={$rulevalue}"; break; case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $content2 .= ";{$rulelabel}="; if (is_array($rulevalue)) { foreach ($rulevalue as $vix => $valuePart) { $content2 .= $vix ? ',' : null; $content2 .= $valuePart; } } else { $content2 .= $rulevalue; } break; case 'BYDAY': $content2 .= ";{$rulelabel}="; $bydaycnt = 0; foreach ($rulevalue as $vix => $valuePart) { $content21 = $content22 = null; if (is_array($valuePart)) { $content2 .= $bydaycnt ? ',' : null; foreach ($valuePart as $vix2 => $valuePart2) { if ('DAY' != strtoupper($vix2)) { $content21 .= $valuePart2; } else { $content22 .= $valuePart2; } } $content2 .= $content21 . $content22; $bydaycnt++; } else { $content2 .= $bydaycnt ? ',' : null; if ('DAY' != strtoupper($vix)) { $content21 .= $valuePart; } else { $content22 .= $valuePart; $bydaycnt++; } $content2 .= $content21 . $content22; } } break; default: $content2 .= ";{$rulelabel}={$rulevalue}"; break; } } $output .= $this->_createElement($recurlabel, $attributes, $content1 . $content2); } return $output; }