Merge pull request 'HOTFIX: Fix the ICS generator (again)' (#7) from khuxkm/tilderadio-site:master into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #7
This commit is contained in:
Ben Harris 2020-07-02 22:53:28 -04:00
commit 24fe2f80c0
1 changed files with 8 additions and 4 deletions

View File

@ -3,6 +3,10 @@ $from = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "last sunday" : "sunda
$to = gmdate("Y-m-d\T00:00:00\Z", strtotime(date("w") ? "sunday" : "next sunday"));
include 'schedule.php';
function ics_formatdate($date) {
return gmdate("Ymd\THis\Z", strtotime($date));
}
// ICS generation. Here be dragons.
// I created the file using a Python script and reverse-engineered it to figure this out.
@ -15,17 +19,17 @@ define("ICS_EOL","\r\n");
echo "BEGIN:VCALENDAR".ICS_EOL;
echo "VERSION:2.0".ICS_EOL;
echo "PRODID:tilderadio schedule".ICS_EOL;
echo "DTSTAMP:".formatdate("now").ICS_EOL;
echo "DTSTAMP:".ics_formatdate("now").ICS_EOL;
foreach ($schedule as $event) {
// The VEVENT structure's pretty easy to generate, especially since we're already in UTC.
echo "BEGIN:VEVENT".ICS_EOL;
// First, we need a creation date.
// Just go with now.
echo "DTSTAMP:".formatdate("now").ICS_EOL;
echo "DTSTAMP:".ics_formatdate("now").ICS_EOL;
// Next, the event start and end.
echo "DTEND:".formatdate($event["end"]).ICS_EOL;
echo "DTSTART:".formatdate($event["start"]).ICS_EOL;
echo "DTEND:".ics_formatdate($event["end"]).ICS_EOL;
echo "DTSTART:".ics_formatdate($event["start"]).ICS_EOL;
// Next, the recurrence rule.
// We assume the format is weekly. (No DJs have requested any other frequency yet.)
echo "RRULE:FREQ=WEEKLY".ICS_EOL;