rubyredrick-ri_cal 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/History.txt +19 -2
  2. data/Manifest.txt +6 -3
  3. data/README.txt +130 -44
  4. data/Rakefile +1 -1
  5. data/copyrights.txt +1 -2
  6. data/lib/ri_cal/component/alarm.rb +1 -2
  7. data/lib/ri_cal/component/calendar.rb +25 -9
  8. data/lib/ri_cal/component/event.rb +1 -2
  9. data/lib/ri_cal/component/freebusy.rb +1 -2
  10. data/lib/ri_cal/component/journal.rb +1 -2
  11. data/lib/ri_cal/component/t_z_info_timezone.rb +1 -2
  12. data/lib/ri_cal/component/timezone/daylight_period.rb +1 -2
  13. data/lib/ri_cal/component/timezone/standard_period.rb +1 -2
  14. data/lib/ri_cal/component/timezone/timezone_period.rb +1 -2
  15. data/lib/ri_cal/component/timezone.rb +5 -2
  16. data/lib/ri_cal/component.rb +22 -7
  17. data/lib/ri_cal/core_extensions/date/conversions.rb +8 -7
  18. data/lib/ri_cal/core_extensions/date_time.rb +4 -2
  19. data/lib/ri_cal/core_extensions/object/conversions.rb +1 -1
  20. data/lib/ri_cal/core_extensions/string/conversions.rb +37 -6
  21. data/lib/ri_cal/core_extensions/time/conversions.rb +11 -7
  22. data/lib/ri_cal/core_extensions/time/tzid_access.rb +37 -0
  23. data/lib/ri_cal/core_extensions/time.rb +3 -1
  24. data/lib/ri_cal/floating_timezone.rb +32 -0
  25. data/lib/ri_cal/invalid_property_value.rb +8 -0
  26. data/lib/ri_cal/invalid_timezone_identifer.rb +2 -2
  27. data/lib/ri_cal/occurrence_enumerator.rb +5 -3
  28. data/lib/ri_cal/parser.rb +8 -8
  29. data/lib/ri_cal/properties/alarm.rb +8 -8
  30. data/lib/ri_cal/properties/event.rb +60 -60
  31. data/lib/ri_cal/properties/freebusy.rb +16 -16
  32. data/lib/ri_cal/properties/journal.rb +58 -58
  33. data/lib/ri_cal/properties/timezone_period.rb +23 -23
  34. data/lib/ri_cal/properties/todo.rb +63 -64
  35. data/lib/ri_cal/property_value/array.rb +10 -2
  36. data/lib/ri_cal/property_value/cal_address.rb +1 -2
  37. data/lib/ri_cal/property_value/date.rb +15 -3
  38. data/lib/ri_cal/property_value/date_time/additive_methods.rb +34 -33
  39. data/lib/ri_cal/property_value/date_time/time_machine.rb +175 -174
  40. data/lib/ri_cal/property_value/date_time/timezone_support.rb +70 -52
  41. data/lib/ri_cal/property_value/date_time.rb +47 -77
  42. data/lib/ri_cal/property_value/duration.rb +6 -3
  43. data/lib/ri_cal/property_value/geo.rb +1 -2
  44. data/lib/ri_cal/property_value/integer.rb +1 -2
  45. data/lib/ri_cal/property_value/occurrence_list.rb +79 -26
  46. data/lib/ri_cal/property_value/period.rb +23 -3
  47. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +1 -2
  48. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +1 -2
  49. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +1 -2
  50. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +1 -2
  51. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +1 -2
  52. data/lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb +1 -2
  53. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +1 -2
  54. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +1 -2
  55. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +1 -2
  56. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +1 -2
  57. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +1 -2
  58. data/lib/ri_cal/property_value/recurrence_rule.rb +3 -4
  59. data/lib/ri_cal/property_value/text.rb +1 -2
  60. data/lib/ri_cal/property_value/uri.rb +1 -2
  61. data/lib/ri_cal/property_value/utc_offset.rb +1 -2
  62. data/lib/ri_cal/property_value.rb +42 -11
  63. data/lib/ri_cal/required_timezones.rb +1 -2
  64. data/lib/ri_cal.rb +1 -2
  65. data/ri_cal.gemspec +6 -4
  66. data/spec/ri_cal/component/alarm_spec.rb +1 -2
  67. data/spec/ri_cal/component/calendar_spec.rb +1 -2
  68. data/spec/ri_cal/component/event_spec.rb +168 -13
  69. data/spec/ri_cal/component/freebusy_spec.rb +1 -2
  70. data/spec/ri_cal/component/journal_spec.rb +1 -2
  71. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +1 -2
  72. data/spec/ri_cal/component/timezone_spec.rb +1 -2
  73. data/spec/ri_cal/component/todo_spec.rb +4 -5
  74. data/spec/ri_cal/component_spec.rb +30 -18
  75. data/spec/ri_cal/core_extensions/string/conversions_spec.rb +78 -0
  76. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +1 -2
  77. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +1 -2
  78. data/spec/ri_cal/occurrence_enumerator_spec.rb +23 -2
  79. data/spec/ri_cal/parser_spec.rb +6 -7
  80. data/spec/ri_cal/property_value/date_spec.rb +1 -2
  81. data/spec/ri_cal/property_value/date_time_spec.rb +54 -119
  82. data/spec/ri_cal/property_value/duration_spec.rb +12 -2
  83. data/spec/ri_cal/property_value/occurrence_list_spec.rb +67 -0
  84. data/spec/ri_cal/property_value/period_spec.rb +1 -2
  85. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +1 -2
  86. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1 -2
  87. data/spec/ri_cal/property_value/text_spec.rb +1 -2
  88. data/spec/ri_cal/property_value/utc_offset_spec.rb +1 -2
  89. data/spec/ri_cal/property_value_spec.rb +19 -8
  90. data/spec/ri_cal/required_timezones_spec.rb +1 -2
  91. data/spec/ri_cal_spec.rb +1 -2
  92. data/spec/spec_helper.rb +2 -7
  93. data/tasks/ri_cal.rake +20 -13
  94. data/tasks/spec.rake +1 -1
  95. metadata +8 -5
  96. data/lib/ri_cal/core_extensions/date_time/conversions.rb +0 -27
  97. data/lib/ri_cal/time_with_floating_timezone.rb +0 -59
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper.rb])
5
4
 
