Skip to content

Instantly share code, notes, and snippets.

@johnreilly
Created April 3, 2012 17:01
Show Gist options
  • Save johnreilly/2293671 to your computer and use it in GitHub Desktop.
Save johnreilly/2293671 to your computer and use it in GitHub Desktop.
# gem install sinatra sinatra-contrib icalendar
require 'sinatra'
require "sinatra/reloader" if development?
require 'icalendar'
require 'date'
get '/schedule.ics' do
cal = Icalendar::Calendar.new
# Set up timezone
cal.timezone do
timezone_id "America/Chicago"
daylight do
timezone_offset_from "-0600"
timezone_offset_to "-0500"
timezone_name "CDT"
dtstart "19700308T020000"
add_recurrence_rule "FREQ=YEARLY;BYMONTH=3;BYDAY=2SU"
end
standard do
timezone_offset_from "-0500"
timezone_offset_to "-0600"
timezone_name "CST"
dtstart "19701101T020000"
add_recurrence_rule "FREQ=YEARLY;BYMONTH=11;BYDAY=1SU"
end
end
# Build a bunch of test events
(10..14).each do |hour|
%w(First Second).each do |name|
cal.event do
summary "#{name} Session at #{hour} with a pretty long title that will likely wrap."
dtstart DateTime.parse("4th Apr 2012 #{hour}:00:00")
dtend DateTime.parse("4th Apr 2012 #{hour + 1}:00:00")
location "Minnetonka"
organizer "", :CN => "Luke Francl\\, Ben Edwards\\, Adrienne Peirce"
categories ["Design"]
description "Raising investment capital - whether seed, angel, or venture - can be a necessary ingredient of the startup lifecycle."
end
end
end
# Return the feed
cal.to_ical
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment