rubyredrick-ri_cal 0.0.7 → 0.0.8

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.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.0.8
2
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/1-occurrence-lists-not-picking-up-timewithzone-identifier#ticket-1-2
3
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/2-date-property-subtraction-bug
4
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/3-fwd-ri_cal-question
5
+ Components with no recurrence rules or rdate properties failed on enumeration, they now
6
+ will enumerate a single occurrence
7
+
1
8
  === 0.0.7
2
9
  * Fixed a bug relating to properly recognizing ActiveRecord::TimeWithZone
3
10
  * DATETIME propertyvalues will now return an instance of TimeWithZone instead of DateTime when
data/Manifest.txt CHANGED
@@ -121,7 +121,7 @@ spec/ri_cal/required_timezones_spec.rb
121
121
  spec/ri_cal_spec.rb
122
122
  spec/spec.opts
123
123
  spec/spec_helper.rb
124
- tasks/ri_cal.rake
125
- tasks/spec.rake
126
124
  tasks/gem_loader/load_active_support.rb
127
125
  tasks/gem_loader/load_tzinfo_gem.rb
126
+ tasks/ri_cal.rake
127
+ tasks/spec.rake
@@ -17,12 +17,12 @@ module RiCal
17
17
  self.tzid = time_zone_identifier
18
18
  self
19
19
  end
20
-
20
+
21
21
  # Predicate indicating whether or not the instance represents a floating time
22
22
  def has_floating_timezone?
23
23
  tzid == :floating
24
24
  end
25
-
25
+
26
26
  end
27
27
  end
28
28
  end
@@ -36,10 +36,12 @@ module RiCal
36
36
  def has_floating_timezone?
37
37
  false
38
38
  end
39
-
40
- def to_ri_cal_date_or_date_time_value(timezone_finder=nil)
39
+
40
+ def to_ri_cal_date_time_value(timezone_finder=nil)
41
41
  ::RiCal::PropertyValue::DateTime.new(timezone_finder, :params => {"TZID" => tzid}, :value => strftime("%Y%m%dT%H%M%S"))
42
42
  end
43
+ alias_method :to_ri_cal_date_or_date_time_value, :to_ri_cal_date_time_value
44
+ alias_method :to_ri_cal_occurrence_list_value, :to_ri_cal_date_time_value
43
45
  end
44
46
  end
45
47
 
@@ -20,6 +20,14 @@ module RiCal
20
20
  def self.next_occurrence
21
21
  nil
22
22
  end
23
+
24
+ def self.bounded?
25
+ true
26
+ end
27
+
28
+ def self.empty?
29
+ true
30
+ end
23
31
  end
24
32
 
25
33
  # OccurrenceMerger takes multiple recurrence rules and enumerates the combination in sequence.
@@ -39,9 +47,14 @@ module RiCal
39
47
  def initialize(component, rules)
40
48
  self.enumerators = rules.map {|rrule| rrule.enumerator(component)}
41
49
  @bounded = enumerators.all? {|enumerator| enumerator.bounded?}
50
+ @empty = enumerators.all? {|enumerator| enumerator.empty?}
42
51
  self.nexts = @enumerators.map {|enumerator| enumerator.next_occurrence}
43
52
  end
44
53
 
54
+ def empty?
55
+ @empty
56
+ end
57
+
45
58
  # return the earliest of each of the enumerators next occurrences
46
59
  def next_occurrence
47
60
  result = nexts.compact.sort.first
@@ -93,18 +106,22 @@ module RiCal
93
106
  # yield each occurrence to a block
94
107
  # some components may be open-ended, e.g. have no COUNT or DTEND
95
108
  def each
96
- occurrence = @rrules.next_occurrence
97
- yielded = 0
98
- @next_exclusion = @exrules.next_occurrence
99
- while (occurrence)
100
- if (@cutoff && occurrence[:start].to_datetime >= @cutoff) || (@count && yielded >= @count)
101
- occurrence = nil
102
- else
103
- unless exclude?(occurrence)
104
- yielded += 1
105
- yield @component.recurrence(occurrence)
109
+ if @rrules.empty?
110
+ yield @component
111
+ else
112
+ occurrence = @rrules.next_occurrence
113
+ yielded = 0
114
+ @next_exclusion = @exrules.next_occurrence
115
+ while (occurrence)
116
+ if (@cutoff && occurrence[:start].to_datetime >= @cutoff) || (@count && yielded >= @count)
117
+ occurrence = nil
118
+ else
119
+ unless exclude?(occurrence)
120
+ yielded += 1
121
+ yield @component.recurrence(occurrence)
122
+ end
123
+ occurrence = @rrules.next_occurrence
106
124
  end
107
- occurrence = @rrules.next_occurrence
108
125
  end
109
126
  end
110
127
  end