@@ -54,6 +53,28 @@ TEXT
54
53
 
55
54
  end
56
55
  end
56
+
57
+ describe ".occurrences" do
58
+ before(:each) do
59
+ @it = RiCal.parse_string(Fr13Unbounded_Zulu).first
60
+ end
61
+
62
+ describe "with :starting specified" do
63
+ it "should exclude dates before :starting" do
64
+ result = @it.occurrences(:starting => Fr13UnboundedZuluExpectedFive[1].dtstart,
65
+ :before => Fr13UnboundedZuluExpectedFive[-1].dtstart)
66
+ result.map{|o|o.dtstart}.should == Fr13UnboundedZuluExpectedFive[1..-2].map{|e| e.dtstart}
67
+ end
68
+ end
69
+
70
+ describe "with :before specified" do
71
+ it "should exclude dates after :before" do
72
+ result = @it.occurrences(:before => Fr13UnboundedZuluExpectedFive[3].dtstart,
73
+ :count => 5)
74
+ result.map{|o|o.dtstart}.should == Fr13UnboundedZuluExpectedFive[0..2].map{|e| e.dtstart}
75
+ end
76
+ end
77
+ end
57
78
 
58
79
 
59
80
  describe ".each" do
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
4
 
@@ -114,7 +113,7 @@ describe RiCal::Parser do
114
113
  describe_multi_property("VEVENT", "ATTACH", {"FMTTYPE" => "application/postscript"}, "FMTTYPE=application/postscript:ftp//xyzCorp.com/put/reports/r-960812.ps", RiCal::PropertyValue::Uri)
