friflaj_ri_cal 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +26 -0
  4. data/History.txt +408 -0
  5. data/README.rdoc +407 -0
  6. data/Rakefile +9 -0
  7. data/component_attributes/alarm.yml +10 -0
  8. data/component_attributes/calendar.yml +4 -0
  9. data/component_attributes/component_property_defs.yml +180 -0
  10. data/component_attributes/event.yml +45 -0
  11. data/component_attributes/freebusy.yml +16 -0
  12. data/component_attributes/journal.yml +35 -0
  13. data/component_attributes/timezone.yml +3 -0
  14. data/component_attributes/timezone_period.yml +11 -0
  15. data/component_attributes/todo.yml +46 -0
  16. data/docs/draft-ietf-calsify-2446bis-08.txt +7280 -0
  17. data/docs/draft-ietf-calsify-rfc2445bis-09.txt +10416 -0
  18. data/docs/incrementers.txt +7 -0
  19. data/docs/rfc2445.pdf +0 -0
  20. data/docs/test.ics +38 -0
  21. data/lib/ri_cal.rb +184 -0
  22. data/lib/ri_cal/component.rb +254 -0
  23. data/lib/ri_cal/component/alarm.rb +17 -0
  24. data/lib/ri_cal/component/calendar.rb +255 -0
  25. data/lib/ri_cal/component/event.rb +56 -0
  26. data/lib/ri_cal/component/freebusy.rb +14 -0
  27. data/lib/ri_cal/component/journal.rb +25 -0
  28. data/lib/ri_cal/component/non_standard.rb +31 -0
  29. data/lib/ri_cal/component/t_z_info_timezone.rb +155 -0
  30. data/lib/ri_cal/component/timezone.rb +195 -0
  31. data/lib/ri_cal/component/timezone/daylight_period.rb +23 -0
  32. data/lib/ri_cal/component/timezone/standard_period.rb +21 -0
  33. data/lib/ri_cal/component/timezone/timezone_period.rb +74 -0
  34. data/lib/ri_cal/component/todo.rb +39 -0
  35. data/lib/ri_cal/core_extensions.rb +7 -0
  36. data/lib/ri_cal/core_extensions/array.rb +16 -0
  37. data/lib/ri_cal/core_extensions/date.rb +63 -0
  38. data/lib/ri_cal/core_extensions/date_time.rb +58 -0
  39. data/lib/ri_cal/core_extensions/object.rb +21 -0
  40. data/lib/ri_cal/core_extensions/string.rb +58 -0
  41. data/lib/ri_cal/core_extensions/time.rb +50 -0
  42. data/lib/ri_cal/core_extensions/time/calculations.rb +150 -0
  43. data/lib/ri_cal/core_extensions/time/tzid_access.rb +47 -0
  44. data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +52 -0
  45. data/lib/ri_cal/fast_date_time.rb +247 -0
  46. data/lib/ri_cal/floating_timezone.rb +29 -0
  47. data/lib/ri_cal/invalid_property_value.rb +5 -0
  48. data/lib/ri_cal/invalid_timezone_identifier.rb +17 -0
  49. data/lib/ri_cal/occurrence_enumerator.rb +262 -0
  50. data/lib/ri_cal/occurrence_period.rb +17 -0
  51. data/lib/ri_cal/parser.rb +142 -0
  52. data/lib/ri_cal/properties.rb +12 -0
  53. data/lib/ri_cal/properties/alarm.rb +387 -0
  54. data/lib/ri_cal/properties/calendar.rb +161 -0
  55. data/lib/ri_cal/properties/event.rb +1520 -0
  56. data/lib/ri_cal/properties/freebusy.rb +590 -0
  57. data/lib/ri_cal/properties/journal.rb +1234 -0
  58. data/lib/ri_cal/properties/timezone.rb +147 -0
  59. data/lib/ri_cal/properties/timezone_period.rb +413 -0
  60. data/lib/ri_cal/properties/todo.rb +1556 -0
  61. data/lib/ri_cal/property_value.rb +157 -0
  62. data/lib/ri_cal/property_value/array.rb +25 -0
  63. data/lib/ri_cal/property_value/cal_address.rb +9 -0
  64. data/lib/ri_cal/property_value/date.rb +182 -0
  65. data/lib/ri_cal/property_value/date_time.rb +357 -0
  66. data/lib/ri_cal/property_value/date_time/additive_methods.rb +42 -0
  67. data/lib/ri_cal/property_value/date_time/time_machine.rb +157 -0
  68. data/lib/ri_cal/property_value/date_time/timezone_support.rb +98 -0
  69. data/lib/ri_cal/property_value/duration.rb +108 -0
  70. data/lib/ri_cal/property_value/geo.rb +9 -0
  71. data/lib/ri_cal/property_value/integer.rb +10 -0
  72. data/lib/ri_cal/property_value/occurrence_list.rb +142 -0
  73. data/lib/ri_cal/property_value/period.rb +84 -0
  74. data/lib/ri_cal/property_value/recurrence_rule.rb +152 -0
  75. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +98 -0
  76. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +77 -0
  77. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +146 -0
  78. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +51 -0
  79. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +29 -0
  80. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb +133 -0
  81. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb +84 -0
  82. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb +29 -0
  83. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb +30 -0
  84. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb +50 -0
  85. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb +29 -0
  86. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb +36 -0
  87. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb +30 -0
  88. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb +67 -0
  89. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb +29 -0
  90. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb +26 -0
  91. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb +78 -0
  92. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb +21 -0
  93. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb +104 -0
  94. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb +21 -0
  95. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb +31 -0
  96. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb +41 -0
  97. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb +26 -0
  98. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb +35 -0
  99. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb +55 -0
  100. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +129 -0
  101. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +62 -0
  102. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +31 -0
  103. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +51 -0
  104. data/lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb +40 -0
  105. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +123 -0
  106. data/lib/ri_cal/property_value/text.rb +42 -0
  107. data/lib/ri_cal/property_value/uri.rb +9 -0
  108. data/lib/ri_cal/property_value/utc_offset.rb +31 -0
  109. data/lib/ri_cal/property_value/zulu_date_time.rb +32 -0
  110. data/lib/ri_cal/required_timezones.rb +53 -0
  111. data/lib/ri_cal/version.rb +3 -0
  112. data/parked_specs/ri_cal/claudio_a_bug_spec.rb +98 -0
  113. data/performance/empty_propval/subject.rb +43 -0
  114. data/performance/paris_eastern/subject.rb +90 -0
  115. data/performance/penultimate_weekday/subject.rb +15 -0
  116. data/performance/psm_big_enum/ical.ics +3171 -0
  117. data/performance/psm_big_enum/subject.rb +16 -0
  118. data/performance/utah_cycling/subject.rb +55 -0
  119. data/performance_data/benchmarks.out +48 -0
  120. data/performance_data/empty_propval.calltree +45650 -0
  121. data/performance_data/paris_eastern.calltree +103058 -0
  122. data/performance_data/penultimate_weekday.calltree +48686 -0
  123. data/performance_data/psm_big_enum.calltree +225814 -0
  124. data/performance_data/utah_cycling.calltree +117950 -0
  125. data/ri_cal.gemspec +35 -0
  126. data/script/benchmark_subject +23 -0
  127. data/script/console +10 -0
  128. data/script/destroy +14 -0
  129. data/script/generate +14 -0
  130. data/script/profile_subject +29 -0
  131. data/script/txt2html +71 -0
  132. data/spec/ri_cal/bugreports_spec.rb +281 -0
  133. data/spec/ri_cal/component/alarm_spec.rb +10 -0
  134. data/spec/ri_cal/component/calendar_spec.rb +87 -0
  135. data/spec/ri_cal/component/event_spec.rb +734 -0
  136. data/spec/ri_cal/component/freebusy_spec.rb +10 -0
  137. data/spec/ri_cal/component/journal_spec.rb +35 -0
  138. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +63 -0
  139. data/spec/ri_cal/component/timezone_spec.rb +233 -0
  140. data/spec/ri_cal/component/todo_spec.rb +110 -0
  141. data/spec/ri_cal/component_spec.rb +225 -0
  142. data/spec/ri_cal/core_extensions/string/conversions_spec.rb +76 -0
  143. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +186 -0
  144. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +43 -0
  145. data/spec/ri_cal/fast_date_time_spec.rb +75 -0
  146. data/spec/ri_cal/inf_loop_spec.rb +75 -0
  147. data/spec/ri_cal/occurrence_enumerator_spec.rb +610 -0
  148. data/spec/ri_cal/parser_spec.rb +335 -0
  149. data/spec/ri_cal/property_value/date_spec.rb +51 -0
  150. data/spec/ri_cal/property_value/date_time_spec.rb +380 -0
  151. data/spec/ri_cal/property_value/duration_spec.rb +123 -0
  152. data/spec/ri_cal/property_value/occurrence_list_spec.rb +70 -0
  153. data/spec/ri_cal/property_value/period_spec.rb +61 -0
  154. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +19 -0
  155. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1810 -0
  156. data/spec/ri_cal/property_value/text_spec.rb +23 -0
  157. data/spec/ri_cal/property_value/utc_offset_spec.rb +46 -0
  158. data/spec/ri_cal/property_value_spec.rb +123 -0
  159. data/spec/ri_cal/required_timezones_spec.rb +63 -0
  160. data/spec/ri_cal_spec.rb +50 -0
  161. data/spec/spec_helper.rb +35 -0
  162. data/tasks/ri_cal.rake +400 -0
  163. data/tasks/spec.rake +26 -0
  164. metadata +260 -0
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe RiCal::Component::Freebusy do
4
+
5
+ describe ".entity_name" do
6
+ it "should be VFREEBUSY" do
7
+ RiCal::Component::Freebusy.entity_name.should == "VFREEBUSY"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe RiCal::Component::Journal do
4
+
5
+ describe ".entity_name" do
6
+ it "should be VJOURNAL" do
7
+ RiCal::Component::Journal.entity_name.should == "VJOURNAL"
8
+ end
9
+ end
10
+
11
+ context ".start_time" do
12
+ it "should be the same as dtstart for a date time" do
13
+ event = RiCal.Journal {|e| e.dtstart = "20090525T151900"}
14
+ event.start_time.should == DateTime.civil(2009,05,25,15,19,0,0)
15
+ end
16
+
17
+ it "should be the start of the day of dtstart for a date" do
18
+ event = RiCal.Journal {|e| e.dtstart = "20090525"}
19
+ event.start_time.should == DateTime.civil(2009,05,25,0,0,0,0)
20
+ end
21
+ end
22
+
23
+ context ".finish_time" do
24
+ it "should be the same as dtstart for a date time" do
25
+ event = RiCal.Journal {|e| e.dtstart = "20090525T151900"}
26
+ event.finish_time.should == DateTime.civil(2009,05,25,15,19,0,0)
27
+ end
28
+
29
+ it "should be the start of the day of dtstart for a date" do
30
+ event = RiCal.Journal {|e| e.dtstart = "20090525"}
31
+ event.finish_time.should == DateTime.civil(2009,05,25,0,0,0,0)
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe RiCal::Component::TZInfoTimezone do
4
+
5
+ it "should produce an rfc representation" do
6
+ tz = RiCal::Component::TZInfoTimezone.new(TZInfo::Timezone.get("America/New_York"))
7
+ local_first = DateTime.parse("Apr 10, 2007")
8
+ local_last = DateTime.parse("Apr 6, 2008")
9
+ utc_first = tz.local_to_utc(local_first)
10
+ utc_last = tz.local_to_utc(local_last)
11
+ rez = tz.to_rfc2445_string(utc_first, utc_last)
12
+ rez.should == <<-ENDDATA
13
+ BEGIN:VTIMEZONE
14
+ TZID;X-RICAL-TZSOURCE=TZINFO:America/New_York
15
+ BEGIN:DAYLIGHT
16
+ DTSTART:20070311T020000
17
+ RDATE:20070311T020000
18
+ RDATE:20080309T020000
19
+ TZOFFSETFROM:-0500
20
+ TZOFFSETTO:-0400
21
+ TZNAME:EDT
22
+ END:DAYLIGHT
23
+ BEGIN:STANDARD
24
+ DTSTART:20071104T020000
25
+ RDATE:20071104T020000
26
+ TZOFFSETFROM:-0400
27
+ TZOFFSETTO:-0500
28
+ TZNAME:EST
29
+ END:STANDARD
30
+ END:VTIMEZONE
31
+ ENDDATA
32
+ end
33
+
34
+ TZInfo::Timezone.all_identifiers.each do |tz|
35
+ context "TZInfo timezone #{tz}" do
36
+ before(:each) do
37
+ @calendar = RiCal.Calendar do |cal|
38
+ cal.event do |event|
39
+ event.description = "test"
40
+ event.dtstart = "TZID=#{tz}:20090530T123000"
41
+ event.dtend = "TZID=#{tz}:20090530T123001"
42
+ end
43
+ end
44
+ end
45
+ it "should be allowed as a tzid" do
46
+ lambda {@calendar.export}.should_not raise_error
47
+ end
48
+ unless tz == "UTC"
49
+ it "should produce at least one period in the VTIMEZONE" do
50
+ @calendar.export.should match(/BEGIN:(STANDARD|DAYLIGHT)/)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ it "should not raise an error with Ambigous times" do
57
+ tz = RiCal::Component::TZInfoTimezone.new(TZInfo::Timezone.get("America/New_York"))
58
+ local_start = DateTime.parse("2011-11-06T01:30:00+00:00")
59
+ # This time appears twice. Because at 2:00 am the clock falls back to 1:00 am again
60
+ local_end = DateTime.parse("Nov 30, 2012")
61
+ lambda { tz.export_local_to(StringIO.new, local_start, local_end) }.should_not raise_error(TZInfo::AmbiguousTime)
62
+ end
63
+ end
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe RiCal::Component::Timezone do
4
+
5
+ context ".entity_name" do
6
+ it "should be VTIMEZONE" do
7
+ RiCal::Component::Timezone.entity_name.should == "VTIMEZONE"
8
+ end
9
+ end
10
+
11
+ context "for a Timezone with no DST periods" do
12
+ before(:each) do
13
+ @it = RiCal.parse_string rectify_ical(<<-'ENDCAL')
14
+ BEGIN:VTIMEZONE
15
+ TZID:Australia/Brisbane
16
+ X-LIC-LOCATION:Australia/Brisbane
17
+ BEGIN:STANDARD
18
+ TZOFFSETFROM:+1000
19
+ TZOFFSETTO:+1000
20
+ TZNAME:EST
21
+ DTSTART:19700101T000000
22
+ END:STANDARD
23
+ END:VTIMEZONE
24
+ ENDCAL
25
+ @it = @it.first
26
+ end
27
+
28
+ context ".periods_for_local" do
29
+ it "should return a single period" do
30
+ @it.periods_for_local(DateTime.parse("20090530T100000")).length.should == 1
31
+ end
32
+ end
33
+ end
34
+
35
+ context "from an iCal.app calendar for America/New_York starting March 11 2007" do
36
+ before(:each) do
37
+ @it = RiCal.parse_string rectify_ical(<<-'ENDCAL')
38
+ BEGIN:VTIMEZONE
39
+ TZID:US/Eastern
40
+ BEGIN:DAYLIGHT
41
+ TZOFFSETFROM:-0500
42
+ TZOFFSETTO:-0400
43
+ DTSTART:20070311T020000
44
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
45
+ TZNAME:EDT
46
+ END:DAYLIGHT
47
+ BEGIN:STANDARD
48
+ TZOFFSETFROM:-0400
49
+ TZOFFSETTO:-0500
50
+ DTSTART:20071104T020000
51
+ RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
52
+ TZNAME:EST
53
+ END:STANDARD
54
+ END:VTIMEZONE
55
+ ENDCAL
56
+ @it = @it.first
57
+ end
58
+
59
+ it "should be a Timezone" do
60
+ @it.should be_kind_of(RiCal::Component::Timezone)
61
+ end
62
+
63
+ context ".local_to_utc" do
64
+ it "should produce 2/27/2009 18:00 UTC for 2/27/2009 13:00" do
65
+ expected = RiCal::PropertyValue::DateTime.new(nil, :value => "20090227T1800Z" )
66
+ @it.local_to_utc(DateTime.parse("Feb 27, 2009 13:00")).should == expected
67
+ end
68
+ end
69
+
70
+ context ".utc_to_local" do
71
+ it "should produce 2/27/2009 13:00 EST for 2/27/2009 18:00 UTC" do
72
+ expected = RiCal::PropertyValue::DateTime.new(nil, :params => {'TZID' => 'US/Eastern'}, :value => "20090227T1300" )
73
+ @it.utc_to_local(DateTime.parse("Feb 27, 2009 18:00")).should == expected
74
+ end
75
+ end
76
+
77
+ context ".period_for_local" do
78
+ it "should raise TZInfo::PeriodNotFound for an invalid local time, e.g. Mar 8, 2009 2:30" do
79
+ lambda {@it.period_for_local(DateTime.parse("Mar 8, 2009 2:30"))}.should raise_error(TZInfo::PeriodNotFound)
80
+ end
81
+
82
+ context "for an ambiguous local time , e.g. Nov 1, 2009 2:00" do
83
+ context "lacking a dst parameter or block" do
84
+ it "should raise TZInfo::AmbiguousTime" do
85
+ lambda {@it.period_for_local(DateTime.parse("Nov 1, 2009 2:00"))}.should raise_error(TZInfo::AmbiguousTime)
86
+ end
87
+ end
88
+
89
+ context "with a dst parameter" do
90
+ it "should return a dst period if the dst parameter is true" do
91
+ @it.period_for_local(DateTime.parse("Nov 1, 2009 2:00"), true).should be_dst
92
+ end
93
+
94
+ it "should return a std period if the dst parameter is false" do
95
+ @it.period_for_local(DateTime.parse("Nov 1, 2009 2:00"), false).should_not be_dst
96
+ end
97
+ end
98
+
99
+ context "with a block" do
100
+ it "should return a period if the block returns a TimezonePeriod" do
101
+ mock_period = ::RiCal::Component::Timezone::TimezonePeriod.new(nil)
102
+ @it.period_for_local(DateTime.parse("Nov 1, 2009 2:00")) { |results| mock_period}.should == mock_period
103
+ end
104
+
105
+ it "should return a period if the block returns a single element array" do
106
+ mock_period = :foo
107
+ @it.period_for_local(DateTime.parse("Nov 1, 2009 2:00")) { |results| [ mock_period]}.should == mock_period
108
+ end
109
+
110
+ it "should raise TZInfo::PeriodNotFound if the block returns a multi-element array" do
111
+ lambda {
112
+ @it.period_for_local(DateTime.parse("Mar 8, 2009 2:30")) {|results| [1,2]}}.should raise_error(TZInfo::PeriodNotFound)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ context ".periods_for_local" do
119
+ context "for the date on which DST begins springing ahead e.g. Mar 8, 2009" do
120
+ it "should return a 1 element array for 1 second before the transition time" do
121
+ @it.periods_for_local(DateTime.parse("Mar 8, 2009 1:59:59")).length.should == 1
122
+ end
123
+
124
+ it "should return an empty array for the transition time" do
125
+ @it.periods_for_local(DateTime.parse("Mar 8, 2009 2:00:00")).should == []
126
+ end
127
+
128
+ it "should return an empty array for 1 second after the transition time" do
129
+ @it.periods_for_local(DateTime.parse("Mar 8, 2009 2:00:01")).should == []
130
+ end
131
+
132
+ it "should return an empty array for 1 second before the spring ahead time" do
133
+ @it.periods_for_local(DateTime.parse("Mar 8, 2009 2:59:59")).should == []
134
+ end
135
+
136
+ it "should return a 1 element array for the spring ahead time" do
137
+ @it.periods_for_local(DateTime.parse("Mar 8, 2009 3:00:00")).length.should == 1
138
+ end
139
+ end
140
+
141
+ context "for the date on which DST ends falling back e.g. Nov 11, 2009" do
142
+ it "should return a 1 element array for 1 second before the transition time" do
143
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 1:59:59")).length.should == 1
144
+ end
145
+
146
+ it "should return a 2 element array for the transition time" do
147
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 2:00:00")).length.should == 2
148
+ end
149
+
150
+ it "should return a 2 element array for 1 second after the transition time" do
151
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 2:00:01")).length.should == 2
152
+ end
153
+
154
+ it "should return a 2 element array for 59 minutes and 59 seconds after the transition time" do
155
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 2:59:59")).length.should == 2
156
+ end
157
+
158
+ it "should return a 2 element array for 1 hour after the transition time" do
159
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 3:00:00")).length.should == 2
160
+ end
161
+
162
+ it "should return a 2 element array for 1 hour and 1 second after the transition time" do
163
+ @it.periods_for_local(DateTime.parse("Nov 1, 2009 3:00:01")).length.should == 2
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ context "Bug report from paulsm" do
170
+ before(:each) do
171
+ cals = RiCal.parse_string rectify_ical(<<-'ENDCAL')
172
+ BEGIN:VCALENDAR
173
+ X-WR-TIMEZONE:America/New_York
174
+ PRODID:-//Apple Inc.//iCal 3.0//EN
175
+ CALSCALE:GREGORIAN
176
+ X-WR-CALNAME:test
177
+ VERSION:2.0
178
+ X-WR-RELCALID:1884C7F8-BC8E-457F-94AC-297871967D5E
179
+ X-APPLE-CALENDAR-COLOR:#2CA10B
180
+ BEGIN:VTIMEZONE
181
+ TZID:US/Eastern
182
+ BEGIN:DAYLIGHT
183
+ TZOFFSETFROM:-0500
184
+ TZOFFSETTO:-0400
185
+ DTSTART:20070311T020000
186
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
187
+ TZNAME:EDT
188
+ END:DAYLIGHT
189
+ BEGIN:STANDARD
190
+ TZOFFSETFROM:-0400
191
+ TZOFFSETTO:-0500
192
+ DTSTART:20071104T020000
193
+ RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
194
+ TZNAME:EST
195
+ END:STANDARD
196
+ END:VTIMEZONE
197
+ BEGIN:VEVENT
198
+ SEQUENCE:5
199
+ TRANSP:OPAQUE
200
+ UID:00481E53-9258-4EA7-9F8D-947D3041A3F2
201
+ DTSTART;TZID=US/Eastern:20090224T090000
202
+ DTSTAMP:20090225T000908Z
203
+ SUMMARY:Test Event
204
+ CREATED:20090225T000839Z
205
+ DTEND;TZID=US/Eastern:20090224T100000
206
+ RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=20090228T045959Z
207
+ END:VEVENT
208
+ END:VCALENDAR
209
+ ENDCAL
210
+ @event = cals.first.events.first
211
+ end
212
+
213
+ context "the events dtstart" do
214
+ it "should be the right DateTime" do
215
+ @event.dtstart.should == DateTime.civil(2009, 2, 24, 9, 0, 0, Rational(-5, 24))
216
+ end
217
+
218
+ it "should have the right tzid" do
219
+ @event.dtstart.tzid.should == "US/Eastern"
220
+ end
221
+ end
222
+
223
+ context "the events dtend" do
224
+ it "should be the right DateTime" do
225
+ @event.dtend.should == DateTime.civil(2009, 2, 24, 10, 0, 0, Rational(-5, 24))
226
+ end
227
+
228
+ it "should have the right tzid" do
229
+ @event.dtend.tzid.should == "US/Eastern"
230
+ end
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe RiCal::Component::Todo do
4
+
5
+ context ".start_time" do
6
+ it "should be the same as dtstart for a date time" do
7
+ todo = RiCal.Todo {|e| e.dtstart = "20090525T151900"}
8
+ todo.start_time.should == DateTime.civil(2009,05,25,15,19,0,0)
9
+ end
10
+
11
+ it "should be the start of the day of dtstart for a date" do
12
+ todo = RiCal.Todo {|e| e.dtstart = "20090525"}
13
+ todo.start_time.should == DateTime.civil(2009,05,25,0,0,0,0)
14
+ end
15
+
16
+ it "should be nil if the dtstart property is not set" do
17
+ RiCal.Todo.start_time.should be_nil
18
+ end
19
+ end
20
+
21
+ context ".finish_time" do
22
+ before(:each) do
23
+ @todo = RiCal.Todo {|t| t.dtstart = "20090525T151900"}
24
+ end
25
+
26
+ context "with a given due" do
27
+ it "should be the same as due for a date time" do
28
+ @todo.due = "20090525T161900"
29
+ @todo.finish_time.should == DateTime.civil(2009,05,25,16,19,0,0)
30
+ end
31
+ end
32
+
33
+ context "with no due" do
34
+ context "and a duration" do
35
+ before(:each) do
36
+ @todo.duration = "+PT1H"
37
+ end
38
+
39
+ it "should be the dtstart plus the duration" do
40
+ @todo.finish_time.should == DateTime.civil(2009,5,25,16,19,0,0)
41
+ end
42
+
43
+ it "should be nil if the dtstart property is not set" do
44
+ @todo.dtstart_property = nil
45
+ @todo.finish_time.should be_nil
46
+ end
47
+ end
48
+
49
+ context "and no duration" do
50
+ it "should be nil" do
51
+ @todo.finish_time.should be_nil
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "with both due and duration specified" do
58
+ before(:each) do
59
+ @it = RiCal::Component::Todo.parse_string("BEGIN:VTODO\nDUE:19970903T190000Z\nDURATION:H1\nEND:VTODO").first
60
+ end
61
+
62
+ it "should be invalid" do
63
+ @it.should_not be_valid
64
+ end
65
+ end
66
+
67
+ describe "with a duration property" do
68
+ before(:each) do
69
+ @it = RiCal::Component::Todo.parse_string("BEGIN:VTODO\nDURATION:H1\nEND:VTODO").first
70
+ end
71
+
72
+ it "should have a duration property" do
73
+ @it.duration_property.should be
74
+ end
75
+
76
+ it "should have a duration of 1 Hour" do
77
+ @it.duration_property.value.should == "H1"
78
+ end
79
+
80
+ it "should reset the duration property if the due property is set" do
81
+ @it.due_property = "19970101T012345".to_ri_cal_date_time_value
82
+ @it.duration_property.should be_nil
83
+ end
84
+
85
+ it "should reset the duration property if the dtend ruby value is set" do
86
+ @it.due = "19970101"
87
+ @it.duration_property.should == nil
88
+ end
89
+ end
90
+
91
+ describe "with a due property" do
92
+ before(:each) do
93
+ @it = RiCal::Component::Todo.parse_string("BEGIN:VTODO\nDUE:19970903T190000Z\nEND:VTODO").first
94
+ end
95
+
96
+ it "should have a due property" do
97
+ @it.due_property.should be
98
+ end
99
+
100
+ it "should reset the due property if the duration property is set" do
101
+ @it.duration_property = "PT1H".to_ri_cal_duration_value
102
+ @it.due_property.should be_nil
103
+ end
104
+
105
+ it "should reset the duration property if the dtend ruby value is set" do
106
+ @it.duration = "PT1H"
107
+ @it.due_property.should == nil
108
+ end
109
+ end
110
+ end