@@ -76,7 +76,7 @@ module RiCal
76
76
 
77
77
  # Return an instance of RiCal::PropertyValue::DateTime representing the start of this date
78
78
  def to_ri_cal_date_time_value
79
- PropertyValue::DateTime.new(:value => @date_time_value)
79
+ PropertyValue::DateTime.new(timezone_finder, :value => @date_time_value)
80
80
  end
81
81
 
82
82
  # Return this date property
@@ -113,6 +113,27 @@ module RiCal
113
113
  # Do nothing since dates don't have a timezone
114
114
  end
115
115
 
116
+ # Return the difference between the receiver and other
117
+ #
118
+ # The parameter other should be either a RiCal::PropertyValue::Duration or a RiCal::PropertyValue::DateTime
119
+ #
120
+ # If other is a Duration, the result will be a DateTime, if it is a DateTime the result will be a Duration
121
+ def -(other)
122
+ other.subtract_from_date_time_value(to_ri_cal_date_time_value)
123
+ end
124
+
125
+ def subtract_from_date_time_value(date_time)
126
+ to_ri_cal_date_time_value.subtract_from_date_time_value(date_time)
127
+ end
128
+
129
+ # Return the sum of the receiver and duration
130
+ #
131
+ # The parameter other duration should be a RiCal::PropertyValue::Duration
132
+ #
133
+ # The result will be an RiCal::PropertyValue::DateTime
134
+ def +(duration)
135
+ duration.add_to_date_time_value(to_ri_cal_date_time_value)
136
+ end
116
137
 
117
138
  # Delegate unknown messages to the wrappered Date instance.
118
139
  # TODO: Is this really necessary?
@@ -28,7 +28,8 @@ module RiCal
28
28
  hour_part = value_part('H', hour_diff)
29
29
  min_part = value_part('M', min_diff)
30
30
  sec_part = value_part('S', sec_diff)
31
- new(parent, :value => "#{sign}P#{day_part}T#{day_part}#{hour_part}#{min_part}#{sec_part}")
31
+ t_part = (hour_diff.abs + min_diff.abs + sec_diff.abs) == 0 ? "" : "T"
32
+ new(parent, :value => "#{sign}P#{day_part}#{t_part}#{hour_part}#{min_part}#{sec_part}")
32
33
  end
33
34
  end
34
35
 
@@ -16,6 +16,10 @@ module RiCal
16
16
  self.default_duration = component.default_duration
17
17
  @index = 0
18
18
  end
19
+
20
+ def empty?
21
+ occurrence_list.empty?
22
+ end
19
23
 
20
24
  def next_occurrence
21
25
  if @index < occurrence_list.length
@@ -19,16 +19,19 @@ module RiCal
19
19
  @next_occurrence_count = 0
20
20
  @incrementer = YearlyIncrementer.from_rrule(recurrence_rule, start_time)
21
21
  end
22
-
22
+
23
23
  def self.for(recurrence_rule, component, setpos_list) # :nodoc:
24
24
  if !setpos_list || setpos_list.all? {|setpos| setpos > 1}
25
25
  self.new(recurrence_rule, component, setpos_list)
26
26
  else
27
27
  NegativeSetposEnumerator.new(recurrence_rule, component, setpos_list)
28
28
  end
29
- end
30
-
31
-
29
+ end
30
+
31
+ def empty?
32
+ false
33
+ end
34
+
32
35
  def bounded?
33
36
  @bounded
34
37
  end
@@ -54,7 +57,7 @@ module RiCal
54
57
  def result_passes_filters?(result)
55
58
  if @setpos_list
56
59
  result_passes_setpos_filter?(result)
57
- else
60
+ else
58
61
  result >= start_time
59
62
  end
60
63
  end
@@ -65,7 +68,7 @@ module RiCal
65
68
  result = next_time
66
69
  self.next_time = @incrementer.next_time(result)
67
70
  if result_passes_filters?(result)
68
- @count += 1
71
+ @count += 1
69
72
  return recurrence_rule.exhausted?(@count, result) ? nil : result_hash(result)
70
73
  end
71
74
  end
data/lib/ri_cal.rb CHANGED
@@ -11,7 +11,7 @@ module RiCal
11
11
  autoload :OccurrenceEnumerator, "#{my_dir}/ri_cal/occurrence_enumerator.rb"
12
12
 
13
13
  # :stopdoc:
14
- VERSION = '0.0.7'
14
+ VERSION = '0.0.8'
15
15
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
16
16
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
17
17
 
data/ri_cal.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ri_cal}
5
- s.version = "0.0.7"
5
+ s.version = "0.0.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["author=Rick DeNatale"]
9
- s.date = %q{2009-05-18}
9
+ s.date = %q{2009-05-19}
10
10
  s.default_executable = %q{ri_cal}
