ics.php when uploaded to Outlook adds 1 hour to time.
Here is my code:
class ICS {
const DT_FORMAT = ‘Ymd\THis\Z’;
protected $properties = array();
private $available_properties = array(
‘description’,
‘dtend’,
‘dtstart’,
‘location’,
‘summary’,
‘url’,
‘UID’,
);
public function __construct($props) {
$this->set($props);
}
public function set($key, $val = false) {
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->set($k, $v);
}
} else {
if (in_array($key, $this->available_properties)) {
$this->properties[$key] = $this->sanitize_val($val, $key);
}
}
}
public function to_string() {
$rows = $this->build_props();
return implode(“\r\n”, $rows);
}
private function build_props() {
// Build ICS properties – add header
$ics_props = array(
‘BEGIN:VCALENDAR’,
‘VERSION:2.0’,
‘PRODID:-//hacksw/handcal//NONSGML v1.0//EN’,
‘CALSCALE:GREGORIAN’,
‘METHOD:PUBLISH’,
‘BEGIN:VEVENT’,
‘ORGANIZER;CN=”‘.get_option(‘blogname’).'”:MAILTO:’.get_option(‘admin_email’),
);
// Build ICS properties – add header
$props = array();
foreach($this->properties as $k => $v) {
$props[strtoupper($k . ($k === ‘url’ ? ‘;VALUE=URI’ : ”))] = $v;
}
// Set some default values
$props[‘DTSTAMP’] = $this->format_timestamp(‘now’);
//$props[‘UID’] = uniqid();
// Append properties
foreach ($props as $k => $v) {
$ics_props[] = “$k:$v”;
}
// Build ICS properties – add footer
$ics_props[] = ‘END:VEVENT’;
$ics_props[] = ‘END:VCALENDAR’;
return $ics_props;
}
private function sanitize_val($val, $key = false) {
switch($key) {
case ‘dtend’:
case ‘dtstamp’:
case ‘dtstart’:
$val = $this->format_timestamp($val);
break;
default:
$val = $this->escape_string($val);
}
return $val;
}
private function format_timestamp($timestamp) {
$dt = new DateTime($timestamp);
return $dt->format(self::DT_FORMAT);
}
private function escape_string($str) {
return preg_replace(‘/([\,;])/’,’\\\$1′, $str);
}
}
/*include ‘ICS.php’;
header(‘Content-type: text/calendar; charset=utf-8’);
header(‘Content-Disposition: attachment; filename=invite.ics’);
$ics = new ICS(array(
‘location’ => ‘factors involved in the dispute.’,
‘description’ => ‘on calls, mediation statements, private caucuses, joint sessions, and post-mediation conversations.? Few of us have given adequate consideration, however, to what factors should shape the specific process used in each particular mediation.? Most mediators have a standardized way of proceeding, without regard to the specific substantive and inter-personal factor’,
‘dtstart’ => ‘Thursday, February 23, 2017’,
‘dtend’ => ‘Thursday, February 23, 2017’,
‘summary’ => ‘Customizing the Mediation: The Mediator’s Role as Process Architect’,
‘url’ => ‘https://mane.work/mediationsociety.org’
));
echo $ics->to_string();*/