friflaj_ri_cal 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +26 -0
  4. data/History.txt +408 -0
  5. data/README.rdoc +407 -0
  6. data/Rakefile +9 -0
  7. data/component_attributes/alarm.yml +10 -0
  8. data/component_attributes/calendar.yml +4 -0
  9. data/component_attributes/component_property_defs.yml +180 -0
  10. data/component_attributes/event.yml +45 -0
  11. data/component_attributes/freebusy.yml +16 -0
  12. data/component_attributes/journal.yml +35 -0
  13. data/component_attributes/timezone.yml +3 -0
  14. data/component_attributes/timezone_period.yml +11 -0
  15. data/component_attributes/todo.yml +46 -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/docs/test.ics +38 -0
  21. data/lib/ri_cal.rb +184 -0
  22. data/lib/ri_cal/component.rb +254 -0
  23. data/lib/ri_cal/component/alarm.rb +17 -0
  24. data/lib/ri_cal/component/calendar.rb +255 -0
  25. data/lib/ri_cal/component/event.rb +56 -0
  26. data/lib/ri_cal/component/freebusy.rb +14 -0
  27. data/lib/ri_cal/component/journal.rb +25 -0
  28. data/lib/ri_cal/component/non_standard.rb +31 -0
  29. data/lib/ri_cal/component/t_z_info_timezone.rb +155 -0
  30. data/lib/ri_cal/component/timezone.rb +195 -0
  31. data/lib/ri_cal/component/timezone/daylight_period.rb +23 -0
  32. data/lib/ri_cal/component/timezone/standard_period.rb +21 -0
  33. data/lib/ri_cal/component/timezone/timezone_period.rb +74 -0
  34. data/lib/ri_cal/component/todo.rb +39 -0
  35. data/lib/ri_cal/core_extensions.rb +7 -0
  36. data/lib/ri_cal/core_extensions/array.rb +16 -0
  37. data/lib/ri_cal/core_extensions/date.rb +63 -0
  38. data/lib/ri_cal/core_extensions/date_time.rb +58 -0
  39. data/lib/ri_cal/core_extensions/object.rb +21 -0
  40. data/lib/ri_cal/core_extensions/string.rb +58 -0
  41. data/lib/ri_cal/core_extensions/time.rb +50 -0
  42. data/lib/ri_cal/core_extensions/time/calculations.rb +150 -0
  43. data/lib/ri_cal/core_extensions/time/tzid_access.rb +47 -0
  44. data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +52 -0
  45. data/lib/ri_cal/fast_date_time.rb +247 -0
  46. data/lib/ri_cal/floating_timezone.rb +29 -0
  47. data/lib/ri_cal/invalid_property_value.rb +5 -0
  48. data/lib/ri_cal/invalid_timezone_identifier.rb +17 -0
  49. data/lib/ri_cal/occurrence_enumerator.rb +262 -0
  50. data/lib/ri_cal/occurrence_period.rb +17 -0
  51. data/lib/ri_cal/parser.rb +142 -0
  52. data/lib/ri_cal/properties.rb +12 -0
  53. data/lib/ri_cal/properties/alarm.rb +387 -0
  54. data/lib/ri_cal/properties/calendar.rb +161 -0
  55. data/lib/ri_cal/properties/event.rb +1520 -0
  56. data/lib/ri_cal/properties/freebusy.rb +590 -0
  57. data/lib/ri_cal/properties/journal.rb +1234 -0
  58. data/lib/ri_cal/properties/timezone.rb +147 -0
  59. data/lib/ri_cal/properties/timezone_period.rb +413 -0
  60. data/lib/ri_cal/properties/todo.rb +1556 -0
  61. data/lib/ri_cal/property_value.rb +157 -0
  62. data/lib/ri_cal/property_value/array.rb +25 -0
  63. data/lib/ri_cal/property_value/cal_address.rb +9 -0
  64. data/lib/ri_cal/property_value/date.rb +182 -0
  65. data/lib/ri_cal/property_value/date_time.rb +357 -0
  66. data/lib/ri_cal/property_value/date_time/additive_methods.rb +42 -0
  67. data/lib/ri_cal/property_value/date_time/time_machine.rb +157 -0
  68. data/lib/ri_cal/property_value/date_time/timezone_support.rb +98 -0
  69. data/lib/ri_cal/property_value/duration.rb +108 -0
  70. data/lib/ri_cal/property_value/geo.rb +9 -0
  71. data/lib/ri_cal/property_value/integer.rb +10 -0
  72. data/lib/ri_cal/property_value/occurrence_list.rb +142 -0
  73. data/lib/ri_cal/property_value/period.rb +84 -0
  74. data/lib/ri_cal/property_value/recurrence_rule.rb +152 -0
  75. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +98 -0
  76. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +77 -0
  77. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +146 -0
  78. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +51 -0
  79. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +29 -0
  80. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb +133 -0
  81. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb +84 -0
  82. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb +29 -0
  83. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb +30 -0
  84. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb +50 -0
  85. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb +29 -0
  86. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb +36 -0
  87. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb +30 -0
  88. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb +67 -0
  89. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb +29 -0
  90. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb +26 -0
  91. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb +78 -0
  92. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb +21 -0
  93. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb +104 -0
  94. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb +21 -0
  95. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb +31 -0
  96. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb +41 -0
  97. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb +26 -0
  98. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb +35 -0
  99. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb +55 -0
  100. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +129 -0
  101. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +62 -0
  102. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +31 -0
  103. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +51 -0
  104. data/lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb +40 -0
  105. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +123 -0
  106. data/lib/ri_cal/property_value/text.rb +42 -0
  107. data/lib/ri_cal/property_value/uri.rb +9 -0
  108. data/lib/ri_cal/property_value/utc_offset.rb +31 -0
  109. data/lib/ri_cal/property_value/zulu_date_time.rb +32 -0
  110. data/lib/ri_cal/required_timezones.rb +53 -0
  111. data/lib/ri_cal/version.rb +3 -0
  112. data/parked_specs/ri_cal/claudio_a_bug_spec.rb +98 -0
  113. data/performance/empty_propval/subject.rb +43 -0
  114. data/performance/paris_eastern/subject.rb +90 -0
  115. data/performance/penultimate_weekday/subject.rb +15 -0
  116. data/performance/psm_big_enum/ical.ics +3171 -0
  117. data/performance/psm_big_enum/subject.rb +16 -0
  118. data/performance/utah_cycling/subject.rb +55 -0
  119. data/performance_data/benchmarks.out +48 -0
  120. data/performance_data/empty_propval.calltree +45650 -0
  121. data/performance_data/paris_eastern.calltree +103058 -0
  122. data/performance_data/penultimate_weekday.calltree +48686 -0
  123. data/performance_data/psm_big_enum.calltree +225814 -0
  124. data/performance_data/utah_cycling.calltree +117950 -0
  125. data/ri_cal.gemspec +35 -0
  126. data/script/benchmark_subject +23 -0
  127. data/script/console +10 -0
  128. data/script/destroy +14 -0
  129. data/script/generate +14 -0
  130. data/script/profile_subject +29 -0
  131. data/script/txt2html +71 -0
  132. data/spec/ri_cal/bugreports_spec.rb +281 -0
  133. data/spec/ri_cal/component/alarm_spec.rb +10 -0
  134. data/spec/ri_cal/component/calendar_spec.rb +87 -0
  135. data/spec/ri_cal/component/event_spec.rb +734 -0
  136. data/spec/ri_cal/component/freebusy_spec.rb +10 -0
  137. data/spec/ri_cal/component/journal_spec.rb +35 -0
  138. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +63 -0
  139. data/spec/ri_cal/component/timezone_spec.rb +233 -0
  140. data/spec/ri_cal/component/todo_spec.rb +110 -0
  141. data/spec/ri_cal/component_spec.rb +225 -0
  142. data/spec/ri_cal/core_extensions/string/conversions_spec.rb +76 -0
  143. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +186 -0
  144. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +43 -0
  145. data/spec/ri_cal/fast_date_time_spec.rb +75 -0
  146. data/spec/ri_cal/inf_loop_spec.rb +75 -0
  147. data/spec/ri_cal/occurrence_enumerator_spec.rb +610 -0
  148. data/spec/ri_cal/parser_spec.rb +335 -0
  149. data/spec/ri_cal/property_value/date_spec.rb +51 -0
  150. data/spec/ri_cal/property_value/date_time_spec.rb +380 -0
  151. data/spec/ri_cal/property_value/duration_spec.rb +123 -0
  152. data/spec/ri_cal/property_value/occurrence_list_spec.rb +70 -0
  153. data/spec/ri_cal/property_value/period_spec.rb +61 -0
  154. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +19 -0
  155. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1810 -0
  156. data/spec/ri_cal/property_value/text_spec.rb +23 -0
  157. data/spec/ri_cal/property_value/utc_offset_spec.rb +46 -0
  158. data/spec/ri_cal/property_value_spec.rb +123 -0
  159. data/spec/ri_cal/required_timezones_spec.rb +63 -0
  160. data/spec/ri_cal_spec.rb +50 -0
  161. data/spec/spec_helper.rb +35 -0
  162. data/tasks/ri_cal.rake +400 -0
  163. data/tasks/spec.rake +26 -0
  164. metadata +260 -0