115
114
 
116
115
  #RFC 2445 section 4.8.1.2 pp 78
117
- describe_multi_property("VEVENT", "CATEGORIES", {"LANGUAGE" => "us-EN"}, %w{APPOINTMENT EDUCATION}, RiCal::PropertyValue::Array)
116
+ describe_multi_property("VEVENT", "CATEGORIES", {"LANGUAGE" => "us-EN"}, "APPOINTMENT,EDUCATION", RiCal::PropertyValue::Array)
118
117
 
119
118
  #RFC 2445 section 4.8.1.3 pp 79
120
119
  describe_named_property("VEVENT", "CLASS", "security_class", {"X-FOO" => "BAR"}, "PUBLIC", false)
@@ -137,7 +136,7 @@ describe RiCal::Parser do
137
136
  describe_property("VEVENT", "PRIORITY", {"X-FOO" => "BAR"}, 1, RiCal::PropertyValue::Integer)
138
137
 
139
138
  #RFC 2445 section 4.8.1.10 pp 87
140
- describe_multi_property("VEVENT", "RESOURCES", {"X-FOO" => "BAR"}, %w{Easel Projector VCR}, RiCal::PropertyValue::Array)
139
+ describe_multi_property("VEVENT", "RESOURCES", {"X-FOO" => "BAR"}, "Easel,Projector,VCR", RiCal::PropertyValue::Array)
141
140
 
142
141
  #RFC 2445 section 4.8.1.11 pp 88
143
142
  describe_property("VEVENT", "STATUS", {"X-FOO" => "BAR"}, "CONFIRMED")
@@ -158,7 +157,7 @@ describe RiCal::Parser do
158
157
  describe_property("VEVENT", "DTSTART", {"X-FOO" => "BAR"}, "19970714T235959Z", RiCal::PropertyValue::DateTime)
159
158
 
160
159
  #RFC 2445 section 4.8.2.5 DURATION p94
161
- describe_property("VEVENT", "DURATION", {"X-FOO" => "BAR"}, "19970714", RiCal::PropertyValue::Duration)
160
+ describe_property("VEVENT", "DURATION", {"X-FOO" => "BAR"}, "P1H", RiCal::PropertyValue::Duration)
162
161
 
163
162
  #RFC 2445 section 4.8.2.6 FREEBUSY does not apply to Events
164
163
 
@@ -193,13 +192,13 @@ describe RiCal::Parser do
193
192
  describe_property("VEVENT", "UID", {"X-FOO" => "BAR"}, "19960401T080045Z-4000F192713-0052@host1.com")
194
193
 
195
194
  #RFC 2445 section 4.8.5.1 EXDATE p112
196
- describe_multi_property("VEVENT", "EXDATE", {"X-FOO" => "BAR"}, %w{19960402T010000Z 19960403T010000Z 19960404T010000Z}, RiCal::PropertyValue::OccurrenceList)
195
+ describe_multi_property("VEVENT", "EXDATE", {"X-FOO" => "BAR"}, "19960402T010000,19960403T010000,19960404T010000", RiCal::PropertyValue::OccurrenceList)
197
196
 
198
197
  #RFC 2445 section 4.8.5.2 EXRULE p114
199
198
  describe_multi_property("VEVENT", "EXRULE", {"X-FOO" => "BAR"}, "FREQ=DAILY;COUNT=10", RiCal::PropertyValue::RecurrenceRule)
200
199
 
201
200
  #RFC 2445 section 4.8.5.3 RDATE p115
202
- describe_multi_property("VEVENT", "RDATE", {"X-FOO" => "BAR"}, %w{19960402T010000Z 19960403T010000Z 19960404T010000Z}, RiCal::PropertyValue::OccurrenceList)
201
+ describe_multi_property("VEVENT", "RDATE", {"X-FOO" => "BAR"}, "19960402T010000,19960403T010000,19960404T010000", RiCal::PropertyValue::OccurrenceList)
203
202
 