11
11
  s.description = %q{This is an UNOFFICIAL version. The public official version will be released on RubyForge. Github will be used
12
12
  for interim versions. USE THIS VERSION AT YOUR OWN RISK.
@@ -22,7 +22,7 @@ A Google group for discussion of this library has been set up http://groups.goog
22
22
  s.email = ["rick.denatale@gmail.com"]
23
23
  s.executables = ["ri_cal"]
24
24
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt", "copyrights.txt", "docs/draft-ietf-calsify-2446bis-08.txt", "docs/draft-ietf-calsify-rfc2445bis-09.txt", "docs/incrementers.txt"]
25
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/ri_cal", "component_attributes/alarm.yml", "component_attributes/calendar.yml", "component_attributes/component_property_defs.yml", "component_attributes/event.yml", "component_attributes/freebusy.yml", "component_attributes/journal.yml", "component_attributes/timezone.yml", "component_attributes/timezone_period.yml", "component_attributes/todo.yml", "copyrights.txt", "docs/draft-ietf-calsify-2446bis-08.txt", "docs/draft-ietf-calsify-rfc2445bis-09.txt", "docs/incrementers.txt", "docs/rfc2445.pdf", "lib/ri_cal.rb", "lib/ri_cal/component.rb", "lib/ri_cal/component/alarm.rb", "lib/ri_cal/component/calendar.rb", "lib/ri_cal/component/event.rb", "lib/ri_cal/component/freebusy.rb", "lib/ri_cal/component/journal.rb", "lib/ri_cal/component/t_z_info_timezone.rb", "lib/ri_cal/component/timezone.rb", "lib/ri_cal/component/timezone/daylight_period.rb", "lib/ri_cal/component/timezone/standard_period.rb", "lib/ri_cal/component/timezone/timezone_period.rb", "lib/ri_cal/component/todo.rb", "lib/ri_cal/core_extensions.rb", "lib/ri_cal/core_extensions/array.rb", "lib/ri_cal/core_extensions/array/conversions.rb", "lib/ri_cal/core_extensions/date.rb", "lib/ri_cal/core_extensions/date/conversions.rb", "lib/ri_cal/core_extensions/date_time.rb", "lib/ri_cal/core_extensions/object.rb", "lib/ri_cal/core_extensions/object/conversions.rb", "lib/ri_cal/core_extensions/string.rb", "lib/ri_cal/core_extensions/string/conversions.rb", "lib/ri_cal/core_extensions/time.rb", "lib/ri_cal/core_extensions/time/calculations.rb", "lib/ri_cal/core_extensions/time/conversions.rb", "lib/ri_cal/core_extensions/time/tzid_access.rb", "lib/ri_cal/core_extensions/time/week_day_predicates.rb", "lib/ri_cal/floating_timezone.rb", "lib/ri_cal/invalid_property_value.rb", "lib/ri_cal/invalid_timezone_identifer.rb", "lib/ri_cal/occurrence_enumerator.rb", "lib/ri_cal/parser.rb", "lib/ri_cal/properties/alarm.rb", "lib/ri_cal/properties/calendar.rb", "lib/ri_cal/properties/event.rb", "lib/ri_cal/properties/freebusy.rb", "lib/ri_cal/properties/journal.rb", "lib/ri_cal/properties/timezone.rb", "lib/ri_cal/properties/timezone_period.rb", "lib/ri_cal/properties/todo.rb", "lib/ri_cal/property_value.rb", "lib/ri_cal/property_value/array.rb", "lib/ri_cal/property_value/cal_address.rb", "lib/ri_cal/property_value/date.rb", "lib/ri_cal/property_value/date_time.rb", "lib/ri_cal/property_value/date_time/additive_methods.rb", "lib/ri_cal/property_value/date_time/time_machine.rb", "lib/ri_cal/property_value/date_time/timezone_support.rb", "lib/ri_cal/property_value/duration.rb", "lib/ri_cal/property_value/geo.rb", "lib/ri_cal/property_value/integer.rb", "lib/ri_cal/property_value/occurrence_list.rb", "lib/ri_cal/property_value/period.rb", "lib/ri_cal/property_value/recurrence_rule.rb", "lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb", "lib/ri_cal/property_value/recurrence_rule/enumerator.rb", "lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb", "lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb", "lib/ri_cal/property_value/recurrence_rule/numbered_span.rb", "lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_day.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb", "lib/ri_cal/property_value/recurrence_rule/validations.rb", "lib/ri_cal/property_value/text.rb", "lib/ri_cal/property_value/uri.rb", "lib/ri_cal/property_value/utc_offset.rb", "lib/ri_cal/required_timezones.rb", "ri_cal.gemspec", "sample_ical_files/from_ical_dot_app/test1.ics", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/ri_cal/component/alarm_spec.rb", "spec/ri_cal/component/calendar_spec.rb", "spec/ri_cal/component/event_spec.rb", "spec/ri_cal/component/freebusy_spec.rb", "spec/ri_cal/component/journal_spec.rb", "spec/ri_cal/component/t_z_info_timezone_spec.rb", "spec/ri_cal/component/timezone_spec.rb", "spec/ri_cal/component/todo_spec.rb", "spec/ri_cal/component_spec.rb", "spec/ri_cal/core_extensions/string/conversions_spec.rb", "spec/ri_cal/core_extensions/time/calculations_spec.rb", "spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb", "spec/ri_cal/occurrence_enumerator_spec.rb", "spec/ri_cal/parser_spec.rb", "spec/ri_cal/property_value/date_spec.rb", "spec/ri_cal/property_value/date_time_spec.rb", "spec/ri_cal/property_value/duration_spec.rb", "spec/ri_cal/property_value/occurrence_list_spec.rb", "spec/ri_cal/property_value/period_spec.rb", "spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb", "spec/ri_cal/property_value/recurrence_rule_spec.rb", "spec/ri_cal/property_value/text_spec.rb", "spec/ri_cal/property_value/utc_offset_spec.rb", "spec/ri_cal/property_value_spec.rb", "spec/ri_cal/required_timezones_spec.rb", "spec/ri_cal_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/ri_cal.rake", "tasks/spec.rake", "tasks/gem_loader/load_active_support.rb", "tasks/gem_loader/load_tzinfo_gem.rb"]
25
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/ri_cal", "component_attributes/alarm.yml", "component_attributes/calendar.yml", "component_attributes/component_property_defs.yml", "component_attributes/event.yml", "component_attributes/freebusy.yml", "component_attributes/journal.yml", "component_attributes/timezone.yml", "component_attributes/timezone_period.yml", "component_attributes/todo.yml", "copyrights.txt", "docs/draft-ietf-calsify-2446bis-08.txt", "docs/draft-ietf-calsify-rfc2445bis-09.txt", "docs/incrementers.txt", "docs/rfc2445.pdf", "lib/ri_cal.rb", "lib/ri_cal/component.rb", "lib/ri_cal/component/alarm.rb", "lib/ri_cal/component/calendar.rb", "lib/ri_cal/component/event.rb", "lib/ri_cal/component/freebusy.rb", "lib/ri_cal/component/journal.rb", "lib/ri_cal/component/t_z_info_timezone.rb", "lib/ri_cal/component/timezone.rb", "lib/ri_cal/component/timezone/daylight_period.rb", "lib/ri_cal/component/timezone/standard_period.rb", "lib/ri_cal/component/timezone/timezone_period.rb", "lib/ri_cal/component/todo.rb", "lib/ri_cal/core_extensions.rb", "lib/ri_cal/core_extensions/array.rb", "lib/ri_cal/core_extensions/array/conversions.rb", "lib/ri_cal/core_extensions/date.rb", "lib/ri_cal/core_extensions/date/conversions.rb", "lib/ri_cal/core_extensions/date_time.rb", "lib/ri_cal/core_extensions/object.rb", "lib/ri_cal/core_extensions/object/conversions.rb", "lib/ri_cal/core_extensions/string.rb", "lib/ri_cal/core_extensions/string/conversions.rb", "lib/ri_cal/core_extensions/time.rb", "lib/ri_cal/core_extensions/time/calculations.rb", "lib/ri_cal/core_extensions/time/conversions.rb", "lib/ri_cal/core_extensions/time/tzid_access.rb", "lib/ri_cal/core_extensions/time/week_day_predicates.rb", "lib/ri_cal/floating_timezone.rb", "lib/ri_cal/invalid_property_value.rb", "lib/ri_cal/invalid_timezone_identifer.rb", "lib/ri_cal/occurrence_enumerator.rb", "lib/ri_cal/parser.rb", "lib/ri_cal/properties/alarm.rb", "lib/ri_cal/properties/calendar.rb", "lib/ri_cal/properties/event.rb", "lib/ri_cal/properties/freebusy.rb", "lib/ri_cal/properties/journal.rb", "lib/ri_cal/properties/timezone.rb", "lib/ri_cal/properties/timezone_period.rb", "lib/ri_cal/properties/todo.rb", "lib/ri_cal/property_value.rb", "lib/ri_cal/property_value/array.rb", "lib/ri_cal/property_value/cal_address.rb", "lib/ri_cal/property_value/date.rb", "lib/ri_cal/property_value/date_time.rb", "lib/ri_cal/property_value/date_time/additive_methods.rb", "lib/ri_cal/property_value/date_time/time_machine.rb", "lib/ri_cal/property_value/date_time/timezone_support.rb", "lib/ri_cal/property_value/duration.rb", "lib/ri_cal/property_value/geo.rb", "lib/ri_cal/property_value/integer.rb", "lib/ri_cal/property_value/occurrence_list.rb", "lib/ri_cal/property_value/period.rb", "lib/ri_cal/property_value/recurrence_rule.rb", "lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb", "lib/ri_cal/property_value/recurrence_rule/enumerator.rb", "lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb", "lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb", "lib/ri_cal/property_value/recurrence_rule/numbered_span.rb", "lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_day.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb", "lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb", "lib/ri_cal/property_value/recurrence_rule/validations.rb", "lib/ri_cal/property_value/text.rb", "lib/ri_cal/property_value/uri.rb", "lib/ri_cal/property_value/utc_offset.rb", "lib/ri_cal/required_timezones.rb", "ri_cal.gemspec", "sample_ical_files/from_ical_dot_app/test1.ics", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/ri_cal/component/alarm_spec.rb", "spec/ri_cal/component/calendar_spec.rb", "spec/ri_cal/component/event_spec.rb", "spec/ri_cal/component/freebusy_spec.rb", "spec/ri_cal/component/journal_spec.rb", "spec/ri_cal/component/t_z_info_timezone_spec.rb", "spec/ri_cal/component/timezone_spec.rb", "spec/ri_cal/component/todo_spec.rb", "spec/ri_cal/component_spec.rb", "spec/ri_cal/core_extensions/string/conversions_spec.rb", "spec/ri_cal/core_extensions/time/calculations_spec.rb", "spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb", "spec/ri_cal/occurrence_enumerator_spec.rb", "spec/ri_cal/parser_spec.rb", "spec/ri_cal/property_value/date_spec.rb", "spec/ri_cal/property_value/date_time_spec.rb", "spec/ri_cal/property_value/duration_spec.rb", "spec/ri_cal/property_value/occurrence_list_spec.rb", "spec/ri_cal/property_value/period_spec.rb", "spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb", "spec/ri_cal/property_value/recurrence_rule_spec.rb", "spec/ri_cal/property_value/text_spec.rb", "spec/ri_cal/property_value/utc_offset_spec.rb", "spec/ri_cal/property_value_spec.rb", "spec/ri_cal/required_timezones_spec.rb", "spec/ri_cal_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/gem_loader/load_active_support.rb", "tasks/gem_loader/load_tzinfo_gem.rb", "tasks/ri_cal.rake", "tasks/spec.rake"]
26
26
  s.has_rdoc = true
