tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
@@ -0,0 +1,1222 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class MainTest < Minitest::Test
6
+ def test_values
7
+ vcal = Tilia::VObject::Component::VCalendar.new
8
+ ev = vcal.create_component('VEVENT')
9
+ ev['UID'] = 'bla'
10
+ ev['RRULE'] = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200'
11
+ dt_start = vcal.create_property('DTSTART')
12
+ dt_start.date_time = Time.zone.parse('2011-10-07')
13
+
14
+ ev.add(dt_start)
15
+
16
+ vcal.add(ev)
17
+
18
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
19
+
20
+ assert(it.infinite?)
21
+ end
22
+
23
+ def test_invalid_freq
24
+ vcal = Tilia::VObject::Component::VCalendar.new
25
+ ev = vcal.create_component('VEVENT')
26
+ ev['RRULE'] = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z'
27
+ ev['UID'] = 'foo'
28
+ dt_start = vcal.create_property('DTSTART')
29
+ dt_start.date_time = ActiveSupport::TimeZone.new('UTC').parse('2011-10-07')
30
+
31
+ ev.add(dt_start)
32
+ vcal.add(ev)
33
+
34
+ assert_raises(ArgumentError) { Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s) }
35
+ end
36
+
37
+ def test_v_calendar_no_uid
38
+ vcal = Tilia::VObject::Component::VCalendar.new
39
+ assert_raises(ArgumentError) { Tilia::VObject::Recur::EventIterator.new(vcal) }
40
+ end
41
+
42
+ def test_v_calendar_invalid_uid
43
+ vcal = Tilia::VObject::Component::VCalendar.new
44
+ assert_raises(ArgumentError) { Tilia::VObject::Recur::EventIterator.new(vcal, 'foo') }
45
+ end
46
+
47
+ def test_hourly
48
+ vcal = Tilia::VObject::Component::VCalendar.new
49
+ ev = vcal.create_component('VEVENT')
50
+
51
+ tz = ActiveSupport::TimeZone.new('UTC')
52
+
53
+ ev['UID'] = 'bla'
54
+ ev['RRULE'] = 'FREQ=HOURLY;INTERVAL=3;UNTIL=20111025T000000Z'
55
+ dt_start = vcal.create_property('DTSTART')
56
+ dt_start.date_time = tz.parse('2011-10-07 12:00:00')
57
+
58
+ ev.add(dt_start)
59
+ vcal.add(ev)
60
+
61
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'])
62
+
63
+ # Max is to prevent overflow
64
+ max = 12
65
+ result = []
66
+ it.each do |item|
67
+ result << item
68
+ max -= 1
69
+
70
+ break if max == 0
71
+ end
72
+
73
+ assert_equal(
74
+ [
75
+ tz.parse('2011-10-07 12:00:00'),
76
+ tz.parse('2011-10-07 15:00:00'),
77
+ tz.parse('2011-10-07 18:00:00'),
78
+ tz.parse('2011-10-07 21:00:00'),
79
+ tz.parse('2011-10-08 00:00:00'),
80
+ tz.parse('2011-10-08 03:00:00'),
81
+ tz.parse('2011-10-08 06:00:00'),
82
+ tz.parse('2011-10-08 09:00:00'),
83
+ tz.parse('2011-10-08 12:00:00'),
84
+ tz.parse('2011-10-08 15:00:00'),
85
+ tz.parse('2011-10-08 18:00:00'),
86
+ tz.parse('2011-10-08 21:00:00')
87
+ ],
88
+ result
89
+ )
90
+ end
91
+
92
+ def test_daily
93
+ vcal = Tilia::VObject::Component::VCalendar.new
94
+ ev = vcal.create_component('VEVENT')
95
+
96
+ tz = ActiveSupport::TimeZone.new('UTC')
97
+
98
+ ev['UID'] = 'bla'
99
+ ev['RRULE'] = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z'
100
+ dt_start = vcal.create_property('DTSTART')
101
+ dt_start.date_time = tz.parse('2011-10-07')
102
+
103
+ ev.add(dt_start)
104
+
105
+ vcal.add(ev)
106
+
107
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'])
108
+
109
+ # Max is to prevent overflow
110
+ max = 12
111
+ result = []
112
+ it.each do |item|
113
+ result << item
114
+ max -= 1
115
+
116
+ break if max == 0
117
+ end
118
+
119
+ assert_equal(
120
+ [
121
+ tz.parse('2011-10-07'),
122
+ tz.parse('2011-10-10'),
123
+ tz.parse('2011-10-13'),
124
+ tz.parse('2011-10-16'),
125
+ tz.parse('2011-10-19'),
126
+ tz.parse('2011-10-22'),
127
+ tz.parse('2011-10-25')
128
+ ],
129
+ result
130
+ )
131
+ end
132
+
133
+ def test_no_rrule
134
+ vcal = Tilia::VObject::Component::VCalendar.new
135
+ ev = vcal.create_component('VEVENT')
136
+
137
+ tz = ActiveSupport::TimeZone.new('UTC')
138
+
139
+ ev['UID'] = 'bla'
140
+ dt_start = vcal.create_property('DTSTART')
141
+ dt_start.date_time = tz.parse('2011-10-07')
142
+
143
+ ev.add(dt_start)
144
+
145
+ vcal.add(ev)
146
+
147
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'])
148
+
149
+ # Max is to prevent overflow
150
+ max = 12
151
+ result = []
152
+ it.each do |item|
153
+ result << item
154
+ max -= 1
155
+
156
+ break if max == 0
157
+ end
158
+
159
+ assert_equal([tz.parse('2011-10-07')], result)
160
+ end
161
+
162
+ def test_daily_by_day_by_hour
163
+ vcal = Tilia::VObject::Component::VCalendar.new
164
+ ev = vcal.create_component('VEVENT')
165
+
166
+ tz = ActiveSupport::TimeZone.new('UTC')
167
+
168
+ ev['UID'] = 'bla'
169
+ ev['RRULE'] = 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7'
170
+ dt_start = vcal.create_property('DTSTART')
171
+ dt_start.date_time = tz.parse('2011-10-08 06:00:00')
172
+
173
+ ev.add(dt_start)
174
+
175
+ vcal.add(ev)
176
+
177
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
178
+
179
+ # Grabbing the next 12 items
180
+ max = 12
181
+ result = []
182
+ it.each do |item|
183
+ result << item
184
+ max -= 1
185
+
186
+ break if max == 0
187
+ end
188
+
189
+ assert_equal(
190
+ [
191
+ tz.parse('2011-10-08 06:00:00'),
192
+ tz.parse('2011-10-08 07:00:00'),
193
+ tz.parse('2011-10-09 06:00:00'),
194
+ tz.parse('2011-10-09 07:00:00'),
195
+ tz.parse('2011-10-15 06:00:00'),
196
+ tz.parse('2011-10-15 07:00:00'),
197
+ tz.parse('2011-10-16 06:00:00'),
198
+ tz.parse('2011-10-16 07:00:00'),
199
+ tz.parse('2011-10-22 06:00:00'),
200
+ tz.parse('2011-10-22 07:00:00'),
201
+ tz.parse('2011-10-23 06:00:00'),
202
+ tz.parse('2011-10-23 07:00:00')
203
+ ],
204
+ result
205
+ )
206
+ end
207
+
208
+ def test_daily_by_hour
209
+ vcal = Tilia::VObject::Component::VCalendar.new
210
+ ev = vcal.create_component('VEVENT')
211
+
212
+ tz = ActiveSupport::TimeZone.new('UTC')
213
+
214
+ ev['UID'] = 'bla'
215
+ ev['RRULE'] = 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15'
216
+ dt_start = vcal.create_property('DTSTART')
217
+ dt_start.date_time = tz.parse('2012-10-11 12:00:00')
218
+
219
+ ev.add(dt_start)
220
+
221
+ vcal.add(ev)
222
+
223
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
224
+
225
+ # Grabbing the next 12 items
226
+ max = 12
227
+ result = []
228
+ it.each do |item|
229
+ result << item
230
+ max -= 1
231
+
232
+ break if max == 0
233
+ end
234
+
235
+ assert_equal(
236
+ [
237
+ tz.parse('2012-10-11 12:00:00'),
238
+ tz.parse('2012-10-11 13:00:00'),
239
+ tz.parse('2012-10-11 14:00:00'),
240
+ tz.parse('2012-10-11 15:00:00'),
241
+ tz.parse('2012-10-13 10:00:00'),
242
+ tz.parse('2012-10-13 11:00:00'),
243
+ tz.parse('2012-10-13 12:00:00'),
244
+ tz.parse('2012-10-13 13:00:00'),
245
+ tz.parse('2012-10-13 14:00:00'),
246
+ tz.parse('2012-10-13 15:00:00'),
247
+ tz.parse('2012-10-15 10:00:00'),
248
+ tz.parse('2012-10-15 11:00:00')
249
+ ],
250
+ result
251
+ )
252
+ end
253
+
254
+ def test_daily_by_day
255
+ vcal = Tilia::VObject::Component::VCalendar.new
256
+ ev = vcal.create_component('VEVENT')
257
+
258
+ tz = ActiveSupport::TimeZone.new('UTC')
259
+
260
+ ev['UID'] = 'bla'
261
+ ev['RRULE'] = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR'
262
+ dt_start = vcal.create_property('DTSTART')
263
+ dt_start.date_time = tz.parse('2011-10-07')
264
+
265
+ ev.add(dt_start)
266
+
267
+ vcal.add(ev)
268
+
269
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
270
+
271
+ # Grabbing the next 12 items
272
+ max = 12
273
+ result = []
274
+ it.each do |item|
275
+ result << item
276
+ max -= 1
277
+
278
+ break if max == 0
279
+ end
280
+
281
+ assert_equal(
282
+ [
283
+ tz.parse('2011-10-07'),
284
+ tz.parse('2011-10-11'),
285
+ tz.parse('2011-10-19'),
286
+ tz.parse('2011-10-21'),
287
+ tz.parse('2011-10-25'),
288
+ tz.parse('2011-11-02'),
289
+ tz.parse('2011-11-04'),
290
+ tz.parse('2011-11-08'),
291
+ tz.parse('2011-11-16'),
292
+ tz.parse('2011-11-18'),
293
+ tz.parse('2011-11-22'),
294
+ tz.parse('2011-11-30')
295
+ ],
296
+ result
297
+ )
298
+ end
299
+
300
+ def test_weekly
301
+ vcal = Tilia::VObject::Component::VCalendar.new
302
+ ev = vcal.create_component('VEVENT')
303
+
304
+ tz = ActiveSupport::TimeZone.new('UTC')
305
+
306
+ ev['UID'] = 'bla'
307
+ ev['RRULE'] = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10'
308
+ dt_start = vcal.create_property('DTSTART')
309
+ dt_start.date_time = tz.parse('2011-10-07')
310
+
311
+ ev.add(dt_start)
312
+
313
+ vcal.add(ev)
314
+
315
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
316
+
317
+ # Max is to prevent overflow
318
+ max = 12
319
+ result = []
320
+ it.each do |item|
321
+ result << item
322
+ max -= 1
323
+
324
+ break if max == 0
325
+ end
326
+
327
+ assert_equal(
328
+ [
329
+ tz.parse('2011-10-07'),
330
+ tz.parse('2011-10-21'),
331
+ tz.parse('2011-11-04'),
332
+ tz.parse('2011-11-18'),
333
+ tz.parse('2011-12-02'),
334
+ tz.parse('2011-12-16'),
335
+ tz.parse('2011-12-30'),
336
+ tz.parse('2012-01-13'),
337
+ tz.parse('2012-01-27'),
338
+ tz.parse('2012-02-10')
339
+ ],
340
+ result
341
+ )
342
+ end
343
+
344
+ def test_weekly_by_day_by_hour
345
+ vcal = Tilia::VObject::Component::VCalendar.new
346
+ ev = vcal.create_component('VEVENT')
347
+
348
+ tz = ActiveSupport::TimeZone.new('UTC')
349
+
350
+ ev['UID'] = 'bla'
351
+ ev['RRULE'] = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10'
352
+ dt_start = vcal.create_property('DTSTART')
353
+ dt_start.date_time = tz.parse('2011-10-07 08:00:00')
354
+
355
+ ev.add(dt_start)
356
+
357
+ vcal.add(ev)
358
+
359
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
360
+
361
+ # Grabbing the next 12 items
362
+ max = 15
363
+ result = []
364
+ it.each do |item|
365
+ result << item
366
+ max -= 1
367
+
368
+ break if max == 0
369
+ end
370
+
371
+ assert_equal(
372
+ [
373
+ tz.parse('2011-10-07 08:00:00'),
374
+ tz.parse('2011-10-07 09:00:00'),
375
+ tz.parse('2011-10-07 10:00:00'),
376
+ tz.parse('2011-10-18 08:00:00'),
377
+ tz.parse('2011-10-18 09:00:00'),
378
+ tz.parse('2011-10-18 10:00:00'),
379
+ tz.parse('2011-10-19 08:00:00'),
380
+ tz.parse('2011-10-19 09:00:00'),
381
+ tz.parse('2011-10-19 10:00:00'),
382
+ tz.parse('2011-10-21 08:00:00'),
383
+ tz.parse('2011-10-21 09:00:00'),
384
+ tz.parse('2011-10-21 10:00:00'),
385
+ tz.parse('2011-11-01 08:00:00'),
386
+ tz.parse('2011-11-01 09:00:00'),
387
+ tz.parse('2011-11-01 10:00:00')
388
+ ],
389
+ result
390
+ )
391
+ end
392
+
393
+ def test_weekly_by_day_specific_hour
394
+ vcal = Tilia::VObject::Component::VCalendar.new
395
+ ev = vcal.create_component('VEVENT')
396
+
397
+ tz = ActiveSupport::TimeZone.new('UTC')
398
+
399
+ ev['UID'] = 'bla'
400
+ ev['RRULE'] = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'
401
+ dt_start = vcal.create_property('DTSTART')
402
+ dt_start.date_time = tz.parse('2011-10-07 18:00:00')
403
+
404
+ ev.add(dt_start)
405
+
406
+ vcal.add(ev)
407
+
408
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
409
+
410
+ # Grabbing the next 12 items
411
+ max = 12
412
+ result = []
413
+ it.each do |item|
414
+ result << item
415
+ max -= 1
416
+
417
+ break if max == 0
418
+ end
419
+
420
+ assert_equal(
421
+ [
422
+ tz.parse('2011-10-07 18:00:00'),
423
+ tz.parse('2011-10-18 18:00:00'),
424
+ tz.parse('2011-10-19 18:00:00'),
425
+ tz.parse('2011-10-21 18:00:00'),
426
+ tz.parse('2011-11-01 18:00:00'),
427
+ tz.parse('2011-11-02 18:00:00'),
428
+ tz.parse('2011-11-04 18:00:00'),
429
+ tz.parse('2011-11-15 18:00:00'),
430
+ tz.parse('2011-11-16 18:00:00'),
431
+ tz.parse('2011-11-18 18:00:00'),
432
+ tz.parse('2011-11-29 18:00:00'),
433
+ tz.parse('2011-11-30 18:00:00')
434
+ ],
435
+ result
436
+ )
437
+ end
438
+
439
+ def test_weekly_by_day
440
+ vcal = Tilia::VObject::Component::VCalendar.new
441
+ ev = vcal.create_component('VEVENT')
442
+
443
+ tz = ActiveSupport::TimeZone.new('UTC')
444
+
445
+ ev['UID'] = 'bla'
446
+ ev['RRULE'] = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'
447
+ dt_start = vcal.create_property('DTSTART')
448
+ dt_start.date_time = tz.parse('2011-10-07')
449
+
450
+ ev.add(dt_start)
451
+
452
+ vcal.add(ev)
453
+
454
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
455
+
456
+ # Grabbing the next 12 items
457
+ max = 12
458
+ result = []
459
+ it.each do |item|
460
+ result << item
461
+ max -= 1
462
+
463
+ break if max == 0
464
+ end
465
+
466
+ assert_equal(
467
+ [
468
+ tz.parse('2011-10-07'),
469
+ tz.parse('2011-10-18'),
470
+ tz.parse('2011-10-19'),
471
+ tz.parse('2011-10-21'),
472
+ tz.parse('2011-11-01'),
473
+ tz.parse('2011-11-02'),
474
+ tz.parse('2011-11-04'),
475
+ tz.parse('2011-11-15'),
476
+ tz.parse('2011-11-16'),
477
+ tz.parse('2011-11-18'),
478
+ tz.parse('2011-11-29'),
479
+ tz.parse('2011-11-30')
480
+ ],
481
+ result
482
+ )
483
+ end
484
+
485
+ def test_monthly
486
+ vcal = Tilia::VObject::Component::VCalendar.new
487
+ ev = vcal.create_component('VEVENT')
488
+
489
+ tz = ActiveSupport::TimeZone.new('UTC')
490
+
491
+ ev['UID'] = 'bla'
492
+ ev['RRULE'] = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5'
493
+ dt_start = vcal.create_property('DTSTART')
494
+ dt_start.date_time = tz.parse('2011-12-05')
495
+
496
+ ev.add(dt_start)
497
+
498
+ vcal.add(ev)
499
+
500
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
501
+
502
+ max = 14
503
+ result = []
504
+ it.each do |item|
505
+ result << item
506
+ max -= 1
507
+
508
+ break if max == 0
509
+ end
510
+
511
+ assert_equal(
512
+ [
513
+ tz.parse('2011-12-05'),
514
+ tz.parse('2012-03-05'),
515
+ tz.parse('2012-06-05'),
516
+ tz.parse('2012-09-05'),
517
+ tz.parse('2012-12-05')
518
+ ],
519
+ result
520
+ )
521
+ end
522
+
523
+ def test_monthly_end_of_month
524
+ vcal = Tilia::VObject::Component::VCalendar.new
525
+ ev = vcal.create_component('VEVENT')
526
+
527
+ tz = ActiveSupport::TimeZone.new('UTC')
528
+
529
+ ev['UID'] = 'bla'
530
+ ev['RRULE'] = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12'
531
+ dt_start = vcal.create_property('DTSTART')
532
+ dt_start.date_time = tz.parse('2011-12-31')
533
+
534
+ ev.add(dt_start)
535
+
536
+ vcal.add(ev)
537
+
538
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
539
+
540
+ max = 14
541
+ result = []
542
+ it.each do |item|
543
+ result << item
544
+ max -= 1
545
+
546
+ break if max == 0
547
+ end
548
+
549
+ assert_equal(
550
+ [
551
+ tz.parse('2011-12-31'),
552
+ tz.parse('2012-08-31'),
553
+ tz.parse('2012-10-31'),
554
+ tz.parse('2012-12-31'),
555
+ tz.parse('2013-08-31'),
556
+ tz.parse('2013-10-31'),
557
+ tz.parse('2013-12-31'),
558
+ tz.parse('2014-08-31'),
559
+ tz.parse('2014-10-31'),
560
+ tz.parse('2014-12-31'),
561
+ tz.parse('2015-08-31'),
562
+ tz.parse('2015-10-31')
563
+ ],
564
+ result
565
+ )
566
+ end
567
+
568
+ def test_monthly_by_month_day
569
+ vcal = Tilia::VObject::Component::VCalendar.new
570
+ ev = vcal.create_component('VEVENT')
571
+
572
+ tz = ActiveSupport::TimeZone.new('UTC')
573
+
574
+ ev['UID'] = 'bla'
575
+ ev['RRULE'] = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7'
576
+ dt_start = vcal.create_property('DTSTART')
577
+ dt_start.date_time = tz.parse('2011-01-01')
578
+
579
+ ev.add(dt_start)
580
+
581
+ vcal.add(ev)
582
+
583
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
584
+
585
+ max = 14
586
+ result = []
587
+ it.each do |item|
588
+ result << item
589
+ max -= 1
590
+
591
+ break if max == 0
592
+ end
593
+
594
+ assert_equal(
595
+ [
596
+ tz.parse('2011-01-01'),
597
+ tz.parse('2011-01-25'),
598
+ tz.parse('2011-01-31'),
599
+ tz.parse('2011-06-01'),
600
+ tz.parse('2011-06-24'),
601
+ tz.parse('2011-11-01'),
602
+ tz.parse('2011-11-24'),
603
+ tz.parse('2012-04-01'),
604
+ tz.parse('2012-04-24')
605
+ ],
606
+ result
607
+ )
608
+ end
609
+
610
+ # A pretty slow test. Had to be marked as 'medium' for phpunit to not die
611
+ # after 1 second. Would be good to optimize later.
612
+ def test_monthly_by_day
613
+ vcal = Tilia::VObject::Component::VCalendar.new
614
+ ev = vcal.create_component('VEVENT')
615
+
616
+ tz = ActiveSupport::TimeZone.new('UTC')
617
+
618
+ ev['UID'] = 'bla'
619
+ ev['RRULE'] = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH'
620
+ dt_start = vcal.create_property('DTSTART')
621
+ dt_start.date_time = tz.parse('2011-01-03')
622
+
623
+ ev.add(dt_start)
624
+
625
+ vcal.add(ev)
626
+
627
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
628
+
629
+ max = 20
630
+ result = []
631
+ it.each do |item|
632
+ result << item
633
+ max -= 1
634
+
635
+ break if max == 0
636
+ end
637
+
638
+ assert_equal(
639
+ [
640
+ tz.parse('2011-01-03'),
641
+ tz.parse('2011-01-05'),
642
+ tz.parse('2011-01-10'),
643
+ tz.parse('2011-01-17'),
644
+ tz.parse('2011-01-18'),
645
+ tz.parse('2011-01-20'),
646
+ tz.parse('2011-01-24'),
647
+ tz.parse('2011-01-31'),
648
+ tz.parse('2011-03-02'),
649
+ tz.parse('2011-03-07'),
650
+ tz.parse('2011-03-14'),
651
+ tz.parse('2011-03-17'),
652
+ tz.parse('2011-03-21'),
653
+ tz.parse('2011-03-22'),
654
+ tz.parse('2011-03-28'),
655
+ tz.parse('2011-05-02')
656
+ ],
657
+ result
658
+ )
659
+ end
660
+
661
+ def test_monthly_by_day_by_month_day
662
+ vcal = Tilia::VObject::Component::VCalendar.new
663
+ ev = vcal.create_component('VEVENT')
664
+
665
+ tz = ActiveSupport::TimeZone.new('UTC')
666
+
667
+ ev['UID'] = 'bla'
668
+ ev['RRULE'] = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1'
669
+ dt_start = vcal.create_property('DTSTART')
670
+ dt_start.date_time = tz.parse('2011-08-01')
671
+
672
+ ev.add(dt_start)
673
+
674
+ vcal.add(ev)
675
+
676
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
677
+
678
+ max = 20
679
+ result = []
680
+ it.each do |item|
681
+ result << item
682
+ max -= 1
683
+
684
+ break if max == 0
685
+ end
686
+
687
+ assert_equal(
688
+ [
689
+ tz.parse('2011-08-01'),
690
+ tz.parse('2012-10-01'),
691
+ tz.parse('2013-04-01'),
692
+ tz.parse('2013-07-01'),
693
+ tz.parse('2014-09-01'),
694
+ tz.parse('2014-12-01'),
695
+ tz.parse('2015-06-01'),
696
+ tz.parse('2016-02-01'),
697
+ tz.parse('2016-08-01'),
698
+ tz.parse('2017-05-01')
699
+ ],
700
+ result
701
+ )
702
+ end
703
+
704
+ def test_monthly_by_day_by_set_pos
705
+ vcal = Tilia::VObject::Component::VCalendar.new
706
+ ev = vcal.create_component('VEVENT')
707
+
708
+ tz = ActiveSupport::TimeZone.new('UTC')
709
+
710
+ ev['UID'] = 'bla'
711
+ ev['RRULE'] = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1'
712
+ dt_start = vcal.create_property('DTSTART')
713
+ dt_start.date_time = tz.parse('2011-01-03')
714
+
715
+ ev.add(dt_start)
716
+
717
+ vcal.add(ev)
718
+
719
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
720
+
721
+ max = 20
722
+ result = []
723
+ it.each do |item|
724
+ result << item
725
+ max -= 1
726
+
727
+ break if max == 0
728
+ end
729
+
730
+ assert_equal(
731
+ [
732
+ tz.parse('2011-01-03'),
733
+ tz.parse('2011-01-31'),
734
+ tz.parse('2011-02-01'),
735
+ tz.parse('2011-02-28'),
736
+ tz.parse('2011-03-01'),
737
+ tz.parse('2011-03-31'),
738
+ tz.parse('2011-04-01'),
739
+ tz.parse('2011-04-29'),
740
+ tz.parse('2011-05-02'),
741
+ tz.parse('2011-05-31')
742
+ ],
743
+ result
744
+ )
745
+ end
746
+
747
+ def test_yearly
748
+ vcal = Tilia::VObject::Component::VCalendar.new
749
+ ev = vcal.create_component('VEVENT')
750
+
751
+ tz = ActiveSupport::TimeZone.new('UTC')
752
+
753
+ ev['UID'] = 'bla'
754
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=10;INTERVAL=3'
755
+ dt_start = vcal.create_property('DTSTART')
756
+ dt_start.date_time = tz.parse('2011-01-01')
757
+
758
+ ev.add(dt_start)
759
+
760
+ vcal.add(ev)
761
+
762
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
763
+
764
+ max = 20
765
+ result = []
766
+ it.each do |item|
767
+ result << item
768
+ max -= 1
769
+
770
+ break if max == 0
771
+ end
772
+
773
+ assert_equal(
774
+ [
775
+ tz.parse('2011-01-01'),
776
+ tz.parse('2014-01-01'),
777
+ tz.parse('2017-01-01'),
778
+ tz.parse('2020-01-01'),
779
+ tz.parse('2023-01-01'),
780
+ tz.parse('2026-01-01'),
781
+ tz.parse('2029-01-01'),
782
+ tz.parse('2032-01-01'),
783
+ tz.parse('2035-01-01'),
784
+ tz.parse('2038-01-01')
785
+ ],
786
+ result
787
+ )
788
+ end
789
+
790
+ def test_yearly_leap_year
791
+ vcal = Tilia::VObject::Component::VCalendar.new
792
+ ev = vcal.create_component('VEVENT')
793
+
794
+ tz = ActiveSupport::TimeZone.new('UTC')
795
+
796
+ ev['UID'] = 'bla'
797
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=3'
798
+ dt_start = vcal.create_property('DTSTART')
799
+ dt_start.date_time = tz.parse('2012-02-29')
800
+
801
+ ev.add(dt_start)
802
+
803
+ vcal.add(ev)
804
+
805
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
806
+
807
+ max = 20
808
+ result = []
809
+ it.each do |item|
810
+ result << item
811
+ max -= 1
812
+
813
+ break if max == 0
814
+ end
815
+
816
+ assert_equal(
817
+ [
818
+ tz.parse('2012-02-29'),
819
+ tz.parse('2016-02-29'),
820
+ tz.parse('2020-02-29')
821
+ ],
822
+ result
823
+ )
824
+ end
825
+
826
+ def test_yearly_by_month
827
+ vcal = Tilia::VObject::Component::VCalendar.new
828
+ ev = vcal.create_component('VEVENT')
829
+
830
+ tz = ActiveSupport::TimeZone.new('UTC')
831
+
832
+ ev['UID'] = 'bla'
833
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10'
834
+ dt_start = vcal.create_property('DTSTART')
835
+ dt_start.date_time = tz.parse('2011-04-07')
836
+
837
+ ev.add(dt_start)
838
+
839
+ vcal.add(ev)
840
+
841
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
842
+
843
+ max = 20
844
+ result = []
845
+ it.each do |item|
846
+ result << item
847
+ max -= 1
848
+
849
+ break if max == 0
850
+ end
851
+
852
+ assert_equal(
853
+ [
854
+ tz.parse('2011-04-07'),
855
+ tz.parse('2011-10-07'),
856
+ tz.parse('2015-04-07'),
857
+ tz.parse('2015-10-07'),
858
+ tz.parse('2019-04-07'),
859
+ tz.parse('2019-10-07'),
860
+ tz.parse('2023-04-07'),
861
+ tz.parse('2023-10-07')
862
+ ],
863
+ result
864
+ )
865
+ end
866
+
867
+ def test_yearly_by_month_by_day
868
+ vcal = Tilia::VObject::Component::VCalendar.new
869
+ ev = vcal.create_component('VEVENT')
870
+
871
+ tz = ActiveSupport::TimeZone.new('UTC')
872
+
873
+ ev['UID'] = 'bla'
874
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'
875
+ dt_start = vcal.create_property('DTSTART')
876
+ dt_start.date_time = tz.parse('2011-04-04')
877
+
878
+ ev.add(dt_start)
879
+
880
+ vcal.add(ev)
881
+
882
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
883
+
884
+ max = 20
885
+ result = []
886
+ it.each do |item|
887
+ result << item
888
+ max -= 1
889
+
890
+ break if max == 0
891
+ end
892
+
893
+ assert_equal(
894
+ [
895
+ tz.parse('2011-04-04'),
896
+ tz.parse('2011-04-24'),
897
+ tz.parse('2011-10-03'),
898
+ tz.parse('2011-10-30'),
899
+ tz.parse('2016-04-04'),
900
+ tz.parse('2016-04-24'),
901
+ tz.parse('2016-10-03'),
902
+ tz.parse('2016-10-30')
903
+ ],
904
+ result
905
+ )
906
+ end
907
+
908
+ def test_fast_forward
909
+ vcal = Tilia::VObject::Component::VCalendar.new
910
+ ev = vcal.create_component('VEVENT')
911
+
912
+ tz = ActiveSupport::TimeZone.new('UTC')
913
+
914
+ ev['UID'] = 'bla'
915
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'
916
+ dt_start = vcal.create_property('DTSTART')
917
+ dt_start.date_time = tz.parse('2011-04-04')
918
+
919
+ ev.add(dt_start)
920
+
921
+ vcal.add(ev)
922
+
923
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
924
+
925
+ # The idea is that we're fast-forwarding too far in the future, so
926
+ # there will be no results left.
927
+ it.fast_forward(tz.parse('2020-05-05'))
928
+
929
+ max = 20
930
+ result = []
931
+ while it.valid
932
+ result << it.current
933
+ max -= 1
934
+
935
+ break if max == 0
936
+ it.next
937
+ end
938
+
939
+ assert_equal([], result)
940
+ end
941
+
942
+ def test_complex_exclusions
943
+ vcal = Tilia::VObject::Component::VCalendar.new
944
+ ev = vcal.create_component('VEVENT')
945
+
946
+ tz = ActiveSupport::TimeZone.new('Canada/Eastern')
947
+
948
+ ev['UID'] = 'bla'
949
+ ev['RRULE'] = 'FREQ=YEARLY;COUNT=10'
950
+ dt_start = vcal.create_property('DTSTART')
951
+
952
+ dt_start.date_time = tz.parse('2011-01-01 13:50:20')
953
+
954
+ ex_date1 = vcal.create_property('EXDATE')
955
+ ex_date1.date_times = [tz.parse('2012-01-01 13:50:20'), tz.parse('2014-01-01 13:50:20')]
956
+ ex_date2 = vcal.create_property('EXDATE')
957
+ ex_date2.date_times = [tz.parse('2016-01-01 13:50:20')]
958
+
959
+ ev.add(dt_start)
960
+ ev.add(ex_date1)
961
+ ev.add(ex_date2)
962
+
963
+ vcal.add(ev)
964
+
965
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'].to_s)
966
+
967
+ max = 20
968
+ result = []
969
+ it.each do |item|
970
+ result << item
971
+ max -= 1
972
+
973
+ break if max == 0
974
+ end
975
+
976
+ assert_equal(
977
+ [
978
+ tz.parse('2011-01-01 13:50:20'),
979
+ tz.parse('2013-01-01 13:50:20'),
980
+ tz.parse('2015-01-01 13:50:20'),
981
+ tz.parse('2017-01-01 13:50:20'),
982
+ tz.parse('2018-01-01 13:50:20'),
983
+ tz.parse('2019-01-01 13:50:20'),
984
+ tz.parse('2020-01-01 13:50:20')
985
+ ],
986
+ result
987
+ )
988
+ end
989
+
990
+ def test_overriden_event
991
+ vcal = Tilia::VObject::Component::VCalendar.new
992
+
993
+ ev1 = vcal.create_component('VEVENT')
994
+ ev1['UID'] = 'overridden'
995
+ ev1['RRULE'] = 'FREQ=DAILY;COUNT=10'
996
+ ev1['DTSTART'] = '20120107T120000Z'
997
+ ev1['SUMMARY'] = 'baseEvent'
998
+
999
+ vcal.add(ev1)
1000
+
1001
+ # ev2 overrides an event, and puts it on 2pm instead.
1002
+ ev2 = vcal.create_component('VEVENT')
1003
+ ev2['UID'] = 'overridden'
1004
+ ev2['RECURRENCE-ID'] = '20120110T120000Z'
1005
+ ev2['DTSTART'] = '20120110T140000Z'
1006
+ ev2['SUMMARY'] = 'Event 2'
1007
+
1008
+ vcal.add(ev2)
1009
+
1010
+ # ev3 overrides an event, and puts it 2 days and 2 hours later
1011
+ ev3 = vcal.create_component('VEVENT')
1012
+ ev3['UID'] = 'overridden'
1013
+ ev3['RECURRENCE-ID'] = '20120113T120000Z'
1014
+ ev3['DTSTART'] = '20120115T140000Z'
1015
+ ev3['SUMMARY'] = 'Event 3'
1016
+
1017
+ vcal.add(ev3)
1018
+
1019
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, 'overridden')
1020
+
1021
+ dates = []
1022
+ summaries = []
1023
+ while it.valid
1024
+ dates << it.dt_start
1025
+ summaries << it.event_object['SUMMARY'].to_s
1026
+ it.next
1027
+ end
1028
+
1029
+ tz = ActiveSupport::TimeZone.new('UTC')
1030
+ assert_equal(
1031
+ [
1032
+ tz.parse('2012-01-07 12:00:00'),
1033
+ tz.parse('2012-01-08 12:00:00'),
1034
+ tz.parse('2012-01-09 12:00:00'),
1035
+ tz.parse('2012-01-10 14:00:00'),
1036
+ tz.parse('2012-01-11 12:00:00'),
1037
+ tz.parse('2012-01-12 12:00:00'),
1038
+ tz.parse('2012-01-14 12:00:00'),
1039
+ tz.parse('2012-01-15 12:00:00'),
1040
+ tz.parse('2012-01-15 14:00:00'),
1041
+ tz.parse('2012-01-16 12:00:00')
1042
+ ],
1043
+ dates
1044
+ )
1045
+
1046
+ assert_equal(
1047
+ [
1048
+ 'baseEvent',
1049
+ 'baseEvent',
1050
+ 'baseEvent',
1051
+ 'Event 2',
1052
+ 'baseEvent',
1053
+ 'baseEvent',
1054
+ 'baseEvent',
1055
+ 'baseEvent',
1056
+ 'Event 3',
1057
+ 'baseEvent'
1058
+ ],
1059
+ summaries
1060
+ )
1061
+ end
1062
+
1063
+ def test_overriden_event2
1064
+ vcal = Tilia::VObject::Component::VCalendar.new
1065
+
1066
+ ev1 = vcal.create_component('VEVENT')
1067
+ ev1['UID'] = 'overridden'
1068
+ ev1['RRULE'] = 'FREQ=WEEKLY;COUNT=3'
1069
+ ev1['DTSTART'] = '20120112T120000Z'
1070
+ ev1['SUMMARY'] = 'baseEvent'
1071
+
1072
+ vcal.add(ev1)
1073
+
1074
+ # ev2 overrides an event, and puts it 6 days earlier instead.
1075
+ ev2 = vcal.create_component('VEVENT')
1076
+ ev2['UID'] = 'overridden'
1077
+ ev2['RECURRENCE-ID'] = '20120119T120000Z'
1078
+ ev2['DTSTART'] = '20120113T120000Z'
1079
+ ev2['SUMMARY'] = 'Override!'
1080
+
1081
+ vcal.add(ev2)
1082
+
1083
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, 'overridden')
1084
+
1085
+ dates = []
1086
+ summaries = []
1087
+ while it.valid
1088
+ dates << it.dt_start
1089
+ summaries << it.event_object['SUMMARY'].to_s
1090
+ it.next
1091
+ end
1092
+
1093
+ tz = ActiveSupport::TimeZone.new('UTC')
1094
+ assert_equal(
1095
+ [
1096
+ tz.parse('2012-01-12 12:00:00'),
1097
+ tz.parse('2012-01-13 12:00:00'),
1098
+ tz.parse('2012-01-26 12:00:00')
1099
+ ],
1100
+ dates
1101
+ )
1102
+
1103
+ assert_equal(
1104
+ [
1105
+ 'baseEvent',
1106
+ 'Override!',
1107
+ 'baseEvent'
1108
+ ],
1109
+ summaries
1110
+ )
1111
+ end
1112
+
1113
+ def test_overriden_event_no_values_expected
1114
+ vcal = Tilia::VObject::Component::VCalendar.new
1115
+ ev1 = vcal.create_component('VEVENT')
1116
+
1117
+ tz = ActiveSupport::TimeZone.new('UTC')
1118
+
1119
+ ev1['UID'] = 'overridden'
1120
+ ev1['RRULE'] = 'FREQ=WEEKLY;COUNT=3'
1121
+ ev1['DTSTART'] = '20120124T120000Z'
1122
+ ev1['SUMMARY'] = 'baseEvent'
1123
+
1124
+ vcal.add(ev1)
1125
+
1126
+ # ev2 overrides an event, and puts it 6 days earlier instead.
1127
+ ev2 = vcal.create_component('VEVENT')
1128
+ ev2['UID'] = 'overridden'
1129
+ ev2['RECURRENCE-ID'] = '20120131T120000Z'
1130
+ ev2['DTSTART'] = '20120125T120000Z'
1131
+ ev2['SUMMARY'] = 'Override!'
1132
+
1133
+ vcal.add(ev2)
1134
+
1135
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, 'overridden')
1136
+
1137
+ dates = []
1138
+ summaries = []
1139
+
1140
+ # The reported problem was specifically related to the VCALENDAR
1141
+ # expansion. In this parcitular case, we had to forward to the 28th of
1142
+ # january.
1143
+ it.fast_forward(tz.parse('2012-01-28 23:00:00'))
1144
+
1145
+ # We stop the loop when it hits the 6th of februari. Normally this
1146
+ # iterator would hit 24, 25 (overriden from 31) and 7 feb but because
1147
+ # we 'filter' from the 28th till the 6th, we should get 0 results.
1148
+ while it.valid && it.dt_start < tz.parse('2012-02-06 23:00:00')
1149
+ dates << it.dt_start
1150
+ summaries << it.event_object['SUMMARY'].to_s
1151
+ it.next
1152
+ end
1153
+
1154
+ assert_equal([], dates)
1155
+ assert_equal([], summaries)
1156
+ end
1157
+
1158
+ def test_rdate
1159
+ vcal = Tilia::VObject::Component::VCalendar.new
1160
+ ev = vcal.create_component('VEVENT')
1161
+
1162
+ tz = ActiveSupport::TimeZone.new('UTC')
1163
+
1164
+ ev['UID'] = 'bla'
1165
+ ev['RDATE'] = [
1166
+ tz.parse('2014-08-07'),
1167
+ tz.parse('2014-08-08')
1168
+ ]
1169
+ dt_start = vcal.create_property('DTSTART')
1170
+ dt_start.date_time = tz.parse('2011-10-07')
1171
+
1172
+ ev.add(dt_start)
1173
+
1174
+ vcal.add(ev)
1175
+
1176
+ it = Tilia::VObject::Recur::EventIterator.new(vcal, ev['UID'])
1177
+
1178
+ # Max is to prevent overflow
1179
+ max = 12
1180
+ result = []
1181
+ it.each do |item|
1182
+ result << item
1183
+ max -= 1
1184
+
1185
+ break if max == 0
1186
+ end
1187
+
1188
+ assert_equal(
1189
+ [
1190
+ tz.parse('2011-10-07'),
1191
+ tz.parse('2014-08-07'),
1192
+ tz.parse('2014-08-08')
1193
+ ],
1194
+ result
1195
+ )
1196
+ end
1197
+
1198
+ def test_no_master_bad_uid
1199
+ vcal = Tilia::VObject::Component::VCalendar.new
1200
+ # ev2 overrides an event, and puts it on 2pm instead.
1201
+ ev2 = vcal.create_component('VEVENT')
1202
+ ev2['UID'] = 'overridden'
1203
+ ev2['RECURRENCE-ID'] = '20120110T120000Z'
1204
+ ev2['DTSTART'] = '20120110T140000Z'
1205
+ ev2['SUMMARY'] = 'Event 2'
1206
+
1207
+ vcal.add(ev2)
1208
+
1209
+ # ev3 overrides an event, and puts it 2 days and 2 hours later
1210
+ ev3 = vcal.create_component('VEVENT')
1211
+ ev3['UID'] = 'overridden'
1212
+ ev3['RECURRENCE-ID'] = '20120113T120000Z'
1213
+ ev3['DTSTART'] = '20120115T140000Z'
1214
+ ev3['SUMMARY'] = 'Event 3'
1215
+
1216
+ vcal.add(ev3)
1217
+
1218
+ assert_raises(ArgumentError) { Tilia::VObject::Recur::EventIterator.new(vcal, 'broken') }
1219
+ end
1220
+ end
1221
+ end
1222
+ end