204
203
  #RFC 2445 section 4.8.5.2 RRULE p117
205
204
  describe_multi_property("VEVENT", "RRULE", {"X-FOO" => "BAR"}, "FREQ=DAILY;COUNT=10", RiCal::PropertyValue::RecurrenceRule)
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
 
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
  require 'tzinfo'
@@ -8,49 +7,50 @@ describe RiCal::PropertyValue::DateTime do
8
7
  before(:each) do
9
8
  @cal = RiCal.Calendar
10
9
  end
11
-
10
+
12
11
  def utc_datetime(string)
13
12
  RiCal::PropertyValue::DateTime.new(@cal, :value => "#{string}Z")
14
13
  end
15
-
14
+
16
15
  def local_datetime(string, tzid = "America/New_York")
17
16
  RiCal::PropertyValue::DateTime.new(@cal, :value => string, :params => {'TZID' => tzid})
18
17
  end
19
-
18
+
20
19
  context "time_with_zone_methods" do
21
20
  context ".utc" do
22
21
  context "for a datetime already in zulu time" do
23
22
  before(:each) do
24
23
  @it = utc_datetime("19970101T012300").utc
25
24
  end
26
-
25
+
27
26
  it "should return the same datetime" do
28
27
  @it.should == utc_datetime("19970101T012300")
29
28
  end
30
-
29
+
31
30
  it "should return a result with a tzid of UTC" do
32
31
  @it.utc.tzid.should == "UTC"
33
32
  end
34
33
  end
35
-
34
+
36
35
  it "should raise an invalid timezone exception if the timezone of the receiver is unknown" do
37
36
  lambda {local_datetime("19970101T012300", 'America/Caspian').utc}.should raise_error(RiCal::InvalidTimezoneIdentifier)
38
37
  end
39
38
 
40
39
  context "for a datetime with a tzid of America/New_York" do
41
40
  before(:each) do
42
- @it = local_datetime("19970101T012300").utc
41
+ @it = local_datetime("19970101T012300")
42
+ @it = @it.utc
43
43
  end
44
-
44
+
45
45
  it "should return the equivalent utc time" do
46
46
  @it.should == utc_datetime("19970101T062300")
47
47
  end
48
-
48
+
49
49
  it "should return a result with a tzid of UTC" do
50
50
  @it.tzid.should == "UTC"
51
51
  end
52
52
  end
53
-
53
+
54
54
  context ".in_timezone('America/New_York')" do
55
55
 
56
56
  it "should raise an invalid timezone exception if the timezone of the receiver is unknown" do
@@ -75,11 +75,11 @@ describe RiCal::PropertyValue::DateTime do
75
75
  before(:each) do
76
76
  @it = local_datetime("19970101T012300").in_time_zone('America/New_York')
77
77
  end
78
-
78
+
79
79
  it "should return the same time" do
80
80
  @it.should == local_datetime("19970101T012300")
81
81
  end
82
-
82
+
83
83
  it "should return a result with a tzid of UTC" do
84
84
  @it.tzid.should == "America/New_York"
85
85
  end
@@ -182,13 +182,13 @@ END:VCALENDAR
182
182
  END_OF_DATA
183
183
  @cal = cals.first
184
184
  end
185
-
185
+
186
186
  def find_event(summary)
187
187
  @cal.events.find {|event| event.summary == summary}
188
188
  end
189
-
189
+
190
190
  context ".utc" do
191
-
191
+
192
192
  it "should raise an invalid timezone exception if the timezone of the receiver is not in the calendar" do
193
193
  lambda {local_datetime("19970101T012300", 'America/New_York').utc}.should raise_error(RiCal::InvalidTimezoneIdentifier)
194
194
  end
@@ -211,23 +211,23 @@ END:VCALENDAR
211
211
  before(:each) do
212
212
  @it = find_event("Eastern Event").dtstart_property.utc
213
213
  end