27
27
  s.homepage = %q{http://rical.rubyforge.org/}
28
28
  s.rdoc_options = ["--main", "README.txt"]
@@ -1,4 +1,5 @@
1
1
  #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
2
+
2
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
3
4
 
4
5
  describe RiCal::Component::Event do
@@ -312,6 +313,32 @@ describe RiCal::Component::Event do
312
313
 
313
314
  if RiCal::TimeWithZone
314
315
  context "with ActiveSupport loaded" do
316
+
317
+ context "an event with an timezoned exdate" do
318
+ before(:each) do
319
+ @old_timezone = Time.zone
320
+ Time.zone = "America/New_York"
321
+ @exception_date_time = Time.zone.local(2009, 5, 19, 11, 13)
322
+ cal = RiCal.Calendar do |cal|
323
+ cal.event do |event|
324
+ event.add_exdate @exception_date_time
325
+ end
326
+ end
327
+ @event = cal.events.first
328
+ end
329
+
330
+ after(:each) do
331
+ Time.zone = @old_timezone
332
+ end
333
+
334
+ it "should pickup the timezone in the exdate property" do
335
+ @event.exdate.first.first.tzid.should == "America/New_York"
336
+ end
337
+
338
+ it "should have the timezone in the ical representation of the exdate property" do
339
+ @event.exdate_property.to_s.should match(%r{;TZID=America/New_York[:;]})
340
+ end
341
+ end
315
342
 
316
343
  context "An event in a non-tzinfo source calendar" do
317
344
  before(:each) do
@@ -2,6 +2,10 @@
2
2
 
3
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper.rb])
4
4
 
