test/test_rrule.rb in vpim-0.619 vs test/test_rrule.rb in vpim-0.658

- old
+ new

@@ -1,10 +1,11 @@ #!/usr/bin/env ruby ENV['TZ'] = 'EST5EDT' require 'vpim/rrule' +require 'vpim/icalendar' require 'test/unit' require 'pp' =begin @@ -12,10 +13,12 @@ alias :inspect :to_s end =end class TestRrule < Test::Unit::TestCase + Rrule = Vpim::Rrule + #=begin # Comment out these if you want printing! def puts(*args) end @@ -972,8 +975,56 @@ CATEGORIES:Holiday - Canada DTSTART;VALUE=DATE:17531226 RRULE:FREQ=MONTHLY;BYMONTH=12;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=26,27,28;BYSETPOS=1 END:VEVENT =end + + + def test_reccurrence_with_utc_dtstart + # Its wrong that the times yielded aren't in the timezone of DTSTART, but + # until vPim supports timezones, its the best it'll get. + txt = <<'__' +BEGIN:VCALENDAR +BEGIN:VEVENT +DTSTAMP:20080416T174954Z +ORGANIZER;CN=Anonymous:MAILTO:ano@nymo.us +CREATED:20080401T090904Z +LAST-MODIFIED:20080401T090904Z +SUMMARY:Very important recurring event +RRULE:FREQ=WEEKLY;UNTIL=20080415T093000Z;BYDAY=TU;BYHOUR=9 +DTSTART:20080401T093000Z +DTEND:20080401T110000Z +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR +__ + cal = Vpim::Icalendar.decode(txt).first + occurs = cal.events.to_a.first.occurrences.to_a + #p occurs + utc = occurs.map{|y| y.utc} + #p utc + expects = [ + Time.utc(2008, 4, 1, 9, 30), + Time.utc(2008, 4, 8, 9, 30), + Time.utc(2008, 4,15, 9, 30), + ] + assert_equal(expects, utc) + end + + def test_maker + assert_equal("FREQ=WEEKLY", + Rrule::Maker.new{|m|m.frequency = "WEEKLY"}.encode) + assert_equal("FREQ=WEEKLY;COUNT=2", + Rrule::Maker.new{|m|m.frequency = "WEEKLY"; m.count = 2}.encode) + assert_raises(ArgumentError) do + Rrule::Maker.new{|m|m.count = 2; m.until = Time.now} + end + assert_raises(ArgumentError) do + Rrule::Maker.new{|m|m.until = Time.now; m.count = 4} + end + assert_raises(ArgumentError) do + Rrule::Maker.new.encode + end + end end