LoginSignup
3
2

More than 5 years have passed since last update.

iCalendar形式のファイルからRRULEを考慮してスケジュールデータを取得する方法

Last updated at Posted at 2014-11-19

iCalendar形式のファイルからRRULEを考慮してスケジュールデータを取得する方法

2011年のPHPMatsuri ぶりにiCalendar形式とか触った

icalendar/recurrence を使うのがポイント

require 'date'
require 'tzinfo'
require 'icalendar'
require 'icalendar/recurrence'

url = 'https://mozorg.cdn.mozilla.net/media/caldata/JapanHolidays.ics'
result = Icalendar.parse(client.get_content(url), true)
result.events.each do |event|
  if event.rrule == []
    puts Date.parse(event.dtstart.to_s)       
  else
    event.occurrences_between(start_date, end_date).each do | e |
      puts Date.parse(e.start_time.to_s)
    end
  end
end
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2