5
+ def mock_enumerator(name, next_occurrence)
6
+ mock(name, :next_occurrence => next_occurrence, :bounded? => true, :empty? => false)
7
+ end
8
+
5
9
  # Note that this is more of a functional spec
6
10
  describe RiCal::OccurrenceEnumerator do
7
11
 
@@ -130,8 +134,8 @@ describe RiCal::OccurrenceEnumerator::OccurrenceMerger do
130
134
  describe "with multiple rrules" do
131
135
  before(:each) do
132
136
  @component = mock("component", :dtstart => :dtstart_value)
133
- @enum1 = mock("rrule_enumerator1", :next_occurrence => :occ1, :bounded? => true)
134
- @enum2 = mock("rrule_enumerator2", :next_occurrence => :occ2, :bounded? => true)
137
+ @enum1 = mock_enumerator("rrule_enumerator1", :occ1)
138
+ @enum2 = mock_enumerator("rrule_enumerator2", :occ2)
135
139
  @rrule1 = mock("rrule", :enumerator => @enum1)
136
140
  @rrule2 = mock("rrule", :enumerator => @enum2)
137
141
  end
@@ -158,8 +162,8 @@ describe RiCal::OccurrenceEnumerator::OccurrenceMerger do
158
162
 
159
163
  describe "with unique nexts" do