@@ -0,0 +1,84 @@
1
+ module RiCal
2
+ class PropertyValue
3
+ # RiCal::PropertyValue::CalAddress represents an icalendar Period property value
4
+ # which is defined in
5
+ # rfc 2445 section 4.3.9 p 39
6
+ #
7
+ # Known bugs. This doesn't properly work when dtstart, dtend or duration are changed independently
8
+ class Period < PropertyValue
9
+
10
+ # The DATE-TIME on which the period starts
11
+ attr_accessor :dtstart
12
+ # The DATE-TIME on which the period ends
13
+ attr_accessor :dtend
14
+ # The DURATION of the period
15
+ attr_accessor :duration
16
+
17
+ def value=(string) # :nodoc:
18
+ starter, terminator = *string.split("/")
19
+ self.dtstart = PropertyValue::DateTime.new(self, :value => starter)
20
+ if /P/ =~ terminator
21
+ self.duration = PropertyValue::Duration.new(self, :value => terminator)
22
+ self.dtend = dtstart + duration
23
+ else
24
+ self.dtend = PropertyValue::DateTime.new(self, :value => terminator)
25
+ self.duration = PropertyValue::Duration.from_datetimes(self, dtstart.to_datetime, dtend.to_datetime)
26
+ end
27
+ @value = string
28
+ end
29
+
30
+ def ruby_value
31
+ self
32
+ end
33
+
34
+ def self.valid_string?(string) # :nodoc:
35
+ return false unless string.include?("/")
36
+ starter, terminator = *string.split("/")
37
+ return false unless PropertyValue::DateTime.valid_string?(starter)
38
+ if /P/ =~ terminator
39
+ return false unless PropertyValue::Duration.valid_string?(terminator)
40
+ else
41
+ return false unless PropertyValue::DateTime.valid_string?(terminator)
42
+ end
43
+ true
44
+ end
45
+
46
+ # Nop to allow occurrence list to try to set it
47
+ def tzid=(val)#:nodoc:
48
+ end
49
+
50
+ def tzid #:nodoc:
51
+ nil
52
+ end
53
+
54
+ def for_parent(parent) #:nodoc:
55
+ if timezone_finder.nil
56
+ @timezone_finder = parent
57
+ self
58
+ elsif timezone_finder == parent
59
+ self
60
+ else
61
+ Period.new(parent, :value => value)
62
+ end
63
+ end
64
+
65
+ def self.convert(parent, ruby_object) # :nodoc:
66
+ ruby_object.to_ri_cal_period_value.for_parent(parent)
67
+ end
68
+
69
+ # return the receiver
70
+ def to_ri_cal_period_value
71
+ self
72
+ end
73
+
74
+ def occurrence_period(default_duration) #:nodoc:
75
+ RiCal::OccurrencePeriod.new(self, (default_duration ? self + default_duration : nil))
76
+ end
77
+
78
+ def add_date_times_to(required_timezones) #:nodoc:
79
+ dtstart.add_date_times_to(required_timezones)
80
+ dtend.add_date_times_to(required_timezones)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,152 @@
1
+ module RiCal
2
+ class PropertyValue
3
+ # RiCal::PropertyValue::RecurrenceRule represents an icalendar Recurrence Rule property value
4
+ # which is defined in
5
+ # rfc 2445 section 4.3.10 pp 40-45
6
+ class RecurrenceRule < PropertyValue
7
+
8
+ autoload :EnumerationSupportMethods, "ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb"
9
+ autoload :OccurrenceIncrementer, "ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb"
10
+ autoload :Enumerator, "ri_cal/property_value/recurrence_rule/enumerator.rb"
11
+ autoload :InitializationMethods, "ri_cal/property_value/recurrence_rule/initialization_methods.rb"
12
+ autoload :NegativeSetposEnumerator, "ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb"
13
+ autoload :NumberedSpan, "ri_cal/property_value/recurrence_rule/numbered_span.rb"
14
+ autoload :RecurringDay, "ri_cal/property_value/recurrence_rule/recurring_day.rb"
15
+ autoload :RecurringMonthDay, "ri_cal/property_value/recurrence_rule/recurring_month_day.rb"
16
+ autoload :RecurringNumberedWeek, "ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb"
17
+ autoload :RecurringYearDay, "ri_cal/property_value/recurrence_rule/recurring_year_day.rb"
18
+ autoload :TimeManipulation, "ri_cal/property_value/recurrence_rule/time_manipulation.rb"
19
+ autoload :Validations, "ri_cal/property_value/recurrence_rule/validations.rb"
20
+
21
+ def initialize(parent, value_hash) # :nodoc:
22
+ @by_list_hash = {}
23
+ super
24
+ init_by_lists
25
+ @by_list_hash = nil
26
+ end
27
+
28
+ def self.convert(parent, value) #:nodoc:
29
+ if String === value
30
+ result = new(parent, :value => value)
31
+ else
32
+ result = new(parent, value)
33
+ end
34
+ result
35
+ end
36
+
37
+ include Validations
38
+ include InitializationMethods
39
+ include EnumerationSupportMethods
40
+
41
+ # The integer count value of the receiver, or nil
42
+ attr_reader :count
43
+ # The DATE-TIME value of until limit of the receiver, or nil
44
+ attr_reader :until
45
+
46
+ def value=(string) # :nodoc:
47
+ if string
48
+ @value = string
49
+ dup_hash = {}
50
+ string.split(";").each do |value_part|
51
+ initialize_from_value_part(value_part, dup_hash)
52
+ end
53
+ end
54
+ end
55
+
56
+ # Set the frequency of the recurrence rule
57
+ # freq_value:: a String which should be in %w[SECONDLY MINUTELY HOURLY DAILY WEEKLY MONTHLY YEARLY]
58
+ #
59
+ # This method resets the receivers list of errors
60
+ def freq=(freq_value)
61
+ reset_errors
62
+ @freq = freq_value
63
+ end
64
+
65
+ # return the frequency of the rule which will be a string
66
+ def freq
67
+ @freq.upcase
68
+ end
69
+
70
+ # return the starting week day for the recurrence rule, which for a valid instance will be one of
71
+ # "SU", "MO", "TU", "WE", "TH", "FR", or "SA"
72
+ def wkst
73
+ @wkst || 'MO'
74
+ end
75
+
76
+ def wkst_day # :nodoc:
77
+ @wkst_day ||= (%w{SU MO TU WE TH FR SA}.index(wkst) || 1)
78
+ end
79
+
80
+ # Set the starting week day for the recurrence rule, which should be one of
81
+ # "SU", "MO", "TU", "WE", "TH", "FR", or "SA" for the instance to be valid.
82
+ # The parameter is however case-insensitive.
83
+ #
84
+ # This method resets the receivers list of errors
85
+ def wkst=(value)
86
+ reset_errors
87
+ @wkst = value
88
+ @wkst_day = nil
89
+ end
90
+
91
+ # Set the count parameter of the recurrence rule, the count value will be converted to an integer using to_i
92
+ #
93
+ # This method resets the receivers list of errors
94
+
95
+ def count=(count_value)
96
+ reset_errors
97
+ @count = count_value
98
+ @until = nil unless @count.nil? || @by_list_hash
99
+ end
100
+
101
+ # Set the until parameter of the recurrence rule
102
+ #
103
+ # until_value:: the value to be set, this may be either a string in RFC 2446 Date or DateTime value format
104
+ # Or a Date, Time, DateTime, RiCal::PropertyValue::Date, or RiCal::PropertyValue::DateTime
105
+ #
106
+ def until=(until_value)
107
+ reset_errors
108
+ @until = until_value && until_value.to_ri_cal_date_or_date_time_value(timezone_finder)
109
+ @count = nil unless @count.nil? || @by_list_hash
110
+ end
111
+
112
+ # return the INTERVAL parameter of the recurrence rule
113
+ # This returns an Integer
114
+ def interval
115
+ @interval ||= 1
116
+ end
117
+
118
+ # Set the INTERVAL parameter of the recurrence rule
119
+ #
120
+ # interval_value:: an Integer
121
+ #
122
+ # This method resets the receivers list of errors
123
+ def interval=(interval_value)
124
+ reset_errors
125
+ @interval = interval_value
126
+ end
127
+
128
+ def value #:nodoc:
129
+ @value || to_ical
130
+ end
131
+
132
+ # Return a string containing the RFC 2445 representation of the recurrence rule
133
+ def to_ical
134
+ result = ["FREQ=#{freq}"]
135
+ result << "INTERVAL=#{interval}" unless interval == 1
136
+ result << "COUNT=#{count}" if count
137
+ result << "UNTIL=#{self.until.value}" if self.until
138
+ %w{bysecond byminute byhour byday bymonthday byyearday byweekno bymonth bysetpos}.each do |by_part|
139
+ val = by_list[by_part.to_sym]
140
+ result << "#{by_part.upcase}=#{[val].flatten.join(',')}" if val
141
+ end
142
+ result << "WKST=#{wkst}" unless wkst == "MO"
143
+ result.join(";")
144
+ end
145
+
146
+ # Predicate to determine if the receiver generates a bounded or infinite set of occurrences
147
+ def bounded?
148
+ @count || @until
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,98 @@
1
+ module RiCal
2
+ class PropertyValue
3
+ class RecurrenceRule < PropertyValue
4
+ module EnumerationSupportMethods # :nodoc:
5
+
6
+ # if the recurrence rule has a bysetpos part we need to search starting with the
7
+ # first time in the frequency period containing the start time specified by DTSTART
8
+ def adjust_start(start_time) # :nodoc:
9
+ if by_list[:bysetpos]
10
+ case freq
11
+ when "SECONDLY"
12
+ start_time
13
+ when "MINUTELY"
14
+ start_time.change(:seconds => 0)
15
+ when "HOURLY"
16
+ start_time.change(
17
+ :minutes => 0,
18
+ :seconds => start_time.sec
19
+ )
20
+ when "DAILY"
21
+ start_time.change(
22
+ :hour => 0,
23
+ :minutes => start_time.min,
24
+ :seconds => start_time.sec
25
+ )
26
+ when "WEEKLY"
27
+ start_of_week(time)
28
+ when "MONTHLY"
29
+ start_time.change(
30
+ :day => 1,
31
+ :hour => start_time.hour,
32
+ :minutes => start_time.min,
33
+ :seconds => start_time.sec
34
+ )
35
+ when "YEARLY"
36
+ start_time.change(
37
+ :month => 1,
38
+ :day => start_time.day,
39
+ :hour => start_time.hour,
40
+ :minutes => start_time.min,
41
+ :seconds => start_time.sec
42
+ )
43
+ end
44
+ else
45
+ start_time
46
+ end
47
+ end
48
+
49
+ def enumerator(component) # :nodoc:
50
+ Enumerator.for(self, component, by_list[:bysetpos])
51
+ end
52
+
53
+ def exhausted?(count, time) # :nodoc:
54
+ (@count && count > @count) || (@until && (time > @until))
55
+ end
56
+
57
+ def in_same_set?(time1, time2) # :nodoc:
58
+ case freq
59
+ when "SECONDLY"
60
+ [time1.year, time1.month, time1.day, time1.hour, time1.min, time1.sec] ==
61
+ [time2.year, time2.month, time2.day, time2.hour, time2.min, time2.sec]
62
+ when "MINUTELY"
63
+ [time1.year, time1.month, time1.day, time1.hour, time1.min] ==
64
+ [time2.year, time2.month, time2.day, time2.hour, time2.min]
65
+ when "HOURLY"
66
+ [time1.year, time1.month, time1.day, time1.hour] ==
67
+ [time2.year, time2.month, time2.day, time2.hour]
68
+ when "DAILY"
69
+ [time1.year, time1.month, time1.day] ==
70
+ [time2.year, time2.month, time2.day]
71
+ when "WEEKLY"
72
+ sow1 = start_of_week(time1)
73
+ sow2 = start_of_week(time2)
74
+ [sow1.year, sow1.month, sow1.day] ==
75
+ [sow2.year, sow2.month, sow2.day]
76
+ when "MONTHLY"
77
+ [time1.year, time1.month] ==
78
+ [time2.year, time2.month]
79
+ when "YEARLY"
80
+ time1.year == time2.year
81
+ end
82
+ end
83
+
84
+ def by_rule_list(which) # :nodoc:
85
+ if @by_list
86
+ @by_list[which]
87
+ else
88
+ nil
89
+ end
90
+ end
91
+
92
+ def incrementer_from_start_time(start_time)
93
+ RecurrenceRule::OccurrenceIncrementer.from_rrule(self, start_time)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,77 @@
1
+ module RiCal
2
+ class PropertyValue
3
+ class RecurrenceRule < PropertyValue
4
+ class Enumerator # :nodoc:
5
+ # base_time gets changed everytime the time is updated by the recurrence rule's frequency
6
+ attr_accessor :start_time, :duration, :next_time, :recurrence_rule, :base_time
7
+ def initialize(recurrence_rule, component, setpos_list)
8
+ self.recurrence_rule = recurrence_rule
9
+ self.start_time = component.default_start_time
10
+ self.duration = component.default_duration
11
+ self.next_time = recurrence_rule.adjust_start(self.start_time)
12
+ self.base_time = next_time
13
+ @bounded = recurrence_rule.bounded?
14
+ @count = 0
15
+ @setpos_list = setpos_list
16
+ @setpos = 1
17
+ @next_occurrence_count = 0
18
+ @incrementer = recurrence_rule.incrementer_from_start_time(start_time)
19
+ end
20
+
21
+ def self.for(recurrence_rule, component, setpos_list) # :nodoc:
22
+ if !setpos_list || setpos_list.all? {|setpos| setpos > 1}
23
+ self.new(recurrence_rule, component, setpos_list)
24
+ else
25
+ NegativeSetposEnumerator.new(recurrence_rule, component, setpos_list)
26
+ end
27
+ end
28
+
29
+ def empty?
30
+ false
31
+ end
32
+
33
+ def bounded?
34
+ @bounded
35
+ end
36
+
37
+ def result_occurrence_period(date_time_value)
38
+ RiCal::OccurrencePeriod.new(date_time_value, nil)
39
+ end
40
+
41
+ def result_passes_setpos_filter?(result)
42
+ result_setpos = @setpos
43
+ if recurrence_rule.in_same_set?(result, next_time)
44
+ @setpos += 1
45
+ else
46
+ @setpos = 1
47
+ end
48
+ if (result == start_time) || (result > start_time && @setpos_list.include?(result_setpos))
49
+ return true
50
+ else
51
+ return false
52
+ end
53
+ end
54
+
55
+ def result_passes_filters?(result)
56
+ if @setpos_list
57
+ result_passes_setpos_filter?(result)
58
+ else
59
+ result >= start_time
60
+ end
61
+ end
62
+
63
+ def next_occurrence
64
+ while true
65
+ @next_occurrence_count += 1
66
+ result = next_time
67
+ self.next_time = @incrementer.next_time(result)
68
+ if result_passes_filters?(result)
69
+ @count += 1
70
+ return recurrence_rule.exhausted?(@count, result) ? nil : result_occurrence_period(result)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,146 @@
1
+ module RiCal
2
+ class PropertyValue
3
+ class RecurrenceRule < PropertyValue
4
+ module InitializationMethods # :nodoc:
5
+
6
+ attr_reader :by_day_scope
7
+
8
+ def add_to_options_hash(options_hash, key, value)
9
+ options_hash[key] = value if value
10
+ options_hash
11
+ end
12
+
13
+ def add_byrule_strings_to_options_hash(options_hash, key)
14
+ if (rules = by_list[key])
15
+ if rules.length == 1
16
+ options_hash[key] = rules.first.source
17
+ else
18
+ options_hash[key] = rules.map {|rule| rule.source}
19
+ end
20
+ end
21
+ end
22
+
23
+ def to_options_hash
24
+ options_hash = {:freq => freq, :interval => interval}
25
+ options_hash[:params] = params unless params.empty?
26
+ add_to_options_hash(options_hash, :count, @count)
27
+ add_to_options_hash(options_hash, :until, @until)
28
+ add_to_options_hash(options_hash, :interval, @interval)
29
+ [:bysecond, :byminute, :byhour, :bymonth, :bysetpos].each do |bypart|
30
+ add_to_options_hash(options_hash, bypart, by_list[bypart])
31
+ end
32
+ [:byday, :bymonthday, :byyearday, :byweekno].each do |bypart|
33
+ add_byrule_strings_to_options_hash(options_hash, bypart)
34
+ end
35
+ options_hash
36
+ end
37
+
38
+ def initialize_from_value_part(part, dup_hash) # :nodoc:
39
+ part_name, value = part.split("=")
40
+ attribute = part_name.downcase
41
+ errors << "Repeated rule part #{attribute} last occurrence was used" if dup_hash[attribute]
42
+ case attribute
43
+ when "freq"
44
+ self.freq = value
45
+ when "wkst"
46
+ self.wkst = value
47
+ when "until"
48
+ @until = PropertyValue.date_or_date_time(self, :value => value)
49
+ when "count"
50
+ @count = value.to_i
51
+ when "interval"
52
+ self.interval = value.to_i
53
+ when "bysecond", "byminute", "byhour", "bymonthday", "byyearday", "byweekno", "bymonth", "bysetpos"
54
+ send("#{attribute}=", value.split(",").map {|int| int.to_i})
55
+ when "byday"
56
+ self.byday = value.split(",")
57
+ else
58
+ errors << "Invalid rule part #{part}"
59
+ end
60
+ end
61
+
62
+ def by_list
63
+ @by_list ||= {}
64
+ end
65
+
66
+ def calc_by_day_scope
67
+ case freq
68
+ when "YEARLY"
69
+ scope = :yearly
70
+ when "MONTHLY"
71
+ scope = :monthly
72
+ when "WEEKLY"
73
+ scope = :weekly
74
+ else
75
+ scope = :daily
76
+ end
77
+ scope = :monthly if scope != :weekly && @by_list_hash[:bymonth]
78
+ scope = :weekly if scope != :daily && @by_list_hash[:byweekno]
79
+ @by_day_scope = scope
80
+ end
81
+
82
+ def bysecond=(val)
83
+ @by_list_hash[:bysecond] = val
84
+ end
85
+
86
+ def byminute=(val)
87
+ @by_list_hash[:byminute] = val
88
+ end
89
+
90
+ def byhour=(val)
91
+ @by_list_hash[:byhour] = val
92
+ end
93
+
94
+ def bymonth=(val)
95
+ @by_list_hash[:bymonth] = val
96
+ end
97
+
98
+ def bysetpos=(val)
99
+ @by_list_hash[:bysetpos] = val
100
+ end
101
+
102
+ def byday=(val)
103
+ @by_list_hash[:byday] = val
104
+ end
105
+
106
+ def bymonthday=(val)
107
+ @by_list_hash[:bymonthday] = val
108
+ end
109
+
110
+ def byyearday=(val)
111
+ @by_list_hash[:byyearday] = val
112
+ end
113
+
114
+ def byweekno=(val)
115
+ @by_list_hash[:byweekno] = val
116
+ end
117
+
118
+ def init_by_lists
119
+ [:bysecond,
120
+ :byminute,
121
+ :byhour,
122
+ :bymonth,
123
+ :bysetpos
124
+ ].each do |which|
125
+ if val = @by_list_hash[which]
126
+ by_list[which] = [val].flatten.sort
127
+ end
128
+ end
129
+ if val = @by_list_hash[:byday]
130
+ byday_scope = calc_by_day_scope
131
+ by_list[:byday] = [val].flatten.map {|day| RecurringDay.new(day, self, byday_scope)}
132
+ end
133
+ if val = @by_list_hash[:bymonthday]
134
+ by_list[:bymonthday] = [val].flatten.map {|md| RecurringMonthDay.new(md)}
135
+ end
136
+ if val = @by_list_hash[:byyearday]
137
+ by_list[:byyearday] = [val].flatten.map {|yd| RecurringYearDay.new(yd)}
138
+ end
139
+ if val = @by_list_hash[:byweekno]
140
+ by_list[:byweekno] = [val].flatten.map {|wkno| RecurringNumberedWeek.new(wkno, self)}
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end