0

In PHP I'm generating a .ical with a timestamp. Everything seems to be generating correctly but when trying to import the the file into OSX's Calendar, it's importing it by the hour and not by the exact time. In this example, the time it should be setting for is 1:30pm. Instead it's trying to import it as 1:00pm. Below is the code I'm using to generate the .ical and below that is the generated .ical.

Code used to generate:

public function createEvent($date)
{
    $eol = "\r\n";
    $ical = "BEGIN:VCALENDAR" . $eol .
    "VERSION:2.0" . $eol .
    "PRODID:-//Reminders/Relatient//NONSGML v1.0//EN" . $eol .
    "BEGIN:VEVENT" . $eol .
    "UID:" . md5(uniqid(mt_rand(), true)) . "@reltient.net" . $eol .
    "DTSTAMP:" . gmdate('Ymd', $date).'T'. gmdate('His', $date) . "Z" . $eol .
    "DTSTART:" . date('Ymd\Tgis\Z', $date) . $eol .
    "DTEND:" . date('Ymd\Tgis\Z', $date) . $eol .
    "SUMMARY:Appointment Reminder for ".date("m-d-Y", $date) . $eol .
    "END:VEVENT" . $eol .
    "END:VCALENDAR";

    //set correct content-type-header
    header('Content-type: text/calendar; charset=utf-8');
    header('Content-Disposition: inline; filename=calendar.ics');
    echo $ical;
    exit;
}

The Generated File

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Reminders/Relatient//NONSGML v1.0//EN
BEGIN:VEVENT
UID:cff16d0441e2d7d9d00a39977a8ea416@reltient.net
DTSTAMP:20150506T013000Z
DTSTART:20150506T13000Z
DTEND:20150506T13000Z
SUMMARY:Appointment Reminder for 05-06-2015
END:VEVENT
END:VCALENDAR

Why would the calendar not be importing the time down to the half hour, and instead be importing it as 1:00pm to 1:00pm?

EDIT: This is the post I was following when trying to create the ical file: How can I use PHP to dynamically publish an ical file to be read by Google Calendar?

UPDATE: New Generated File Below (When importing this into calendar, it's being imported as 05-05-2015 8:30pm - 8:30pm)

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Reminders/Relatient//NONSGML v1.0//EN
BEGIN:VEVENT
UID:7813cb2429c9075704866becde76c4b7@reltient.net
DTSTAMP:20150506T013000Z
DTSTART:20150506T013000Z
DTEND:20150506T013000Z
SUMMARY:Appointment Reminder for 05-05-2015
END:VEVENT
END:VCALENDAR
Community
  • 1
  • 1
jamadri
  • 926
  • 3
  • 17
  • 32
  • 1
    something's goofy with those times. `T013000Z` is fine, but `T13000Z` is missing a digit. should be 4 `0`'s for 1pm (`13:00:00`, v.s. `13:00:0` you've got now). – Marc B May 11 '15 at 17:10
  • After taking your advice and adding a 0 in front of the T1300Z to make it T01300Z, it's now importing the time as 8:30pm to 8:30pm. So it's adding the half hour, but why has it jumped from 1:30pm to 8:30pm? – jamadri May 11 '15 at 17:25
  • You're probably in a UTC-7 timezone, e.g. 7 hours away from (Z)ulu time. – Marc B May 11 '15 at 18:08
  • How would I go about setting the timezone in php to be used for central time then? – jamadri May 11 '15 at 19:26
  • http://php.net/date_default_timezone_set – Marc B May 11 '15 at 19:29
  • Above is the newly generated file. The odd thing is the ics file looks correct but it's importing incorrectly. It's importing under 5-5-2015, and the time that's showing is 8:30 now and this is after changing the time zone as follows: date_default_timezone_set('America/Chicago'); What could be causing this? – jamadri May 11 '15 at 19:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77553/discussion-between-jamadri-and-marc-b). – jamadri May 11 '15 at 19:38

1 Answers1

0

So it was nothing wrong with the PHP, it was writing the .ics file. There is actually an entire section I've not seen posted about in any question yet but there is a BEGIN:VTIMEZONE section. Below is the updated .ics file with the VTIMEZONE section. It allows you to set the timezone of the file.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Reminders/Relatient//NONSGML v1.0//EN
X-WR-CALNAME: Appointment Reminder
CALSCALE:GREGORIAN

BEGIN:VTIMEZONE
TZID:America/Chicago
TZURL:http://tzurl.org/zoneinfo-outlook/America/Chicago
X-LIC-LOCATION:America/Chicago
BEGIN:DAYLIGHT
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
TZNAME:CDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
TZNAME:CST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE

BEGIN:VEVENT
UID:07a982306563eda4045da725b9318d13@relatient.net
DTSTAMP:20150512T143025Z
DTSTART;TZID='America/Chicago':20150506T133000
DTEND;TZID='America/Chicago':20150506T133000
SUMMARY:Appointment Reminder for 05-06-2015
                                 END:VEVENT
END:VCALENDAR
jamadri
  • 926
  • 3
  • 17
  • 32