160
164
  before(:each) do
161
- @enum1 = mock("rrule_enumerator1", :next_occurrence => 3, :bounded? => true)
162
- @enum2 = mock("rrule_enumerator2", :next_occurrence => 2, :bounded? => true)
165
+ @enum1 = mock_enumerator("rrule_enumerator1",3)
166
+ @enum2 = mock_enumerator("rrule_enumerator2", 2)
163
167
  @rrule1 = mock("rrule", :enumerator => @enum1)
164
168
  @rrule2 = mock("rrule", :enumerator => @enum2)
165
169
  @it = @merger.new(0, [@rrule1, @rrule2])
@@ -188,8 +192,8 @@ describe RiCal::OccurrenceEnumerator::OccurrenceMerger do
188
192
 
189
193
  describe "with duplicated nexts" do
190
194
  before(:each) do
191
- @enum1 = mock("rrule_enumerator1", :next_occurrence => 2, :bounded? => true)
192
- @enum2 = mock("rrule_enumerator2", :next_occurrence => 2, :bounded? => true)
195
+ @enum1 = mock_enumerator("rrule_enumerator1", 2)
196
+ @enum2 = mock_enumerator("rrule_enumerator2", 2)
193
197
  @rrule1 = mock("rrule", :enumerator => @enum1)
194
198
  @rrule2 = mock("rrule", :enumerator => @enum2)
195
199
  @it = @merger.new(0, [@rrule1, @rrule2])
@@ -216,8 +220,8 @@ describe RiCal::OccurrenceEnumerator::OccurrenceMerger do
216
220
 
217
221
  describe "with all enumerators at end" do
218
222
  before(:each) do
219
- @enum1 = mock("rrule_enumerator1", :next_occurrence => nil, :bounded? => true)
220
- @enum2 = mock("rrule_enumerator2", :next_occurrence => nil, :bounded? => true)
223
+ @enum1 = mock_enumerator("rrule_enumerator1", nil)
224
+ @enum2 = mock_enumerator("rrule_enumerator2", nil)
221
225
  @rrule1 = mock("rrule", :enumerator => @enum1)
222
226
  @rrule2 = mock("rrule", :enumerator => @enum2)
223
227
  @it = @merger.new(0, [@rrule1, @rrule2])
@@ -284,7 +288,49 @@ ENDCAL
284
288
  lambda {@event.occurrences}.should_not raise_error
285
289
  end
286
290
  end
287
-
291
+
292
+ context "Lighthouse bug #3" do
293
+ before(:each) do
294
+ cals = RiCal.parse_string <<ENDCAL
295
+ BEGIN:VCALENDAR
296
+ VERSION:2.0
297
+ PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
298
+ BEGIN:VTIMEZONE
299
+ TZID:/mozilla.org/20070129_1/Europe/Paris
300
+ X-LIC-LOCATION:Europe/Paris
301
+ BEGIN:DAYLIGHT
302
+ TZOFFSETFROM:+0100
303
+ TZOFFSETTO:+0200
304
+ TZNAME:CEST
305
+ DTSTART:19700329T020000
306
+ RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
307
+ END:DAYLIGHT
308
+ BEGIN:STANDARD
309
+ TZOFFSETFROM:+0200
310
+ TZOFFSETTO:+0100
311
+ TZNAME:CET
312
+ DTSTART:19701025T030000
313
+ RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
314
+ END:STANDARD
315
+ END:VTIMEZONE
316
+ BEGIN:VEVENT
317
+ CREATED:20070606T141629Z
318
+ LAST-MODIFIED:20070606T154611Z
319
+ DTSTAMP:20070607T120859Z
320
+ UID:5d1ae55f-3910-4de9-8b65-d652768fb2f2
321
+ SUMMARY:Lundi de Pâques
322
+ DTSTART;VALUE=DATE;TZID=/mozilla.org/20070129_1/Europe/Paris:20070409
323
+ DTEND;VALUE=DATE;TZID=/mozilla.org/20070129_1/Europe/Paris:20070410
324
+ CATEGORIES:Jours fériés
325
+ END:VEVENT
326
+ END:VCALENDAR
327
+ ENDCAL
328
+ @event = cals.first.events.first
329
+ end
330
+
331
+ it "should be able to enumerate occurrences" do
332
+ @event.occurrences.should == [@event]
333
+ end
334
+ end
335
+
288
336
  end