214
-
214
+
215
215
  it "should return the equivalent utc time" do
216
216
  @it.should == utc_datetime("20090430T180000")
217
217
  end
218
-
218
+
219
219
  it "should return a result with a tzid of UTC" do
220
220
  @it.tzid.should == "UTC"
221
221
  end
222
222
  end
223
223
  end
224
-
224
+
225
225
  context ".in_timezone('US/Eastern')" do
226
-
226
+
227
227
  it "should raise an invalid timezone exception if the timezone of the receiver is not in the calendar" do
228
228
  lambda {local_datetime("19970101T012300", 'America/New_York').in_time_zone("US/Eastern")}.should raise_error(RiCal::InvalidTimezoneIdentifier)
229
229
  end
230
-
230
+
231
231
  context "for the DTSTART of the UTC Event" do
232
232
  before(:each) do
233
233
  @it = find_event("UTC Event").dtstart_property.in_time_zone("US/Eastern")
@@ -246,11 +246,11 @@ END:VCALENDAR
246
246
  before(:each) do
247
247
  @it = find_event("Eastern Event").dtstart_property.in_time_zone("US/Eastern")
248
248
  end
249
-
249
+
250
250
  it "should return the same time" do
251
251
  @it.should == local_datetime("20090430T140000", "US/Eastern")
252
252
  end
253
-
253
+
254
254
  it "should return a result with a tzid of UTC" do
255
255
  @it.tzid.should == "US/Eastern"
256
256
  end
@@ -260,11 +260,11 @@ END:VCALENDAR
260
260
  before(:each) do
261
261
  @it = find_event("Paris Event").dtstart_property.in_time_zone("US/Eastern")
262
262
  end
263
-
263
+
264
264
  it "should return 8:00 a.m. on Apr 30, 2009" do
265
265
  @it.should == local_datetime("20090430T080000", "US/Eastern")
266
266
  end
267
-
267
+
268
268
  it "should return a result with a tzid of UTC" do
269
269
  @it.tzid.should == "US/Eastern"
270
270
  end
@@ -282,7 +282,7 @@ END:VCALENDAR
282
282
  RiCal::PropertyValue::DateTime.or_date(nil, :value => "19980118T230000").should be_kind_of(RiCal::PropertyValue::DateTime)
283
283
  end
284
284
  end
285
-
285
+
286
286
  context ".advance" do
287
287
  it "should advance by one week if passed :days => 7" do
288
288
  dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "20050131T230000")
@@ -290,17 +290,17 @@ END:VCALENDAR
290
290
  dt1.advance(:days => 7).should == dt2
291
291
  end
292
292
  end
293
-
293
+
294
294
  context "subtracting one date-time from another" do
295
-
295
+
296
296
  it "should produce the right RiCal::PropertyValue::Duration" do
297
297
  dt1 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T230000")
298
298
  dt2 = RiCal::PropertyValue::DateTime.new(nil, :value => "19980119T010000")
299
299
  @it = dt2 - dt1
300
300
  @it.should == RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
301
- end
301
+ end
302
302
  end
303
-
303
+
304
304
  context "adding a RiCal::PropertyValue::Duration to a RiCal::PropertyValue::DateTime" do
305
305
 
306
306
  it "should produce the right RiCal::PropertyValue::DateTime" do
@@ -320,6 +320,28 @@ END:VCALENDAR
320
320
  @it.should == RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T230000")
321
321
  end
322
322
  end
323
+ context "when setting the default timezone identifier" do
324
+
325
+ before(:each) do
326
+ RiCal::PropertyValue::DateTime.default_tzid = "America/Chicago"
327
+ @time = Time.mktime(2009,2,5,19,17,11)
328
+ @it = RiCal::PropertyValue::DateTime.convert(nil, @time)
329
+ end
330
+
331
+ after(:each) do
332
+ RiCal::PropertyValue::DateTime.default_tzid = "UTC"
333
+ end
334
+
335
+ it "should update the default timezone to America/Chicago" do
336
+ @it.params.should == {'TZID' => 'America/Chicago'}
337
+ end
338
+
339
+ it "should not have a tzid when default_tzid is :floating" do
340
+ RiCal::PropertyValue::DateTime.default_tzid = :floating
341
+ dt = RiCal::PropertyValue::DateTime.convert(nil, @time)
342
+ dt.params.should == {}
343
+ end
344
+ end
323
345
 
