I want to create ics start and end time (UTC) with format like:
DTSTART:20141107T110000Z
DTEND:20141107T120000Z
I have following Object as input:
"event": {
"timezone": "GMT+2",
"start_time": "2014-11-07 13:00:00", // client local time
"duration": 30
},
function _calc_end_date($start, $duration) {
$start_date = new DateTime($start, new DateTimeZone('UTC'));
$end_date = $start_date->add(new DateInterval('PT'.$duration.'M'));
$end_date_str = $end_date->format('Y-m-d H:i:s');
return $end_date_str;
}
private function dateToCal($timestamp) {
return GMDATE("Ymd\THis\Z", $timestamp);
}
$timezone = $event['timezone']; // ????
$start = strtotime($event['start_time'] . " UTC");
$end_date = $this->_calc_end_date($event['start_time'], $event['duration']);
$end = strtotime($end_date . " UTC");
So I write:
"DTSTART:" . $this->dateToCal( $start ) . $eol .
"DTEND:" . $this->dateToCal( $end ) . $eol .
This code works but I get result with 2 hours difference. As you can notice I don't entered TimeZone because I don't know how.
$timezone = $event['timezone']; //
Somehow I need parse "GMT+2" and calculate
$start = strtotime($event['start_time'] . " UTC");
with TZ.
Please help,