friflaj_ri_cal 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/History.txt +408 -0
- data/README.rdoc +407 -0
- data/Rakefile +9 -0
- data/component_attributes/alarm.yml +10 -0
- data/component_attributes/calendar.yml +4 -0
- data/component_attributes/component_property_defs.yml +180 -0
- data/component_attributes/event.yml +45 -0
- data/component_attributes/freebusy.yml +16 -0
- data/component_attributes/journal.yml +35 -0
- data/component_attributes/timezone.yml +3 -0
- data/component_attributes/timezone_period.yml +11 -0
- data/component_attributes/todo.yml +46 -0
- data/docs/draft-ietf-calsify-2446bis-08.txt +7280 -0
- data/docs/draft-ietf-calsify-rfc2445bis-09.txt +10416 -0
- data/docs/incrementers.txt +7 -0
- data/docs/rfc2445.pdf +0 -0
- data/docs/test.ics +38 -0
- data/lib/ri_cal.rb +184 -0
- data/lib/ri_cal/component.rb +254 -0
- data/lib/ri_cal/component/alarm.rb +17 -0
- data/lib/ri_cal/component/calendar.rb +255 -0
- data/lib/ri_cal/component/event.rb +56 -0
- data/lib/ri_cal/component/freebusy.rb +14 -0
- data/lib/ri_cal/component/journal.rb +25 -0
- data/lib/ri_cal/component/non_standard.rb +31 -0
- data/lib/ri_cal/component/t_z_info_timezone.rb +155 -0
- data/lib/ri_cal/component/timezone.rb +195 -0
- data/lib/ri_cal/component/timezone/daylight_period.rb +23 -0
- data/lib/ri_cal/component/timezone/standard_period.rb +21 -0
- data/lib/ri_cal/component/timezone/timezone_period.rb +74 -0
- data/lib/ri_cal/component/todo.rb +39 -0
- data/lib/ri_cal/core_extensions.rb +7 -0
- data/lib/ri_cal/core_extensions/array.rb +16 -0
- data/lib/ri_cal/core_extensions/date.rb +63 -0
- data/lib/ri_cal/core_extensions/date_time.rb +58 -0
- data/lib/ri_cal/core_extensions/object.rb +21 -0
- data/lib/ri_cal/core_extensions/string.rb +58 -0
- data/lib/ri_cal/core_extensions/time.rb +50 -0
- data/lib/ri_cal/core_extensions/time/calculations.rb +150 -0
- data/lib/ri_cal/core_extensions/time/tzid_access.rb +47 -0
- data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +52 -0
- data/lib/ri_cal/fast_date_time.rb +247 -0
- data/lib/ri_cal/floating_timezone.rb +29 -0
- data/lib/ri_cal/invalid_property_value.rb +5 -0
- data/lib/ri_cal/invalid_timezone_identifier.rb +17 -0
- data/lib/ri_cal/occurrence_enumerator.rb +262 -0
- data/lib/ri_cal/occurrence_period.rb +17 -0
- data/lib/ri_cal/parser.rb +142 -0
- data/lib/ri_cal/properties.rb +12 -0
- data/lib/ri_cal/properties/alarm.rb +387 -0
- data/lib/ri_cal/properties/calendar.rb +161 -0
- data/lib/ri_cal/properties/event.rb +1520 -0
- data/lib/ri_cal/properties/freebusy.rb +590 -0
- data/lib/ri_cal/properties/journal.rb +1234 -0
- data/lib/ri_cal/properties/timezone.rb +147 -0
- data/lib/ri_cal/properties/timezone_period.rb +413 -0
- data/lib/ri_cal/properties/todo.rb +1556 -0
- data/lib/ri_cal/property_value.rb +157 -0
- data/lib/ri_cal/property_value/array.rb +25 -0
- data/lib/ri_cal/property_value/cal_address.rb +9 -0
- data/lib/ri_cal/property_value/date.rb +182 -0
- data/lib/ri_cal/property_value/date_time.rb +357 -0
- data/lib/ri_cal/property_value/date_time/additive_methods.rb +42 -0
- data/lib/ri_cal/property_value/date_time/time_machine.rb +157 -0
- data/lib/ri_cal/property_value/date_time/timezone_support.rb +98 -0
- data/lib/ri_cal/property_value/duration.rb +108 -0
- data/lib/ri_cal/property_value/geo.rb +9 -0
- data/lib/ri_cal/property_value/integer.rb +10 -0
- data/lib/ri_cal/property_value/occurrence_list.rb +142 -0
- data/lib/ri_cal/property_value/period.rb +84 -0
- data/lib/ri_cal/property_value/recurrence_rule.rb +152 -0
- data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +98 -0
- data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +77 -0
- data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +146 -0
- data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +51 -0
- data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +29 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb +133 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb +84 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb +29 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb +30 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb +50 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb +29 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb +36 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb +30 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb +67 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb +29 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb +26 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb +78 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb +21 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb +104 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb +21 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb +41 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb +26 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb +35 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb +55 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +129 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +62 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +51 -0
- data/lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb +40 -0
- data/lib/ri_cal/property_value/recurrence_rule/validations.rb +123 -0
- data/lib/ri_cal/property_value/text.rb +42 -0
- data/lib/ri_cal/property_value/uri.rb +9 -0
- data/lib/ri_cal/property_value/utc_offset.rb +31 -0
- data/lib/ri_cal/property_value/zulu_date_time.rb +32 -0
- data/lib/ri_cal/required_timezones.rb +53 -0
- data/lib/ri_cal/version.rb +3 -0
- data/parked_specs/ri_cal/claudio_a_bug_spec.rb +98 -0
- data/performance/empty_propval/subject.rb +43 -0
- data/performance/paris_eastern/subject.rb +90 -0
- data/performance/penultimate_weekday/subject.rb +15 -0
- data/performance/psm_big_enum/ical.ics +3171 -0
- data/performance/psm_big_enum/subject.rb +16 -0
- data/performance/utah_cycling/subject.rb +55 -0
- data/performance_data/benchmarks.out +48 -0
- data/performance_data/empty_propval.calltree +45650 -0
- data/performance_data/paris_eastern.calltree +103058 -0
- data/performance_data/penultimate_weekday.calltree +48686 -0
- data/performance_data/psm_big_enum.calltree +225814 -0
- data/performance_data/utah_cycling.calltree +117950 -0
- data/ri_cal.gemspec +35 -0
- data/script/benchmark_subject +23 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/profile_subject +29 -0
- data/script/txt2html +71 -0
- data/spec/ri_cal/bugreports_spec.rb +281 -0
- data/spec/ri_cal/component/alarm_spec.rb +10 -0
- data/spec/ri_cal/component/calendar_spec.rb +87 -0
- data/spec/ri_cal/component/event_spec.rb +734 -0
- data/spec/ri_cal/component/freebusy_spec.rb +10 -0
- data/spec/ri_cal/component/journal_spec.rb +35 -0
- data/spec/ri_cal/component/t_z_info_timezone_spec.rb +63 -0
- data/spec/ri_cal/component/timezone_spec.rb +233 -0
- data/spec/ri_cal/component/todo_spec.rb +110 -0
- data/spec/ri_cal/component_spec.rb +225 -0
- data/spec/ri_cal/core_extensions/string/conversions_spec.rb +76 -0
- data/spec/ri_cal/core_extensions/time/calculations_spec.rb +186 -0
- data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +43 -0
- data/spec/ri_cal/fast_date_time_spec.rb +75 -0
- data/spec/ri_cal/inf_loop_spec.rb +75 -0
- data/spec/ri_cal/occurrence_enumerator_spec.rb +610 -0
- data/spec/ri_cal/parser_spec.rb +335 -0
- data/spec/ri_cal/property_value/date_spec.rb +51 -0
- data/spec/ri_cal/property_value/date_time_spec.rb +380 -0
- data/spec/ri_cal/property_value/duration_spec.rb +123 -0
- data/spec/ri_cal/property_value/occurrence_list_spec.rb +70 -0
- data/spec/ri_cal/property_value/period_spec.rb +61 -0
- data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +19 -0
- data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1810 -0
- data/spec/ri_cal/property_value/text_spec.rb +23 -0
- data/spec/ri_cal/property_value/utc_offset_spec.rb +46 -0
- data/spec/ri_cal/property_value_spec.rb +123 -0
- data/spec/ri_cal/required_timezones_spec.rb +63 -0
- data/spec/ri_cal_spec.rb +50 -0
- data/spec/spec_helper.rb +35 -0
- data/tasks/ri_cal.rake +400 -0
- data/tasks/spec.rake +26 -0
- metadata +260 -0
data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class OccurrenceIncrementer # :nodoc:
|
5
|
+
class NullSubCycleIncrementer #:nodoc:
|
6
|
+
def self.next_time(previous)
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.add_outer_incrementer(incrementer)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.unneeded?(candidate)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.first_within_outer_cycle(previous_occurrence, outer_cycle_range)
|
18
|
+
outer_cycle_range.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.first_sub_occurrence(previous_occurrence, outer_cycle_range)
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.cycle_adjust(date_time)
|
26
|
+
date_time
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.to_s
|
30
|
+
"NULL-INCR"
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class OccurrenceIncrementer # :nodoc:
|
5
|
+
class SecondlyIncrementer < FrequencyIncrementer #:nodoc:
|
6
|
+
|
7
|
+
def self.for_rrule(rrule)
|
8
|
+
if rrule.freq == "SECONDLY"
|
9
|
+
new(rrule, nil)
|
10
|
+
else
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def advance_what
|
16
|
+
:seconds
|
17
|
+
end
|
18
|
+
|
19
|
+
def end_of_occurrence(date_time)
|
20
|
+
date_time
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class OccurrenceIncrementer # :nodoc:
|
5
|
+
class WeeklyIncrementer < FrequencyIncrementer #:nodoc:
|
6
|
+
|
7
|
+
attr_reader :wkst
|
8
|
+
|
9
|
+
# include WeeklyBydayMethods
|
10
|
+
|
11
|
+
def initialize(rrule, parent)
|
12
|
+
@wkst = rrule.wkst_day
|
13
|
+
super(rrule, parent)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.for_rrule(rrule)
|
17
|
+
conditional_incrementer(rrule, "WEEKLY", ByDayIncrementer)
|
18
|
+
end
|
19
|
+
|
20
|
+
def multiplier
|
21
|
+
7
|
22
|
+
end
|
23
|
+
|
24
|
+
def advance_what
|
25
|
+
:days
|
26
|
+
end
|
27
|
+
|
28
|
+
def end_of_occurrence(date_time)
|
29
|
+
date_time.end_of_week_with_wkst(wkst)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class OccurrenceIncrementer # :nodoc:
|
5
|
+
class YearlyIncrementer < FrequencyIncrementer #:nodoc:
|
6
|
+
|
7
|
+
attr_reader :wkst
|
8
|
+
|
9
|
+
def initialize(rrule, sub_cycle_incrementer)
|
10
|
+
@wkst = rrule.wkst_day
|
11
|
+
super(rrule, sub_cycle_incrementer)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_rrule(rrule, start_time)
|
15
|
+
conditional_incrementer(rrule, "YEARLY", ByMonthIncrementer)
|
16
|
+
end
|
17
|
+
|
18
|
+
def advance_what
|
19
|
+
:years
|
20
|
+
end
|
21
|
+
|
22
|
+
def step(date_time)
|
23
|
+
if contains_weeknum_incrementer?
|
24
|
+
result = date_time
|
25
|
+
multiplier.times do
|
26
|
+
result = result.at_start_of_next_iso_year(wkst)
|
27
|
+
end
|
28
|
+
result
|
29
|
+
else
|
30
|
+
super(date_time)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start_of_cycle(date_time)
|
35
|
+
if contains_weeknum_incrementer?
|
36
|
+
date_time.at_start_of_iso_year(wkst)
|
37
|
+
elsif contains_daily_incrementer?
|
38
|
+
date_time.change(:month => 1, :day => 1)
|
39
|
+
else
|
40
|
+
date_time.change(:month => 1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def end_of_occurrence(date_time)
|
45
|
+
if contains_weeknum_incrementer?
|
46
|
+
date_time.end_of_iso_year(wkst)
|
47
|
+
else
|
48
|
+
date_time.end_of_year
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
# Instances of RecurringDay are used to represent values in BYDAY recurrence rule parts
|
5
|
+
#
|
6
|
+
class RecurringDay # :nodoc:
|
7
|
+
|
8
|
+
attr_reader :wday, :index, :rrule
|
9
|
+
|
10
|
+
DayNames = %w{SU MO TU WE TH FR SA} unless defined? DayNames
|
11
|
+
day_nums = {}
|
12
|
+
unless defined? DayNums
|
13
|
+
DayNames.each_with_index { |name, i| day_nums[name] = i }
|
14
|
+
DayNums = day_nums
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :source, :scope
|
18
|
+
def initialize(source, rrule, scope = :monthly)
|
19
|
+
@source = source
|
20
|
+
@rrule = rrule
|
21
|
+
@scope = scope
|
22
|
+
wd_match = source.match(/([+-]?\d*)(SU|MO|TU|WE|TH|FR|SA)/)
|
23
|
+
if wd_match
|
24
|
+
@day, @ordinal = wd_match[2], wd_match[1]
|
25
|
+
@wday = DayNums[@day]
|
26
|
+
@index = (@ordinal == "") ? nil : @ordinal.to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
!@day.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def ==(another)
|
35
|
+
self.class === another && to_a = another.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_a
|
39
|
+
[@day, @ordinal]
|
40
|
+
end
|
41
|
+
|
42
|
+
# return a list id for a given time to allow the enumerator to cache lists
|
43
|
+
def list_id(time)
|
44
|
+
case @scope
|
45
|
+
when :yearly
|
46
|
+
time.year
|
47
|
+
when :monthly
|
48
|
+
(time.year * 100) + time.month
|
49
|
+
when :weekly
|
50
|
+
time.at_start_of_week_with_wkst(rrule.wkst_day).jd
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# return a list of times which match the time parameter within the scope of the RecurringDay
|
55
|
+
def matches_for(time)
|
56
|
+
case @scope
|
57
|
+
when :yearly
|
58
|
+
yearly_matches_for(time)
|
59
|
+
when :monthly
|
60
|
+
monthly_matches_for(time)
|
61
|
+
when :weekly
|
62
|
+
weekly_matches_for(time)
|
63
|
+
else
|
64
|
+
walkback = caller.grep(/recurrence/i)
|
65
|
+
raise "Logic error!#{@scope.inspect}\n #{walkback.join("\n ")}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def yearly_matches_for(time)
|
70
|
+
if @ordinal == ""
|
71
|
+
t = time.nth_wday_in_year(1, wday)
|
72
|
+
result = []
|
73
|
+
year = time.year
|
74
|
+
while t.year == year
|
75
|
+
result << t
|
76
|
+
t = t.advance(:week => 1)
|
77
|
+
end
|
78
|
+
result
|
79
|
+
else
|
80
|
+
[time.nth_wday_in_year(@ordinal.to_i, wday)]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def monthly_matches_for(time)
|
85
|
+
if @ordinal == ""
|
86
|
+
t = time.nth_wday_in_month(1, wday)
|
87
|
+
result = []
|
88
|
+
month = time.month
|
89
|
+
while t.month == month
|
90
|
+
result << t
|
91
|
+
t = t.advance(:days => 7)
|
92
|
+
end
|
93
|
+
result
|
94
|
+
else
|
95
|
+
result = [time.nth_wday_in_month(index, wday)]
|
96
|
+
result
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def weekly_matches_for(time)
|
101
|
+
date = time.start_of_week_with_wkst(rrule.wkst_day)
|
102
|
+
date += 1 while date.wday != wday
|
103
|
+
[time.change(:year => date.year, :month => date.month, :day => date.day)]
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s
|
107
|
+
"#{@ordinal}#{@day}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def ordinal_match(date_or_time)
|
111
|
+
if @ordinal == "" || @scope == :weekly
|
112
|
+
true
|
113
|
+
else
|
114
|
+
if @scope == :yearly
|
115
|
+
date_or_time.nth_wday_in_year?(index, wday)
|
116
|
+
else
|
117
|
+
date_or_time.nth_wday_in_month?(index, wday)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Determine if a particular date, time, or date_time is included in the recurrence
|
123
|
+
def include?(date_or_time)
|
124
|
+
date_or_time.wday == wday && ordinal_match(date_or_time)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
# Instances of RecurringMonthDay represent BYMONTHDAY parts in recurrence rules
|
5
|
+
class RecurringMonthDay < NumberedSpan # :nodoc:
|
6
|
+
|
7
|
+
def last
|
8
|
+
31
|
9
|
+
end
|
10
|
+
|
11
|
+
# return a list id for a given time to allow the enumerator to cache lists
|
12
|
+
def list_id(time)
|
13
|
+
time.month
|
14
|
+
end
|
15
|
+
|
16
|
+
# return a list of times which match the time parameter within the scope of the RecurringDay
|
17
|
+
def matches_for(time)
|
18
|
+
[time.change(:day => 1).advance(:days => target_for(time)- 1)]
|
19
|
+
end
|
20
|
+
|
21
|
+
# return a list id for a given time to allow the enumerator to cache lists
|
22
|
+
def list_id(time)
|
23
|
+
time.month
|
24
|
+
end
|
25
|
+
|
26
|
+
# return a list of times which match the time parameter within the scope of the RecurringDay
|
27
|
+
def matches_for(time)
|
28
|
+
[time.change(:day => 1).advance(:days => target_for(time)- 1)]
|
29
|
+
end
|
30
|
+
|
31
|
+
def target_date_time_for(date_time)
|
32
|
+
matches_for(date_time)[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
# return a list of times which match the time parameter within the scope of the RecurringDay
|
36
|
+
def matches_for(time)
|
37
|
+
[time.change(:day => 1).advance(:days => target_for(time)- 1)]
|
38
|
+
end
|
39
|
+
|
40
|
+
def target_date_time_for(date_time)
|
41
|
+
matches_for(date_time)[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
def fixed_day?
|
45
|
+
@source > 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def target_for(date_or_time)
|
49
|
+
if fixed_day?
|
50
|
+
@source
|
51
|
+
else
|
52
|
+
date_or_time.days_in_month + @source + 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def include?(date_or_time)
|
57
|
+
date_or_time.mday == target_for(date_or_time)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class RecurringNumberedWeek < NumberedSpan # :nodoc:
|
5
|
+
def last
|
6
|
+
53
|
7
|
+
end
|
8
|
+
|
9
|
+
def rule_wkst
|
10
|
+
@rule && rule.wkst_day
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_wkst
|
14
|
+
rule_wkst || 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def adjusted_iso_weeknum(date_or_time)
|
18
|
+
if @source > 0
|
19
|
+
@source
|
20
|
+
else
|
21
|
+
date_or_time.iso_weeks_in_year(wkst) + @source + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def include?(date_or_time, wkst=default_wkst)
|
26
|
+
date_or_time.iso_week_num(wkst) == adjusted_iso_weeknum(date_or_time)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
class RecurringYearDay < NumberedSpan # :nodoc:
|
5
|
+
|
6
|
+
def last
|
7
|
+
366
|
8
|
+
end
|
9
|
+
|
10
|
+
def leap_year?(year)
|
11
|
+
year % 4 == 0 && (year % 400 == 0 || year % 100 != 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def length_of_year(year)
|
16
|
+
leap_year?(year) ? 366 : 365
|
17
|
+
end
|
18
|
+
|
19
|
+
# return a list id for a given time to allow the enumerator to cache lists
|
20
|
+
def list_id(time)
|
21
|
+
time.year
|
22
|
+
end
|
23
|
+
|
24
|
+
# return a list of times which match the time parameter within the scope of the RecurringDay
|
25
|
+
def matches_for(time)
|
26
|
+
[time.change(:month => 1, :day => 1).advance(:days => target_for(time)- 1)]
|
27
|
+
end
|
28
|
+
|
29
|
+
def target_date_time_for(date_time)
|
30
|
+
matches_for(date_time)[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def fixed_day?
|
34
|
+
@source > 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def target_for(date_or_time)
|
38
|
+
if fixed_day?
|
39
|
+
@source
|
40
|
+
else
|
41
|
+
length_of_year(date_or_time.year) + @source + 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def include?(date_or_time)
|
46
|
+
date_or_time.yday == target_for(date_or_time)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RiCal
|
2
|
+
class PropertyValue
|
3
|
+
class RecurrenceRule < PropertyValue
|
4
|
+
module TimeManipulation #:nodoc:
|
5
|
+
|
6
|
+
def advance_day(date_time)
|
7
|
+
date_time.advance(:days => 1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def first_hour_of_day(date_time)
|
11
|
+
date_time.change(:hour => 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
def advance_week(date_time)
|
15
|
+
date_time.advance(:days => 7)
|
16
|
+
end
|
17
|
+
|
18
|
+
def first_day_of_week(wkst_day, date_time)
|
19
|
+
date_time.at_start_of_week_with_wkst(wkst_day)
|
20
|
+
end
|
21
|
+
|
22
|
+
def advance_month(date_time)
|
23
|
+
date_time.advance(:months => 1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def first_day_of_month(date_time)
|
27
|
+
date_time.change(:day => 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def advance_year(date_time)
|
31
|
+
date_time.advance(:years => 1)
|
32
|
+
end
|
33
|
+
|
34
|
+
def first_day_of_year(date_time)
|
35
|
+
date_time.change(:month => 1, :day => 1)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|