289
-
290
-
@@ -3,19 +3,51 @@
3
3
  require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
4
4
 
5
5
  describe RiCal::PropertyValue::Date do
6
- describe ".advance" do
6
+ context ".advance" do
7
7
  it "should advance by one week if passed :days => 7" do
8
8
  dt1 = RiCal::PropertyValue::Date.new(nil, :value => "20050131")
9
9
  dt2 = RiCal::PropertyValue::Date.new(nil, :value => "20050207")
10
10
  dt1.advance(:days => 7).should == dt2
11
11
  end
12
-
13
- describe ".==" do
12
+
13
+ context ".==" do
14
14
  it "should return true for two instances representing the same date" do
15
15
  dt1 = RiCal::PropertyValue::Date.new(nil, :value => DateTime.parse("20050131T010000"))
16
16
  dt2 = RiCal::PropertyValue::Date.new(nil, :value => DateTime.parse("20050131T010001"))
17
- dt1.should == dt2
17
+ dt1.should == dt2
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ context ".-" do
23
+
24
+ it "should return a Duration property when the argument is also a Date property" do
25
+ dt1 = RiCal::PropertyValue::Date.new(nil, :value => DateTime.parse("20090519"))
26
+ dt2 = RiCal::PropertyValue::Date.new(nil, :value => DateTime.parse("20090518"))
27
+ (dt1 - dt2).should == RiCal::PropertyValue::Duration.new(nil, :value => "+P1D")
28
+ end
29
+
30
+ it "should return a Duration property when the argument is a DateTime property" do
31
+ dt1 = RiCal::PropertyValue::Date.new(nil, :value => DateTime.parse("20090519"))
32
+ dt2 = RiCal::PropertyValue::DateTime.new(nil, :value => DateTime.parse("20090518T120000"))
33
+ (dt1 - dt2).should == RiCal::PropertyValue::Duration.new(nil, :value => "+PT12H")
34
+ end
35
+
36
+ it "should return a DateTime property when the argument is a Duration Property" do
37
+ dt1 = RiCal::PropertyValue::Date.new(nil, :value => "19980119")
38
+ duration = RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
39
+ @it = dt1 - duration
40
+ @it.should == RiCal::PropertyValue::DateTime.new(nil, :value => "19980118T220000")
41
+ end
42
+ end
43
+
44
+ context ".+" do
45
+
46
+ it "should return a DateTime property when the argument is a Duration Property" do
47
+ dt1 = RiCal::PropertyValue::Date.new(nil, :value => "19980119")
48
+ duration = RiCal::PropertyValue::Duration.new(nil, :value => "+PT2H")
49
+ @it = dt1 + duration
50
+ @it.should == RiCal::PropertyValue::DateTime.new(nil, :value => "19980119T020000")
51
+ end
52
+ end
21
53
  end
@@ -4,8 +4,8 @@ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
4
4
  require 'date'
5
5
 
6
6
  describe RiCal::PropertyValue::Duration do
7
-
8
- describe "with various values" do
7
+
8
+ context "with various values" do
9
9
  def value_expectations(dv, values = {})
10
10
  values = {:weeks => 0, :days => 0, :hours => 0, :minutes => 0, :seconds => 0}.merge(values)
11
11
  dv.weeks.should == values[:weeks]
@@ -14,77 +14,113 @@ describe RiCal::PropertyValue::Duration do
14
14
  dv.minutes.should == values[:minutes]
15
15
  dv.seconds.should == values[:seconds]
16
16
  end
17
-
17
+
18
18
  it ".+P7W should have represent 7 weeks" do
19
19
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+P7W"), :weeks => 7)
20
20
  end
21
-
21
+
22
22
  it ".P15DT5H0M20S should have represent 15 days, 5 hours and 20 seconds" do
23
23
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "P15DT5H0M20S"), :days => 15, :hours => 5, :seconds => 20)
24
24
  end
25
-
25
+
26
26
  it ".+P2D should have represent 2 days" do
27
27
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+P2D"), :days => 2)
28
28
  end
29
-
29
+
30
30
  it ".+PT3H should have represent 3 hours" do
31
31
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT3H"), :hours => 3)
32
32
  end
33
-
33
+
34
34
  it ".+PT15M should have represent 15 minutes" do
35
35
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT15M"), :minutes => 15)
36
36
  end
37
-
37
+
38
38
  it ".+PT45S should have represent 45 seconds" do
