Create a calendar of date and time events, attach arbitrary objects to them and ask which objects are current at any point in time.

Uses the flexible time parsing of Time.parse to be easy to use and the timezone and DST handling of tzinfo.

Originally conceived for making web sites look and behave differently depending on the time of day or year.

Example (print holiday greetings):


require 'seasonal'

holidays = Seasonal::Calendar.new

holidays.push(Seasonal::Event.new('Merry Christmas', 'America/New_York',
  :on => 'dec 25'))
holidays.push(Seasonal::Event.new("April Fool's Day", 'America/New_York',
  :on => 'apr 1'))

holidays.going_on { |e| puts e }

Example (make text red between 9:00 and 10:00 am):


require 'seasonal'

colors = Seasonal::Calendar.new

colors.push(Seasonal::Event.new('#ff0000', 'America/New_York',
  :start => '9:00am', :end => '10:00am'))

color = colors.going_on(:or_if_none => '#000000')
puts "<p style=\"background-color : #{color}\">test</p>"

Example (sale ends Jul 10):


require 'seasonal'

sales = Seasonal::Calendar.new

sales.push(Seasonal::Event.new('Everything on sale', 'America/New_York',
  :end => 'jul 10 2009'))

sales.going_on { |e| puts e }