→関連クラス図 05.RFC5545継承と包含
require 'when_exe' include When
標準時間と夏時間の切り替え時の振る舞いについては時間帯を参照
GoogleCalendarを利用する場合はGoogleCalendarも参照
event = When::V::Event.new({ 'rrule' => {'FREQ'=>'MONTHLY', 'INTERVAL'=>12, 'BYDAY'=>{''=>'3MO'}}, 'dtstart' => 'VALUE=DATE;TZID=Asia/Tokyo:20080915' }) p event.class #=> When::V::Event event.enum_for(When.when?('20070101'), :forward, 3).each do |date| p date #=> 2008-09-15T+09:00, 2009-09-21T+09:00, 2010-09-20T+09:00 end
When::TM::Clock.local_time = Clock("+0900") event = When::V::Event.new({ 'rrule' => {'FREQ'=>'MONTHLY', 'INTERVAL'=>12, 'BYDAY'=>{''=>'3MO'}}, 'dtstart' => 'VALUE=DATE:20080915' }) p event.class #=> When::V::Event event.enum_for(When.when?('20070101'), :forward, 3).each do |date| p date #=> 2008-09-15, 2009-09-21, 2010-09-20 end
-- sample1.ics -- (使用する場合は行頭の空白を削除) BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VTIMEZONE TZID:Asia/Tokyo BEGIN:STANDARD TZOFFSETFROM:+0900 TZOFFSETTO:+0900 TZNAME:JST DTSTART:19700101T000000 END:STANDARD END:VTIMEZONE BEGIN:VEVENT CREATED:20050809T050000Z LAST-MODIFIED:20050809T050000Z DTSTAMP:20050809T050000Z UID:event1-ID RRULE:FREQ=MONTHLY;INTERVAL=12;BYDAY=3MO DTSTART;VALUE=DATE;TZID=Asia/Tokyo:20080915 DTEND;VALUE=DATE;TZID=Asia/Tokyo:20080916 END:VEVENT END:VCALENDAR ----------------
event = Resource('sample1.ics::event1-ID') p event.iri #=> "sample1.ics::event1-ID" (実際は IRI に適合しないが便宜上ファイル名から生成) p event.class #=> When::V::Event event.enum_for(When.when?('20080101'), :forward, 3).each do |date| p date #=> 2008-09-15T+09:00, 2009-09-21T+09:00, 2010-09-20T+09:00 end
event = When::V::Event.new({ 'rrule' => {'FREQ'=>'YEARLY', 'BYDAY'=>{'SolarTerms'=>'term180'}}, 'dtstart' => 'VALUE=DATE;TZID=Asia/Tokyo:19480923' }) p event.class #=> When::V::Event event.enum_for(When.when?('20110101'), :forward, 3).each do |date| p date #=> 2011-09-23T+09:00, 2012-09-22T+09:00, 2013-09-23T+09:00 end
-- sample2.ics -- (snip) - sample1.ics と同じ UID:event2-ID RRULE:FREQ=YEARLY;BYDAY/SolarTerms=term180 DTSTART;VALUE=DATE;TZID=Asia/Tokyo:19480923 DTEND;VALUE=DATE;TZID=Asia/Tokyo:19480924 (snip) - sample1.ics と同じ ----------------
event = Resource('sample2.ics::event2-ID') p event.iri #=> "sample2.ics::event2-ID" (実際は IRI に適合しないが便宜上ファイル名から生成) p event.class #=> When::V::Event event.enum_for(When.when?('20110101'), :forward, 3).each do |date| p date #=> 2011-09-23T+09:00, 2012-09-22T+09:00, 2013-09-23T+09:00 end
TM::Clock.local_time = Clock("+0900") cal = Resource("../test/examples/JapanHolidays.ics") cal.each(when?('20090101')...when?('20100101')) do |date| p date #=> 下記の通り # 2009-01-01T+09:00 # 2009-01-12T+09:00 # 2009-02-11T+09:00 # 2009-03-20T+09:00 # 2009-04-29T+09:00 # 2009-05-03T+09:00 # 2009-05-04T+09:00 # 2009-05-05T+09:00 # 2009-05-06T+09:00 # 2009-07-20T+09:00 # 2009-09-21T+09:00 # 2009-09-22T+09:00 # 2009-09-23T+09:00 # 2009-10-12T+09:00 # 2009-11-03T+09:00 # 2009-11-23T+09:00 # 2009-12-23T+09:00 end
9月22日が現れるのは JapanHolidays.ics に拡張構文
# -- JapanHolidays.ics -- # (snip) # RRULE:FREQ=MONTHLY;INTERVAL=12;BYDAY=TU;BYDAY/SolarTerms=term180-1 # (snip) # ----------------
で「秋分の前日である火曜日」が定義してあるからです。 拡張構文を使っていますからJapanHolidays.ics は when.exe 以外とは情報交換できません。