324
346
  context ".convert(rubyobject)" do
325
347
  describe "for a Time instance of Feb 05 19:17:11"
@@ -341,6 +363,7 @@ END:VCALENDAR
341
363
  @it.value.should == "20090205T191711Z"
342
364
  end
343
365
  end
366
+
344
367
  context "when the default timezone has been set to 'America/Chicago" do
345
368
  before(:each) do
346
369
  RiCal::PropertyValue::DateTime.stub!(:default_tzid).and_return("America/Chicago")
@@ -356,93 +379,5 @@ END:VCALENDAR
356
379
  end
357
380
  end
358
381
  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
382
  end
448
383
  end
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
  require 'date'
@@ -77,4 +76,15 @@ describe RiCal::PropertyValue::Duration do
77
76
  end
78
77
  end
79
78
 
79
+ describe ".from_datetimes" do
80
+ it "should work when start > finish" do
81
+ lambda {
82
+ RiCal::PropertyValue::Duration.from_datetimes(nil,
83
+ DateTime.parse("Sep 2, 2008 1:01:02"),
84
+ DateTime.parse("Sep 1, 2008 23:00")
85
+ )
86
+ }.should_not raise_error(ArgumentError)
87
+ end
88
+ end
89
+
80
90
  end
@@ -0,0 +1,67 @@
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
2
+
3
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
4
+
5
+ describe RiCal::PropertyValue::OccurrenceList do
6
+
7
+ context ".convert method" do
8
+ context "with a single datetime" do
9
+ before(:each) do
10
+ @it = RiCal::PropertyValue::OccurrenceList.convert(nil, DateTime.parse("5 May 2009, 9:32 am"))
11
+ end
12
+
13
+ it "should produce the right ical representation" do
14
+ @it.to_s.should == ":20090505T093200Z"
15
+ end
16
+
17
+ it "should have the right ruby value" do
18
+ @it.ruby_value.should == [DateTime.parse("5 May 2009, 9:32 am")]
19
+ end
20
+
21
+ it "should have the right elements" do
22
+ @it.send(:elements).should == [RiCal::PropertyValue::DateTime.new(nil, :value => "20090505T093200Z" )]
23
+ end
24
+ end
25
+
26
+ context "with conflicting timezones" do
27
+ before(:each) do
28
+ @event = RiCal.Event
29
+ end
30
+
31
+ it "should raise an InvalidPropertyValue if an argument does not match an explicit time zone" do
32
+ lambda {RiCal::PropertyValue::OccurrenceList.convert(@event, "America/New_York", Time.now.set_tzid("America/Chicago"))}.should raise_error(RiCal::InvalidPropertyValue)
33
+ end
34
+
35
+ it "should raise an InvalidPropertyValue if the arguments have mixed time zones" do
36
+ lambda {RiCal::PropertyValue::OccurrenceList.convert(@event, Time.now.set_tzid("America/New_York"), Time.now.set_tzid("America/Chicago"))}.should raise_error(RiCal::InvalidPropertyValue)
37
+ end
38
+ end
39
+
40
+ context "with a tzid and a single datetime" do
41
+ before(:each) do
42
+ timezone = mock("Timezone", :rational_utc_offset => Rational(-5, 24))
43
+ timezone_finder = mock("tz_finder", :find_timezone => timezone, :default_tzid => "UTC")
44
+ @it = RiCal::PropertyValue::OccurrenceList.convert(timezone_finder, 'US/Eastern', "19620220T144739")
45
+ end
46
+
47
+ it "should produce the right ical representation" do
48
+ @it.to_s.should == ";TZID=US/Eastern:19620220T144739"
49
+ end
50
+
51
+ context "its ruby value" do
52
+
53
+ it "should be the right DateTime" do
54
+ @it.ruby_value.should == [DateTime.civil(1962, 2, 20, 14, 47, 39, Rational(-5, 24))]
55
+ end
56
+
57
+ it "should have the right tzid" do
58
+ @it.ruby_value.first.tzid.should == "US/Eastern"
59
+ end
60
+ end
61
+
62
+ it "should have the right elements" do
63
+ @it.send(:elements).should == [RiCal::PropertyValue::DateTime.new(nil, :params=> {'TZID' => 'US/Eastern'}, :value => "19620220T144739" )]
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
 
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. .. spec_helper])
5
4
 
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
 
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
 
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
4
 
