rubyredrick-ri_cal 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +122 -0
  3. data/README.txt +271 -0
  4. data/Rakefile +31 -0
  5. data/bin/ri_cal +8 -0
  6. data/component_attributes/alarm.yml +10 -0
  7. data/component_attributes/calendar.yml +4 -0
  8. data/component_attributes/component_property_defs.yml +180 -0
  9. data/component_attributes/event.yml +45 -0
  10. data/component_attributes/freebusy.yml +16 -0
  11. data/component_attributes/journal.yml +35 -0
  12. data/component_attributes/timezone.yml +3 -0
  13. data/component_attributes/timezone_period.yml +11 -0
  14. data/component_attributes/todo.yml +46 -0
  15. data/copyrights.txt +2 -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/lib/ri_cal/component/alarm.rb +22 -0
  21. data/lib/ri_cal/component/calendar.rb +199 -0
  22. data/lib/ri_cal/component/event.rb +30 -0
  23. data/lib/ri_cal/component/freebusy.rb +19 -0
  24. data/lib/ri_cal/component/journal.rb +22 -0
  25. data/lib/ri_cal/component/t_z_info_timezone.rb +124 -0
  26. data/lib/ri_cal/component/timezone/daylight_period.rb +26 -0
  27. data/lib/ri_cal/component/timezone/standard_period.rb +24 -0
  28. data/lib/ri_cal/component/timezone/timezone_period.rb +54 -0
  29. data/lib/ri_cal/component/timezone.rb +193 -0
  30. data/lib/ri_cal/component/todo.rb +26 -0
  31. data/lib/ri_cal/component.rb +224 -0
  32. data/lib/ri_cal/core_extensions/array/conversions.rb +15 -0
  33. data/lib/ri_cal/core_extensions/array.rb +7 -0
  34. data/lib/ri_cal/core_extensions/date/conversions.rb +27 -0
  35. data/lib/ri_cal/core_extensions/date.rb +13 -0
  36. data/lib/ri_cal/core_extensions/date_time/conversions.rb +27 -0
  37. data/lib/ri_cal/core_extensions/date_time.rb +13 -0
  38. data/lib/ri_cal/core_extensions/object/conversions.rb +20 -0
  39. data/lib/ri_cal/core_extensions/object.rb +8 -0
  40. data/lib/ri_cal/core_extensions/string/conversions.rb +32 -0
  41. data/lib/ri_cal/core_extensions/string.rb +8 -0
  42. data/lib/ri_cal/core_extensions/time/calculations.rb +153 -0
  43. data/lib/ri_cal/core_extensions/time/conversions.rb +27 -0
  44. data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +88 -0
  45. data/lib/ri_cal/core_extensions/time.rb +11 -0
  46. data/lib/ri_cal/core_extensions.rb +6 -0
  47. data/lib/ri_cal/invalid_timezone_identifer.rb +20 -0
  48. data/lib/ri_cal/occurrence_enumerator.rb +172 -0
  49. data/lib/ri_cal/parser.rb +138 -0
  50. data/lib/ri_cal/properties/alarm.rb +390 -0
  51. data/lib/ri_cal/properties/calendar.rb +164 -0
  52. data/lib/ri_cal/properties/event.rb +1526 -0
  53. data/lib/ri_cal/properties/freebusy.rb +594 -0
  54. data/lib/ri_cal/properties/journal.rb +1240 -0
  55. data/lib/ri_cal/properties/timezone.rb +151 -0
  56. data/lib/ri_cal/properties/timezone_period.rb +416 -0
  57. data/lib/ri_cal/properties/todo.rb +1562 -0
  58. data/lib/ri_cal/property_value/array.rb +19 -0
  59. data/lib/ri_cal/property_value/cal_address.rb +12 -0
  60. data/lib/ri_cal/property_value/date.rb +119 -0
  61. data/lib/ri_cal/property_value/date_time/additive_methods.rb +43 -0
  62. data/lib/ri_cal/property_value/date_time/time_machine.rb +180 -0
  63. data/lib/ri_cal/property_value/date_time/timezone_support.rb +65 -0
  64. data/lib/ri_cal/property_value/date_time.rb +324 -0
  65. data/lib/ri_cal/property_value/duration.rb +106 -0
  66. data/lib/ri_cal/property_value/geo.rb +12 -0
  67. data/lib/ri_cal/property_value/integer.rb +13 -0
  68. data/lib/ri_cal/property_value/occurrence_list.rb +82 -0
  69. data/lib/ri_cal/property_value/period.rb +63 -0
  70. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +98 -0
  71. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +77 -0
  72. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +149 -0
  73. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +54 -0
  74. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +32 -0
  75. data/lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb +794 -0
  76. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +132 -0
  77. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +61 -0
  78. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +34 -0
  79. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +50 -0
  80. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +126 -0
  81. data/lib/ri_cal/property_value/recurrence_rule.rb +146 -0
  82. data/lib/ri_cal/property_value/text.rb +41 -0
  83. data/lib/ri_cal/property_value/uri.rb +12 -0
  84. data/lib/ri_cal/property_value/utc_offset.rb +34 -0
  85. data/lib/ri_cal/property_value.rb +110 -0
  86. data/lib/ri_cal/required_timezones.rb +56 -0
  87. data/lib/ri_cal/time_with_floating_timezone.rb +59 -0
  88. data/lib/ri_cal.rb +134 -0
  89. data/ri_cal.gemspec +47 -0
  90. data/sample_ical_files/from_ical_dot_app/test1.ics +38 -0
  91. data/script/console +10 -0
  92. data/script/destroy +14 -0
  93. data/script/generate +14 -0
  94. data/script/txt2html +71 -0
  95. data/spec/ri_cal/component/alarm_spec.rb +13 -0
  96. data/spec/ri_cal/component/calendar_spec.rb +55 -0
  97. data/spec/ri_cal/component/event_spec.rb +157 -0
  98. data/spec/ri_cal/component/freebusy_spec.rb +13 -0
  99. data/spec/ri_cal/component/journal_spec.rb +13 -0
  100. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +37 -0
  101. data/spec/ri_cal/component/timezone_spec.rb +155 -0
  102. data/spec/ri_cal/component/todo_spec.rb +61 -0
  103. data/spec/ri_cal/component_spec.rb +212 -0
  104. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +189 -0
  105. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +46 -0
  106. data/spec/ri_cal/occurrence_enumerator_spec.rb +218 -0
  107. data/spec/ri_cal/parser_spec.rb +304 -0
  108. data/spec/ri_cal/property_value/date_spec.rb +22 -0
  109. data/spec/ri_cal/property_value/date_time_spec.rb +448 -0
  110. data/spec/ri_cal/property_value/duration_spec.rb +80 -0
  111. data/spec/ri_cal/property_value/period_spec.rb +50 -0
  112. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +22 -0
  113. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1815 -0
  114. data/spec/ri_cal/property_value/text_spec.rb +14 -0
  115. data/spec/ri_cal/property_value/utc_offset_spec.rb +49 -0
  116. data/spec/ri_cal/property_value_spec.rb +111 -0
  117. data/spec/ri_cal/required_timezones_spec.rb +68 -0
  118. data/spec/ri_cal_spec.rb +54 -0
  119. data/spec/spec.opts +4 -0
  120. data/spec/spec_helper.rb +24 -0
  121. data/tasks/ri_cal.rake +403 -0
  122. data/tasks/spec.rake +35 -0
  123. metadata +201 -0
