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,526 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class DateTimeParserTest < Minitest::Test
6
+ def setup
7
+ @utc = ActiveSupport::TimeZone.new('UTC')
8
+ end
9
+
10
+ def vcard_dates
11
+ [
12
+ [
13
+ '19961022T140000',
14
+ {
15
+ 'year' => 1996,
16
+ 'month' => 10,
17
+ 'date' => 22,
18
+ 'hour' => 14,
19
+ 'minute' => 00,
20
+ 'second' => 00,
21
+ 'timezone' => nil
22
+ }
23
+ ],
24
+ [
25
+ '--1022T1400',
26
+ {
27
+ 'year' => nil,
28
+ 'month' => 10,
29
+ 'date' => 22,
30
+ 'hour' => 14,
31
+ 'minute' => 00,
32
+ 'second' => nil,
33
+ 'timezone' => nil
34
+ }
35
+ ],
36
+ [
37
+ '---22T14',
38
+ {
39
+ 'year' => nil,
40
+ 'month' => nil,
41
+ 'date' => 22,
42
+ 'hour' => 14,
43
+ 'minute' => nil,
44
+ 'second' => nil,
45
+ 'timezone' => nil
46
+ }
47
+ ],
48
+ [
49
+ '19850412',
50
+ {
51
+ 'year' => 1985,
52
+ 'month' => 4,
53
+ 'date' => 12,
54
+ 'hour' => nil,
55
+ 'minute' => nil,
56
+ 'second' => nil,
57
+ 'timezone' => nil
58
+ }
59
+ ],
60
+ [
61
+ '1985-04',
62
+ {
63
+ 'year' => 1985,
64
+ 'month' => 04,
65
+ 'date' => nil,
66
+ 'hour' => nil,
67
+ 'minute' => nil,
68
+ 'second' => nil,
69
+ 'timezone' => nil
70
+ }
71
+ ],
72
+ [
73
+ '1985',
74
+ {
75
+ 'year' => 1985,
76
+ 'month' => nil,
77
+ 'date' => nil,
78
+ 'hour' => nil,
79
+ 'minute' => nil,
80
+ 'second' => nil,
81
+ 'timezone' => nil
82
+ }
83
+ ],
84
+ [
85
+ '--0412',
86
+ {
87
+ 'year' => nil,
88
+ 'month' => 4,
89
+ 'date' => 12,
90
+ 'hour' => nil,
91
+ 'minute' => nil,
92
+ 'second' => nil,
93
+ 'timezone' => nil
94
+ }
95
+ ],
96
+ [
97
+ '---12',
98
+ {
99
+ 'year' => nil,
100
+ 'month' => nil,
101
+ 'date' => 12,
102
+ 'hour' => nil,
103
+ 'minute' => nil,
104
+ 'second' => nil,
105
+ 'timezone' => nil
106
+ }
107
+ ],
108
+ [
109
+ 'T102200',
110
+ {
111
+ 'year' => nil,
112
+ 'month' => nil,
113
+ 'date' => nil,
114
+ 'hour' => 10,
115
+ 'minute' => 22,
116
+ 'second' => 0,
117
+ 'timezone' => nil
118
+ }
119
+ ],
120
+ [
121
+ 'T1022',
122
+ {
123
+ 'year' => nil,
124
+ 'month' => nil,
125
+ 'date' => nil,
126
+ 'hour' => 10,
127
+ 'minute' => 22,
128
+ 'second' => nil,
129
+ 'timezone' => nil
130
+ }
131
+ ],
132
+ [
133
+ 'T10',
134
+ {
135
+ 'year' => nil,
136
+ 'month' => nil,
137
+ 'date' => nil,
138
+ 'hour' => 10,
139
+ 'minute' => nil,
140
+ 'second' => nil,
141
+ 'timezone' => nil
142
+ }
143
+ ],
144
+ [
145
+ 'T-2200',
146
+ {
147
+ 'year' => nil,
148
+ 'month' => nil,
149
+ 'date' => nil,
150
+ 'hour' => nil,
151
+ 'minute' => 22,
152
+ 'second' => 00,
153
+ 'timezone' => nil
154
+ }
155
+ ],
156
+ [
157
+ 'T--00',
158
+ {
159
+ 'year' => nil,
160
+ 'month' => nil,
161
+ 'date' => nil,
162
+ 'hour' => nil,
163
+ 'minute' => nil,
164
+ 'second' => 00,
165
+ 'timezone' => nil
166
+ }
167
+ ],
168
+ [
169
+ 'T102200Z',
170
+ {
171
+ 'year' => nil,
172
+ 'month' => nil,
173
+ 'date' => nil,
174
+ 'hour' => 10,
175
+ 'minute' => 22,
176
+ 'second' => 00,
177
+ 'timezone' => 'Z'
178
+ }
179
+ ],
180
+ [
181
+ 'T102200-0800',
182
+ {
183
+ 'year' => nil,
184
+ 'month' => nil,
185
+ 'date' => nil,
186
+ 'hour' => 10,
187
+ 'minute' => 22,
188
+ 'second' => 00,
189
+ 'timezone' => '-0800'
190
+ }
191
+ ],
192
+
193
+ # extended format
194
+ [
195
+ '2012-11-29T15:10:53Z',
196
+ {
197
+ 'year' => 2012,
198
+ 'month' => 11,
199
+ 'date' => 29,
200
+ 'hour' => 15,
201
+ 'minute' => 10,
202
+ 'second' => 53,
203
+ 'timezone' => 'Z'
204
+ }
205
+ ],
206
+
207
+ # with milliseconds
208
+ [
209
+ '20121129T151053.123Z',
210
+ {
211
+ 'year' => 2012,
212
+ 'month' => 11,
213
+ 'date' => 29,
214
+ 'hour' => 15,
215
+ 'minute' => 10,
216
+ 'second' => 53,
217
+ 'timezone' => 'Z'
218
+ }
219
+ ],
220
+
221
+ # extended format with milliseconds
222
+ [
223
+ '2012-11-29T15:10:53.123Z',
224
+ {
225
+ 'year' => 2012,
226
+ 'month' => 11,
227
+ 'date' => 29,
228
+ 'hour' => 15,
229
+ 'minute' => 10,
230
+ 'second' => 53,
231
+ 'timezone' => 'Z'
232
+ }
233
+ ]
234
+ ]
235
+ end
236
+
237
+ def assert_date_and_or_time_equals_to(date, parts)
238
+ expected = {
239
+ 'year' => nil,
240
+ 'month' => nil,
241
+ 'date' => nil,
242
+ 'hour' => nil,
243
+ 'minute' => nil,
244
+ 'second' => nil,
245
+ 'timezone' => nil
246
+ }.merge parts
247
+ assert_equal(expected, Tilia::VObject::DateTimeParser.parse_v_card_date_and_or_time(date))
248
+ end
249
+
250
+ def test_parse_i_calendar_duration
251
+ assert_equal('+1 weeks', Tilia::VObject::DateTimeParser.parse_duration('P1W', true))
252
+ assert_equal('+5 days', Tilia::VObject::DateTimeParser.parse_duration('P5D', true))
253
+ assert_equal('+5 days 3 hours 50 minutes 12 seconds', Tilia::VObject::DateTimeParser.parse_duration('P5DT3H50M12S', true))
254
+ assert_equal('-1 weeks 50 minutes', Tilia::VObject::DateTimeParser.parse_duration('-P1WT50M', true))
255
+ assert_equal('+50 days 3 hours 2 seconds', Tilia::VObject::DateTimeParser.parse_duration('+P50DT3H2S', true))
256
+ assert_equal('+0 seconds', Tilia::VObject::DateTimeParser.parse_duration('+PT0S', true))
257
+ assert_equal(0.seconds, Tilia::VObject::DateTimeParser.parse_duration('PT0S'))
258
+ end
259
+
260
+ def test_parse_i_calendar_duration_date_interval
261
+ expected = 7.days
262
+ assert_equal(expected, Tilia::VObject::DateTimeParser.parse_duration('P1W'))
263
+ assert_equal(expected, Tilia::VObject::DateTimeParser.parse('P1W'))
264
+
265
+ expected = -3.minutes
266
+ assert_equal(expected, Tilia::VObject::DateTimeParser.parse_duration('-PT3M'))
267
+ end
268
+
269
+ def test_parse_i_calendar_duration_fail
270
+ assert_raises(RuntimeError) { Tilia::VObject::DateTimeParser.parse_duration('P1X', true) }
271
+ end
272
+
273
+ def test_parse_i_calendar_date_time
274
+ date_time = Tilia::VObject::DateTimeParser.parse_date_time('20100316T141405')
275
+
276
+ compare = @utc.parse('2010-03-16 14:14:05')
277
+
278
+ assert_equal(compare, date_time)
279
+ end
280
+
281
+ def test_parse_i_calendar_date_time_bad_format
282
+ assert_raises(RuntimeError) { Tilia::VObject::DateTimeParser.parse_date_time('20100316T141405 ') }
283
+ end
284
+
285
+ def test_parse_i_calendar_date_time_utc
286
+ date_time = Tilia::VObject::DateTimeParser.parse_date_time('20100316T141405Z')
287
+
288
+ compare = @utc.parse('2010-03-16 14:14:05')
289
+ assert_equal(compare, date_time)
290
+ end
291
+
292
+ def test_parse_i_calendar_date_time_utc2
293
+ date_time = Tilia::VObject::DateTimeParser.parse_date_time('20101211T160000Z')
294
+
295
+ compare = @utc.parse('2010-12-11 16:00:00')
296
+ assert_equal(compare, date_time)
297
+ end
298
+
299
+ def test_parse_i_calendar_date_time_custom_time_zone
300
+ date_time = Tilia::VObject::DateTimeParser.parse_date_time('20100316T141405', ActiveSupport::TimeZone.new('Europe/Amsterdam'))
301
+
302
+ compare = @utc.parse('2010-03-16 13:14:05')
303
+ assert_equal(compare, date_time)
304
+ end
305
+
306
+ def test_parse_i_calendar_date
307
+ date_time = Tilia::VObject::DateTimeParser.parse_date('20100316')
308
+
309
+ expected = @utc.parse('2010-03-16 00:00:00')
310
+ assert_equal(expected, date_time)
311
+
312
+ date_time = Tilia::VObject::DateTimeParser.parse('20100316')
313
+ assert_equal(expected, date_time)
314
+ end
315
+
316
+ # TCheck if a date with year > 4000 will not throw an exception. iOS seems
317
+ # to use 45001231 in yearly recurring events
318
+ def test_parse_i_calendar_date_greater_than4000
319
+ date_time = Tilia::VObject::DateTimeParser.parse_date('45001231')
320
+
321
+ expected = @utc.parse('4500-12-31 00:00:00')
322
+ assert_equal(expected, date_time)
323
+
324
+ date_time = Tilia::VObject::DateTimeParser.parse('45001231')
325
+ assert_equal(expected, date_time)
326
+ end
327
+
328
+ # Check if a datetime with year > 4000 will not throw an exception. iOS
329
+ # seems to use 45001231T235959 in yearly recurring events
330
+ def test_parse_i_calendar_date_time_greater_than4000
331
+ date_time = Tilia::VObject::DateTimeParser.parse_date_time('45001231T235959')
332
+
333
+ expected = @utc.parse('4500-12-31 23:59:59')
334
+ assert_equal(expected, date_time)
335
+
336
+ date_time = Tilia::VObject::DateTimeParser.parse('45001231T235959')
337
+ assert_equal(expected, date_time)
338
+ end
339
+
340
+ def test_parse_i_calendar_date_bad_format
341
+ assert_raises(RuntimeError) { Tilia::VObject::DateTimeParser.parse_date('20100316T141405') }
342
+ end
343
+
344
+ def test_v_card_date
345
+ vcard_dates.each do |data|
346
+ (input, output) = data
347
+ assert_equal(output, Tilia::VObject::DateTimeParser.parse_v_card_date_time(input))
348
+ end
349
+ end
350
+
351
+ def test_bad_v_card_date
352
+ assert_raises(ArgumentError) { Tilia::VObject::DateTimeParser.parse_v_card_date_time('1985---01') }
353
+ end
354
+
355
+ def test_bad_v_card_time
356
+ assert_raises(ArgumentError) { Tilia::VObject::DateTimeParser.parse_v_card_time('23:12:166') }
357
+ end
358
+
359
+ def test_date_and_or_time_date_with_year_month_day
360
+ assert_date_and_or_time_equals_to(
361
+ '20150128',
362
+ 'year' => '2015',
363
+ 'month' => '01',
364
+ 'date' => '28'
365
+ )
366
+ end
367
+
368
+ def test_date_and_or_time_date_with_year_month
369
+ assert_date_and_or_time_equals_to(
370
+ '2015-01',
371
+ 'year' => '2015',
372
+ 'month' => '01'
373
+ )
374
+ end
375
+
376
+ def test_date_and_or_time_date_with_month
377
+ assert_date_and_or_time_equals_to(
378
+ '--01',
379
+ 'month' => '01'
380
+ )
381
+ end
382
+
383
+ def test_date_and_or_time_date_with_month_day
384
+ assert_date_and_or_time_equals_to(
385
+ '--0128',
386
+ 'month' => '01',
387
+ 'date' => '28'
388
+ )
389
+ end
390
+
391
+ def test_date_and_or_time_date_with_day
392
+ assert_date_and_or_time_equals_to(
393
+ '---28',
394
+ 'date' => '28'
395
+ )
396
+ end
397
+
398
+ def test_date_and_or_time_time_with_hour
399
+ assert_date_and_or_time_equals_to(
400
+ '13',
401
+ 'hour' => '13'
402
+ )
403
+ end
404
+
405
+ def test_date_and_or_time_time_with_hour_minute
406
+ assert_date_and_or_time_equals_to(
407
+ '1353',
408
+ 'hour' => '13',
409
+ 'minute' => '53'
410
+ )
411
+ end
412
+
413
+ def test_date_and_or_time_time_with_hour_second
414
+ assert_date_and_or_time_equals_to(
415
+ '135301',
416
+ 'hour' => '13',
417
+ 'minute' => '53',
418
+ 'second' => '01'
419
+
420
+ )
421
+ end
422
+
423
+ def test_date_and_or_time_time_with_minute
424
+ assert_date_and_or_time_equals_to(
425
+ '-53',
426
+ 'minute' => '53'
427
+ )
428
+ end
429
+
430
+ def test_date_and_or_time_time_with_minute_second
431
+ assert_date_and_or_time_equals_to(
432
+ '-5301',
433
+ 'minute' => '53',
434
+ 'second' => '01'
435
+ )
436
+ end
437
+
438
+ def test_date_and_or_time_time_with_second
439
+ assert(true)
440
+
441
+ # This is unreachable due to a conflict between date and time pattern.
442
+ # This is an error in the specification, not in our implementation.
443
+ end
444
+
445
+ def test_date_and_or_time_time_with_second_z
446
+ assert_date_and_or_time_equals_to(
447
+ '--01Z',
448
+ 'second' => '01',
449
+ 'timezone' => 'Z'
450
+ )
451
+ end
452
+
453
+ def test_date_and_or_time_time_with_second_tz
454
+ assert_date_and_or_time_equals_to(
455
+ '--01+1234',
456
+ 'second' => '01',
457
+ 'timezone' => '+1234'
458
+ )
459
+ end
460
+
461
+ def test_date_and_or_time_date_time_with_year_month_day_hour
462
+ assert_date_and_or_time_equals_to(
463
+ '20150128T13',
464
+ 'year' => '2015',
465
+ 'month' => '01',
466
+ 'date' => '28',
467
+ 'hour' => '13'
468
+ )
469
+ end
470
+
471
+ def test_date_and_or_time_date_time_with_month_day_hour
472
+ assert_date_and_or_time_equals_to(
473
+ '--0128T13',
474
+ 'month' => '01',
475
+ 'date' => '28',
476
+ 'hour' => '13'
477
+ )
478
+ end
479
+
480
+ def test_date_and_or_time_date_time_with_day_hour
481
+ assert_date_and_or_time_equals_to(
482
+ '---28T13',
483
+ 'date' => '28',
484
+ 'hour' => '13'
485
+ )
486
+ end
487
+
488
+ def test_date_and_or_time_date_time_with_day_hour_minute
489
+ assert_date_and_or_time_equals_to(
490
+ '---28T1353',
491
+ 'date' => '28',
492
+ 'hour' => '13',
493
+ 'minute' => '53'
494
+ )
495
+ end
496
+
497
+ def test_date_and_or_time_date_time_with_day_hour_minute_second
498
+ assert_date_and_or_time_equals_to(
499
+ '---28T135301',
500
+ 'date' => '28',
501
+ 'hour' => '13',
502
+ 'minute' => '53',
503
+ 'second' => '01'
504
+ )
505
+ end
506
+
507
+ def test_date_and_or_time_date_time_with_day_hour_z
508
+ assert_date_and_or_time_equals_to(
509
+ '---28T13Z',
510
+ 'date' => '28',
511
+ 'hour' => '13',
512
+ 'timezone' => 'Z'
513
+ )
514
+ end
515
+
516
+ def test_date_and_or_time_date_time_with_day_hour_tz
517
+ assert_date_and_or_time_equals_to(
518
+ '---28T13+1234',
519
+ 'date' => '28',
520
+ 'hour' => '13',
521
+ 'timezone' => '+1234'
522
+ )
523
+ end
524
+ end
525
+ end
526
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+ require 'v_object/mock_document'
3
+
4
+ module Tilia
5
+ module VObject
6
+ class DocumentTest < Minitest::Test
7
+ def test_get_document_type
8
+ doc = Tilia::VObject::MockDocument.new
9
+ assert_equal(Tilia::VObject::Document::UNKNOWN, doc.document_type)
10
+ end
11
+
12
+ def test_construct
13
+ doc = Tilia::VObject::MockDocument.new('VLIST')
14
+ assert_equal('VLIST', doc.name)
15
+ end
16
+
17
+ def test_create_component
18
+ vcal = Tilia::VObject::Component::VCalendar.new({}, false)
19
+
20
+ event = vcal.create_component('VEVENT')
21
+
22
+ assert_kind_of(Tilia::VObject::Component::VEvent, event)
23
+ vcal.add(event)
24
+
25
+ prop = vcal.create_property('X-PROP', '1234256', 'X-PARAM' => '3')
26
+ assert_kind_of(Tilia::VObject::Property, prop)
27
+
28
+ event.add(prop)
29
+
30
+ event.delete('DTSTAMP')
31
+ event.delete('UID')
32
+
33
+ out = vcal.serialize
34
+ assert_equal("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nX-PROP;X-PARAM=3:1234256\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", out)
35
+ end
36
+
37
+ def test_create
38
+ vcal = Tilia::VObject::Component::VCalendar.new({}, false)
39
+
40
+ event = vcal.create('VEVENT')
41
+ assert_kind_of(Tilia::VObject::Component::VEvent, event)
42
+
43
+ prop = vcal.create('CALSCALE')
44
+ assert_kind_of(Tilia::VObject::Property::Text, prop)
45
+ end
46
+
47
+ def test_get_class_name_for_property_value
48
+ vcal = Tilia::VObject::Component::VCalendar.new({}, false)
49
+ assert_equal(Tilia::VObject::Property::Text, vcal.class_name_for_property_value('TEXT'))
50
+ assert_nil(vcal.class_name_for_property_value('FOO'))
51
+ end
52
+
53
+ def test_destroy
54
+ vcal = Tilia::VObject::Component::VCalendar.new({}, false)
55
+ event = vcal.create_component('VEVENT')
56
+
57
+ assert_kind_of(Tilia::VObject::Component::VEvent, event)
58
+ vcal.add(event)
59
+
60
+ prop = vcal.create_property('X-PROP', '1234256', 'X-PARAM' => '3')
61
+
62
+ event.add(prop)
63
+ assert_equal(event, prop.parent)
64
+
65
+ # TODO: destroy object?!
66
+ # vcal.destroy
67
+ # assert_nil(prop.parent)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class ElementListTest < Minitest::Test
6
+ def test_iterate
7
+ cal = Tilia::VObject::Component::VCalendar.new
8
+ sub = cal.create_component('VEVENT')
9
+
10
+ elems = [sub, sub.clone, sub.clone]
11
+
12
+ elem_list = Tilia::VObject::ElementList.new(elems)
13
+
14
+ count = 0
15
+ key = nil
16
+ elem_list.each_with_index do |subcomponent, i|
17
+ count += 1
18
+ key = i
19
+ assert_kind_of(Tilia::VObject::Component, subcomponent)
20
+ end
21
+
22
+ assert_equal(3, count)
23
+ assert_equal(2, key)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class EmClientTest < Minitest::Test
6
+ def test_parse_tz
7
+ str = <<VCF
8
+ BEGIN:VCALENDAR
9
+ X-WR-CALNAME:Blackhawks Schedule 2011-12
10
+ X-APPLE-CALENDAR-COLOR:#E51717
11
+ X-WR-TIMEZONE:America/Chicago
12
+ CALSCALE:GREGORIAN
13
+ PRODID:-//eM Client/4.0.13961.0
14
+ VERSION:2.0
15
+ BEGIN:VTIMEZONE
16
+ TZID:America/Chicago
17
+ BEGIN:DAYLIGHT
18
+ TZOFFSETFROM:-0600
19
+ RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
20
+ DTSTART:20070311T020000
21
+ TZNAME:CDT
22
+ TZOFFSETTO:-0500
23
+ END:DAYLIGHT
24
+ BEGIN:STANDARD
25
+ TZOFFSETFROM:-0500
26
+ RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
27
+ DTSTART:20071104T020000
28
+ TZNAME:CST
29
+ TZOFFSETTO:-0600
30
+ END:STANDARD
31
+ END:VTIMEZONE
32
+ BEGIN:VEVENT
33
+ CREATED:20110624T181236Z
34
+ UID:be3bbfff-96e8-4c66-9908-ab791a62231d
35
+ DTEND;TZID="America/Chicago":20111008T223000
36
+ TRANSP:OPAQUE
37
+ SUMMARY:Stars @ Blackhawks (Home Opener)
38
+ DTSTART;TZID="America/Chicago":20111008T193000
39
+ DTSTAMP:20120330T013232Z
40
+ SEQUENCE:2
41
+ X-MICROSOFT-CDO-BUSYSTATUS:BUSY
42
+ LAST-MODIFIED:20120330T013237Z
43
+ CLASS:PUBLIC
44
+ END:VEVENT
45
+ END:VCALENDAR
46
+ VCF
47
+ v_object = Tilia::VObject::Reader.read(str)
48
+ dt = v_object['VEVENT']['DTSTART'].date_time
49
+ assert_equal(ActiveSupport::TimeZone.new('America/Chicago').parse('2011-10-08 19:30:00'), dt)
50
+ end
51
+ end
52
+ end
53
+ end