@@ -1,7 +1,7 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
4
+ require 'tzinfo'
5
5
 
6
6
  describe RiCal::PropertyValue do
7
7
 
@@ -38,7 +38,7 @@ describe RiCal::PropertyValue do
38
38
  before(:each) do
39
39
  @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456")
40
40
  end
41
-
41
+
42
42
  it "should return a PropertyValue::DateTime" do
43
43
  @prop.should be_kind_of(RiCal::PropertyValue::DateTime)
44
44
  end
@@ -52,7 +52,7 @@ describe RiCal::PropertyValue do
52
52
  end
53
53
 
54
54
  it "should have a nil tzid" do
55
- @prop.tzid.should be_nil
55
+ @prop.tzid.should == nil
56
56
  end
57
57
  end
58
58
 
@@ -81,7 +81,9 @@ describe RiCal::PropertyValue do
81
81
 
82
82
  describe "FORM #3 date with local time and time zone reference p 36" do
83
83
  before(:each) do
84
- @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456", :params => {'TZID' => 'US-Eastern'})
84
+ timezone = mock("Timezone", :rational_utc_offset => Rational(-4, 24))
85
+ timezone_finder = mock("tz_finder", :find_timezone => timezone)
86
+ @prop = RiCal::PropertyValue.date_or_date_time(timezone_finder, :value => "19970714T123456", :params => {'TZID' => 'US-Eastern'})
85
87
  end
86
88
 
87
89
  it "should return a PropertyValue::DateTime" do
@@ -92,9 +94,18 @@ describe RiCal::PropertyValue do
92
94
  @prop.value.should == "19970714T123456"
93
95
  end
94
96
 
95
- it "should have the right ruby value" do
96
- #TODO - what do we do about timezone with and without activesupport
97
- @prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456")
97
+ context "it's Ruby value" do
98
+ before(:each) do
99
+ @it = @prop.ruby_value
100
+ end
101
+
102
+ it "should be the right DateTime" do
103
+ @it.should == DateTime.civil(1997,7, 14, 12, 34, 56, Rational(-4, 24))
104
+ end
105
+
106
+ it "should have the right tzid" do
107
+ @it.tzid.should == "US-Eastern"
108
+ end
98
109
  end
99
110
 
100
111
  it "should have the right tzid" do
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
4
 
data/spec/ri_cal_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.join(File.dirname(__FILE__), %w[spec_helper])
5
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
- #- ©2009 Rick DeNatale
2
- #- All rights reserved
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
3
2
 
4
3
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ri_cal]))
5
4
  require 'cgi'
@@ -12,11 +11,7 @@ module Kernel
12
11
  end
13
12
 
14
13
  def date_time_with_zone(date_time, tzid = "US/Eastern")
15
- result = date_time.dup
16
- result.stub!(:acts_like_time?).and_return(true)
17
- time_zone = mock("timezone", :identifier => tzid)
18
- result.stub!(:time_zone).and_return(time_zone)
19
- result
14
+ date_time.dup.set_tzid(tzid)
20
15
  end
21
16
 
22
17
  def dt_prop(date_time, tzid = "US/Eastern")