@@ -0,0 +1,448 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
+ require 'tzinfo'
6
+
7
+ describe RiCal::PropertyValue::DateTime do
8
+ before(:each) do
9
+ @cal = RiCal.Calendar
10
+ end
11
+
12
+ def utc_datetime(string)
13
+ RiCal::PropertyValue::DateTime.new(@cal, :value => "#{string}Z")
14
+ end
15
+
16
+ def local_datetime(string, tzid = "America/New_York")
17
+ RiCal::PropertyValue::DateTime.new(@cal, :value => string, :params => {'TZID' => tzid})
18
+ end
19
+
20
+ context "time_with_zone_methods" do
21
+ context ".utc" do
22
+ context "for a datetime already in zulu time" do
23
+ before(:each) do
24
+ @it = utc_datetime("19970101T012300").utc
25
+ end
26
+
27
+ it "should return the same datetime" do
28
+ @it.should == utc_datetime("19970101T012300")
29
+ end
30
+
31
+ it "should return a result with a tzid of UTC" do
32
+ @it.utc.tzid.should == "UTC"
33
+ end
34
+ end
35
+
36
+ it "should raise an invalid timezone exception if the timezone of the receiver is unknown" do
37
+ lambda {local_datetime("19970101T012300", 'America/Caspian').utc}.should raise_error(RiCal::InvalidTimezoneIdentifier)
38
+ end
39
+
40
+ context "for a datetime with a tzid of America/New_York" do
41
+ before(:each) do
42
+ @it = local_datetime("19970101T012300").utc
43
+ end
44
+
45
+ it "should return the equivalent utc time" do
46
+ @it.should == utc_datetime("19970101T062300")
47
+ end
48
+
49
+ it "should return a result with a tzid of UTC" do
50
+ @it.tzid.should == "UTC"
51
+ end
52
+ end
53
+
54
+ context ".in_timezone('America/New_York')" do
55
+
56
+ it "should raise an invalid timezone exception if the timezone of the receiver is unknown" do
57
+ lambda {local_datetime("19970101T012300", 'America/Caspian').in_time_zone('America/New_York')}.should raise_error(RiCal::InvalidTimezoneIdentifier)
58
+ end
59
+
60
+ context "for a datetime 19970101T012300 in zulu time" do
61
+ before(:each) do
62
+ @it = utc_datetime("19970101T012300").in_time_zone('America/New_York')
63
+ end
64
+
65
+ it "should return the 8:23 p. Dec 31, 1996" do
66
+ @it.should == local_datetime("19961231T202300")
67
+ end
68
+
69
+ it "should return a result with a tzid of UTC" do
70
+ @it.tzid.should == "America/New_York"
71
+ end
72
+ end
73
+
74
+ context "for a datetime 19970101T012300 with a tzid of America/New_York" do
75
+ before(:each) do
76
+ @it = local_datetime("19970101T012300").in_time_zone('America/New_York')
77
+ end
78
+
79
+ it "should return the same time" do
80
+ @it.should == local_datetime("19970101T012300")
81
+ end
82
+
83
+ it "should return a result with a tzid of UTC" do
84
+ @it.tzid.should == "America/New_York"
85
+ end
86
+ end
87
+
88
+ context "for a datetime 19970101T012300 with a tzid of America/Chicago" do
89
+ before(:each) do
90
+ @it = local_datetime("19970101T012300", "America/Chicago").in_time_zone('America/New_York')
91
+ end
92
+
93
+ it "should return Jan 1, 1997 02:23 a.m." do
94
+ @it.should == local_datetime("19970101T022300")
95
+ end
96
+
97
+ it "should return a result with a tzid of America/New_York" do
98
+ @it.tzid.should == "America/New_York"
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ context "for a datetime from an imported calendar" do
105
+
106
+ before(:each) do
107
+ cals = RiCal.parse_string <<-END_OF_DATA
108
+ BEGIN:VCALENDAR
109
+ METHOD:PUBLISH
110
+ X-WR-TIMEZONE:America/New_York
111
+ PRODID:-//Apple Inc.//iCal 3.0//EN
112
+ CALSCALE:GREGORIAN
113
+ X-WR-CALNAME:Test
114
+ VERSION:2.0
115
+ X-WR-RELCALID:58DB0663-196B-4B6B-A05A-A53049661280
116
+ X-APPLE-CALENDAR-COLOR:#0252D4
117
+ BEGIN:VTIMEZONE
118
+ TZID:Europe/Paris
119
+ BEGIN:DAYLIGHT
120
+ TZOFFSETFROM:+0100
121
+ TZOFFSETTO:+0200
122
+ DTSTART:19810329T020000
123
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
124
+ TZNAME:CEST
125
+ END:DAYLIGHT
126
+ BEGIN:STANDARD
127
+ TZOFFSETFROM:+0200
128
+ TZOFFSETTO:+0100
129
+ DTSTART:19961027T030000
130
+ RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
131
+ TZNAME:CET
132
+ END:STANDARD
133
+ END:VTIMEZONE
134
+ BEGIN:VTIMEZONE
135
+ TZID:US/Eastern
136
+ BEGIN:DAYLIGHT
137
+ TZOFFSETFROM:-0500
138
+ TZOFFSETTO:-0400
139
+ DTSTART:20070311T020000
140
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
141
+ TZNAME:EDT
142
+ END:DAYLIGHT
143
+ BEGIN:STANDARD
144
+ TZOFFSETFROM:-0400
145
+ TZOFFSETTO:-0500
146
+ DTSTART:20071104T020000
147
+ RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
148
+ TZNAME:EST
149
+ END:STANDARD
150
+ END:VTIMEZONE
151
+ BEGIN:VEVENT
152
+ SEQUENCE:3
153
+ TRANSP:OPAQUE
154
+ UID:AC2EFB19-A8A8-49EF-929F-CA0975374ED6
155
+ DTSTART:20090501T000000Z
156
+ DTSTAMP:20090501T174405Z
157
+ SUMMARY:UTC Event
158
+ CREATED:20090501T174347Z
159
+ DTEND:20090501T010000Z
160
+ END:VEVENT
161
+ BEGIN:VEVENT
162
+ SEQUENCE:2
163
+ TRANSP:OPAQUE
164
+ UID:A5517A09-C53E-4E1F-A642-EA47680BF2B6
165
+ DTSTART;TZID=US/Eastern:20090430T140000
166
+ DTSTAMP:20090501T174428Z
167
+ SUMMARY:Eastern Event
168
+ CREATED:20090501T174415Z
169
+ DTEND;TZID=US/Eastern:20090430T150000
170
+ END:VEVENT
171
+ BEGIN:VEVENT
172
+ SEQUENCE:3
173
+ TRANSP:OPAQUE
174
+ UID:B5024763-9197-4A60-A96E-D8D59D578BB2
175
+ DTSTART;TZID=Europe/Paris:20090430T140000
176
+ DTSTAMP:20090501T174509Z
177
+ SUMMARY:Paris Event
178
+ CREATED:20090501T174439Z
179
+ DTEND;TZID=Europe/Paris:20090430T150000
180
+ END:VEVENT
181
+ END:VCALENDAR
182
+ END_OF_DATA
183
+ @cal = cals.first
184
+ end
185
+
186
+ def find_event(summary)
187
+ @cal.events.find {|event| event.summary == summary}
188
+ end
189
+
190
+ context ".utc" do
191
+
192
+ it "should raise an invalid timezone exception if the timezone of the receiver is not in the calendar" do
193
+ lambda {local_datetime("19970101T012300", 'America/New_York').utc}.should raise_error(RiCal::InvalidTimezoneIdentifier)
194
+ end
195
+
196
+ context "for the DTSTART of the UTC Event" do
197
+ before(:each) do
198
+ @it = find_event("UTC Event").dtstart_property.utc
199
+ end
200
+
201
+ it "should return the same datetime" do
202
+ @it.should == utc_datetime("20090501T000000")
203
+ end
204
+
205
+ it "should return a result with a tzid of UTC" do
206
+ @it.utc.tzid.should == "UTC"
207
+ end
208
+ end
209
+
210
+ context "for the DTSTART of the Eastern Event" do
211
+ before(:each) do
212
+ @it = find_event("Eastern Event").dtstart_property.utc
213
+ end
214
+
215
+ it "should return the equivalent utc time" do
216
+ @it.should == utc_datetime("20090430T180000")
217
+ end
218
+
219
+ it "should return a result with a tzid of UTC" do
220
+ @it.tzid.should == "UTC"
221
+ end
222
+ end
223
+ end
224
+
225
+ context ".in_timezone('US/Eastern')" do
226
+
227
+ it "should raise an invalid timezone exception if the timezone of the receiver is not in the calendar" do
228
+ lambda {local_datetime("19970101T012300", 'America/New_York').in_time_zone("US/Eastern")}.should raise_error(RiCal::InvalidTimezoneIdentifier)
229
+ end
230
+
231
+ context "for the DTSTART of the UTC Event" do
232
+ before(:each) do
233
+ @it = find_event("UTC Event").dtstart_property.in_time_zone("US/Eastern")
234
+ end
235
+
236
+ it "should return 8:00 p.m. Apr 30, 2009" do
237
+ @it.should == local_datetime("20090430T2000000", "US/Eastern")
238
+ end
239
+
240
+ it "should return a result with a tzid of US/Eastern" do
241
+ @it.tzid.should == "US/Eastern"
242
+ end
243
+ end
244
+
245
+ context "for the DTSTART of the Eastern Event" do
246
+ before(:each) do
247
+ @it = find_event("Eastern Event").dtstart_property.in_time_zone("US/Eastern")
248
+ end
249
+
250
+ it "should return the same time" do
251
+ @it.should == local_datetime("20090430T140000", "US/Eastern")
252
+ end
253
+
254
+ it "should return a result with a tzid of UTC" do
255
+ @it.tzid.should == "US/Eastern"
256
+ end
257
+ end
258
+
259
+ context "for the DTSTART of the Paris Event" do
260
+ before(:each) do
261
+ @it = find_event("Paris Event").dtstart_property.in_time_zone("US/Eastern")
262
+ end
263
+
264
+ it "should return 8:00 a.m. on Apr 30, 2009" do
265
+ @it.should == local_datetime("20090430T080000", "US/Eastern")
266
+ end
267
+
268
+ it "should return a result with a tzid of UTC" do
269
+ @it.tzid.should == "US/Eastern"
270
+ end
271
+ end
272
+ end
273
+ end
274
+ end
275
+
276
+ context ".from_separated_line" do
277
+ it "should return a RiCal::PropertyValue::Date if the value doesn't contain a time specification" do
278
+ RiCal::PropertyValue::DateTime.or_date(nil, :value => "19970714").should be_kind_of(RiCal::PropertyValue::Date)
279
+ end
280
+
281
+ it "should return a RiCal::PropertyValue::DateTime if the value does contain a time specification" do
282
+ RiCal::PropertyValue::DateTime.or_date(nil, :value => "19980118T230000").should be_kind_of(RiCal::PropertyValue::DateTime)
283
+ end
284
+ end
285
+
286
+ context ".advance" do
287
+ it "should advance by one week if passed :days => 7" do
288
+ dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "20050131T230000")
289
+ dt2 = RiCal::PropertyValue::DateTime.new(nil, :value => "20050207T230000")
290
+ dt1.advance(:days => 7).should == dt2
291
+ end
292
+ end
293
+
294
+ context "subtracting one date-time from another" do
295
+
296
+ it "should produce the right RiCal::PropertyValue::Duration" do
297
+ dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T230000")
298
+ dt2 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980119T010000")
299
+ @it = dt2 - dt1
300
+ @it.should == RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
301
+ end
302
+ end
303
+
304
+ context "adding a RiCal::PropertyValue::Duration to a RiCal::PropertyValue::DateTime" do
305
+
306
+ it "should produce the right RiCal::PropertyValue::DateTime" do
307
+ dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T230000")
308
+ duration = RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
309
+ @it = dt1 + duration
310
+ @it.should == RiCal::PropertyValue::DateTime.new(nil, :value => "19980119T010000")
311
+ end
312
+ end
313
+
314
+ context "subtracting a RiCal::PropertyValue::Duration from a RiCal::PropertyValue::DateTime" do
315
+
316
+ it "should produce the right RiCal::PropertyValue::DateTime" do
317
+ dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980119T010000")
318
+ duration = RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
319
+ @it = dt1 - duration
320
+ @it.should == RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T230000")
321
+ end
322
+ end
323
+
324
+ context ".convert(rubyobject)" do
325
+ describe "for a Time instance of Feb 05 19:17:11"
326
+ before(:each) do
327
+ @time = Time.mktime(2009,2,5,19,17,11)
328
+ end
329
+
330
+ context "with a normal a normal time instance" do
331
+ describe "when the default timezone identifier is UTC" do
332
+ before(:each) do
333
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
334
+ end
335
+
336
+ it "should have a TZID of UTC" do
337
+ @it.tzid.should == 'UTC'
338
+ end
339
+
340
+ it "should have the right value" do
341
+ @it.value.should == "20090205T191711Z"
342
+ end
343
+ end
344
+ context "when the default timezone has been set to 'America/Chicago" do
345
+ before(:each) do
346
+ RiCal::PropertyValue::DateTime.stub!(:default_tzid).and_return("America/Chicago")
347
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
348
+ end
349
+
350
+ it "should have a TZID of America/Chicago" do
351
+ @it.tzid.should == 'America/Chicago'
352
+ end
353
+
354
+ it "should have the right value" do
355
+ @it.value.should == "20090205T191711"
356
+ end
357
+ end
358
+ end
359
+
360
+ context "with an activesupport like extended time instance with time_zone returning a TZInfo::TimeZone" do
361
+ before(:each) do
362
+ @time.stub!(:"acts_like_time?").and_return(true)
363
+ @time.stub!(:time_zone).and_return(mock("TZINFO_TIMEZONE", :identifier => "America/New_York"))
364
+ end
365
+
366
+ context "when the default timezone identifier is UTC" do
367
+ before(:each) do
368
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
369
+ end
370
+
371
+ it "should have the correct parameters" do
372
+ @it.params.should == {'TZID' => 'America/New_York'}
373
+ end
374
+
375
+ it "should have a TZID of America/New_York" do
376
+ @it.tzid.should == 'America/New_York'
377
+ end
378
+
379
+ it "should have the right value" do
380
+ @it.value.should == "20090205T191711"
381
+ end
382
+ end
383
+ context "when the default timezone has been set to 'America/Chicago" do
384
+ before(:each) do
385
+ RiCal::PropertyValue::DateTime.stub!(:default_tzid).and_return("America/Chicago")
386
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
387
+ end
388
+
389
+ it "should have the correct parameters" do
390
+ @it.params.should == {'TZID' => 'America/New_York'}
391
+ end
392
+
393
+ it "should have a TZID of America/New_York" do
394
+ @it.tzid.should == 'America/New_York'
395
+ end
396
+
397
+ it "should have the right value" do
398
+ @it.value.should == "20090205T191711"
399
+ end
400
+ end
401
+ end
402
+
403
+ context "with an activesupport like extended time instance with time_zone returning an ActiveSupport::TimeZone" do
404
+ before(:each) do
405
+ @time.stub!(:"acts_like_time?").and_return(true)
406
+ @tzinfo_timezone = mock("TZInfo_TimeZone", :identifier => "America/New_York")
407
+ @active_support_timezone = mock("ActiveSupport::TimeZone", :identifier => "America/New_York", :tzinfo => @tzinfo_timezone )
408
+ @time.stub!(:time_zone).and_return(@active_support_timezone)
409
+ end
410
+
411
+ context "when the default timezone identifier is UTC" do
412
+ before(:each) do
413
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
414
+ end
415
+
416
+ it "should have the correct parameters" do
417
+ @it.params.should == {'TZID' => 'America/New_York'}
418
+ end
419
+
420
+ it "should have a TZID of America/New_York" do
421
+ @it.tzid.should == 'America/New_York'
422
+ end
423
+
424
+ it "should have the right value" do
425
+ @it.value.should == "20090205T191711"
426
+ end
427
+ end
428
+ context "when the default timezone has been set to 'America/Chicago" do
429
+ before(:each) do
430
+ RiCal::PropertyValue::DateTime.stub!(:default_tzid).and_return("America/Chicago")
431
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
432
+ end
433
+
434
+ it "should have the correct parameters" do
435
+ @it.params.should == {'TZID' => 'America/New_York'}
436
+ end
437
+
438
+ it "should have a TZID of America/New_York" do
439
+ @it.tzid.should == 'America/New_York'
440
+ end
441
+
442
+ it "should have the right value" do
443
+ @it.value.should == "20090205T191711"
444
+ end
445
+ end
446
+ end
447
+ end
448
+ end
@@ -0,0 +1,80 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
+ require 'date'
6
+
7
+ describe RiCal::PropertyValue::Duration do
8
+
9
+ describe "with various values" do
10
+ def value_expectations(dv, values = {})
11
+ values = {:weeks => 0, :days => 0, :hours => 0, :minutes => 0, :seconds => 0}.merge(values)
12
+ dv.weeks.should == values[:weeks]
13
+ dv.days.should == values[:days]
14
+ dv.hours.should == values[:hours]
15
+ dv.minutes.should == values[:minutes]
16
+ dv.seconds.should == values[:seconds]
17
+ end
18
+
19
+ it ".+P7W should have represent 7 weeks" do
20
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+P7W"), :weeks => 7)
21
+ end
22
+
23
+ it ".P15DT5H0M20S should have represent 15 days, 5 hours and 20 seconds" do
24
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "P15DT5H0M20S"), :days => 15, :hours => 5, :seconds => 20)
25
+ end
26
+
27
+ it ".+P2D should have represent 2 days" do
28
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+P2D"), :days => 2)
29
+ end
30
+
31
+ it ".+PT3H should have represent 3 hours" do
32
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT3H"), :hours => 3)
33
+ end
34
+
35
+ it ".+PT15M should have represent 15 minutes" do
36
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT15M"), :minutes => 15)
37
+ end
38
+
39
+ it ".+PT45S should have represent 45 seconds" do
40
+ value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT45S"), :seconds => 45)
41
+ end
42
+ end
43
+
44
+ describe ".from_datetimes" do
45
+
46
+ describe "starting at 11:00 pm, and ending at 1:01:02 am the next day" do
47
+ before(:each) do
48
+ @it = RiCal::PropertyValue::Duration.from_datetimes(nil,
49
+ DateTime.parse("Sep 1, 2008 23:00"),
50
+ DateTime.parse("Sep 2, 2008 1:01:02")
51
+ )
52
+ end
53
+
54
+ it "should produce a duration" do
55
+ @it.class.should == RiCal::PropertyValue::Duration
56
+ end
57
+
58
+ it "should have a value of '+P2H1M2S'" do
59
+ @it.value.should == '+PT2H1M2S'
60
+ end
61
+
62
+ it "should contain zero days" do
63
+ @it.days.should == 0
64
+ end
65
+
66
+ it "should contain two hours" do
67
+ @it.hours.should == 2
68
+ end
69
+
70
+ it "should contain one minute" do
71
+ @it.minutes.should == 1
72
+ end
73
+
74
+ it "should contain one minute" do
75
+ @it.minutes.should == 1
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,50 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
+
6
+ # RFC 2445 Section 4.3.9 pp 39-40
7
+ describe RiCal::PropertyValue::Period do
8
+
9
+ before(:each) do
10
+ @start_dt = RiCal::PropertyValue::DateTime.new(nil, :value => "19970101T180000Z")
11
+ @end_dt = RiCal::PropertyValue::DateTime.new(nil, :value => "19970102T070000Z")
12
+ @duration = RiCal::PropertyValue::Duration.from_datetimes(nil, @start_dt.to_datetime, @end_dt.to_datetime)
13
+ end
14
+
15
+ describe "with an explicit period" do
16
+ before(:each) do
17
+ @it = RiCal::PropertyValue::Period.new(nil, :value => "#{@start_dt.value}/#{@end_dt.value}")
18
+ end
19
+
20
+ it "should have the correct dtstart value" do
21
+ @it.dtstart.should == @start_dt
22
+ end
23
+
24
+ it "should have the correct dtend value" do
25
+ @it.dtend.should == @end_dt
26
+ end
27
+
28
+ it "should have the correct duration value" do
29
+ @it.duration.should == @duration
30
+ end
31
+ end
32
+
33
+ describe "with a start time and period" do
34
+ before(:each) do
35
+ @it = RiCal::PropertyValue::Period.new(nil, :value => "#{@start_dt.value}/#{@duration.value}")
36
+ end
37
+
38
+ it "should have the correct dtstart value" do
39
+ @it.dtstart.should == @start_dt
40
+ end
41
+
42
+ it "should have the correct dtend value" do
43
+ @it.dtend.should == @end_dt
44
+ end
45
+
46
+ it "should have the correct duration value" do
47
+ @it.duration.should == @duration
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. .. spec_helper])
5
+
6
+ describe RiCal::PropertyValue::RecurrenceRule::RecurringYearDay do
7
+
8
+ def set_it(which, rule=nil)
9
+ @it = RiCal::PropertyValue::RecurrenceRule::RecurringYearDay.new(which, rule)
10
+ end
11
+
12
+ def time_property(str)
13
+ RiCal::PropertyValue.date_or_date_time(nil, :value => str)
14
+ end
15
+
16
+ describe ".matches_for(time)" do
17
+
18
+ it "should return an array containing January 1, in the times year for the the 1st day" do
19
+ set_it(1).matches_for(time_property("19970603T090000")).should == [time_property("19970101T090000")]
20
+ end
21
+ end
22
+ end