39
39
  value_expectations(RiCal::PropertyValue::Duration.new(nil, :value => "+PT45S"), :seconds => 45)
40
40
  end
41
41
  end
42
-
43
- describe ".from_datetimes" do
44
-
45
- describe "starting at 11:00 pm, and ending at 1:01:02 am the next day" do
42
+
43
+ context ".==" do
44
+ it "should return true for two durations of one day" do
45
+ RiCal::PropertyValue.new(nil, :value => "+P1D").should == RiCal::PropertyValue.new(nil, :value => "+P1D")
46
+ end
47
+ end
48
+
49
+ context ".from_datetimes" do
50
+
51
+ context "starting at 11:00 pm, and ending at 1:01:02 am the next day" do
46
52
  before(:each) do
47
- @it = RiCal::PropertyValue::Duration.from_datetimes(nil,
48
- DateTime.parse("Sep 1, 2008 23:00"),
49
- DateTime.parse("Sep 2, 2008 1:01:02")
50
- )
53
+ @it = RiCal::PropertyValue::Duration.from_datetimes(nil,
54
+ DateTime.parse("Sep 1, 2008 23:00"),
55
+ DateTime.parse("Sep 2, 2008 1:01:02")
56
+ )
51
57
  end
52
58
 
53
59
  it "should produce a duration" do
54
60
  @it.class.should == RiCal::PropertyValue::Duration
55
61
  end
56
-
62
+
57
63
  it "should have a value of '+P2H1M2S'" do
58
64
  @it.value.should == '+PT2H1M2S'
59
65
  end
60
-
66
+
61
67
  it "should contain zero days" do
62
68
  @it.days.should == 0
63
69
  end
64
-
70
+
65
71
  it "should contain two hours" do
66
72
  @it.hours.should == 2
67
73
  end
68
-
74
+
69
75
  it "should contain one minute" do
70
76
  @it.minutes.should == 1
71
77
  end
72
-
78
+
73
79
  it "should contain one minute" do
74
80
  @it.minutes.should == 1
75
81
  end
76
82
  end
77
- end
78
-
79
- describe ".from_datetimes" do
83
+
84
+ context "starting at 00:00, and ending at 00:00 the next day" do
85
+ before(:each) do
86
+ @it = RiCal::PropertyValue::Duration.from_datetimes(nil,
87
+ DateTime.parse("Sep 1, 2008 00:00"),
88
+ DateTime.parse("Sep 2, 2008 00:00")
89
+ )
90
+ end
91
+
92
+ it "should produce a duration" do
93
+ @it.class.should == RiCal::PropertyValue::Duration
94
+ end
95
+
96
+ it "should have a value of '+P1D'" do
97
+ @it.value.should == '+P1D'
98
+ end
99
+
100
+ it "should contain zero days" do
101
+ @it.days.should == 1
102
+ end
103
+
104
+ it "should contain zero hours" do
105
+ @it.hours.should == 0
106
+ end
107
+
108
+ it "should contain zero minutes" do
109
+ @it.minutes.should == 0
110
+ end
111
+
112
+ it "should contain zero minutes" do
113
+ @it.minutes.should == 0
114
+ end
115
+ end
116
+
80
117
  it "should work when start > finish" do
81
118
  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)
119
+ RiCal::PropertyValue::Duration.from_datetimes(nil,
120
+ DateTime.parse("Sep 2, 2008 1:01:02"),
121
+ DateTime.parse("Sep 1, 2008 23:00")
122
+ )
123
+ }.should_not raise_error(ArgumentError)
124
+ end
87
125
  end
88
- end
89
-
90
- end
126
+ end
data/tasks/spec.rake CHANGED
@@ -18,6 +18,7 @@ desc "Run all specs"
18
18
  Spec::Rake::SpecTask.new do |t|
19
19
  t.spec_opts = ['--options', "spec/spec.opts"]
20
20
  t.spec_files = FileList['spec/**/*_spec.rb']
21
+ t.ruby_opts << "-rubygems"
21
22
  end
22
23
 
23
24
  namespace :spec do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyredrick-ri_cal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - author=Rick DeNatale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -07:00
12
+ date: 2009-05-19 00:00:00 -07:00
13
13
  default_executable: ri_cal
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -171,10 +171,10 @@ files:
171
171
  - spec/ri_cal_spec.rb
172
172
  - spec/spec.opts
173
173
  - spec/spec_helper.rb
174
- - tasks/ri_cal.rake
175
- - tasks/spec.rake
176
174
  - tasks/gem_loader/load_active_support.rb
177
175
  - tasks/gem_loader/load_tzinfo_gem.rb
176
+ - tasks/ri_cal.rake
177
+ - tasks/spec.rake
178
178
  has_rdoc: true
179
179
  homepage: http://rical.rubyforge.org/
180
180
  post_install_message: