awallis-ri_cal 0.8.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 +402 -0
- data/Manifest.txt +161 -0
- data/README.txt +410 -0
- data/Rakefile +69 -0
- data/VERSION +1 -0
- data/bin/ri_cal +8 -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/copyrights.txt +1 -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/lib/ri_cal.rb +187 -0
- data/lib/ri_cal/component.rb +256 -0
- data/lib/ri_cal/component/alarm.rb +19 -0
- data/lib/ri_cal/component/calendar.rb +257 -0
- data/lib/ri_cal/component/event.rb +58 -0
- data/lib/ri_cal/component/freebusy.rb +16 -0
- data/lib/ri_cal/component/journal.rb +27 -0
- data/lib/ri_cal/component/non_standard.rb +33 -0
- data/lib/ri_cal/component/t_z_info_timezone.rb +153 -0
- data/lib/ri_cal/component/timezone.rb +197 -0
- data/lib/ri_cal/component/timezone/daylight_period.rb +25 -0
- data/lib/ri_cal/component/timezone/standard_period.rb +23 -0
- data/lib/ri_cal/component/timezone/timezone_period.rb +76 -0
- data/lib/ri_cal/component/todo.rb +42 -0
- data/lib/ri_cal/core_extensions.rb +11 -0
- data/lib/ri_cal/core_extensions/array.rb +7 -0
- data/lib/ri_cal/core_extensions/array/conversions.rb +15 -0
- data/lib/ri_cal/core_extensions/date.rb +13 -0
- data/lib/ri_cal/core_extensions/date/conversions.rb +56 -0
- data/lib/ri_cal/core_extensions/date_time.rb +15 -0
- data/lib/ri_cal/core_extensions/date_time/conversions.rb +50 -0
- data/lib/ri_cal/core_extensions/object.rb +8 -0
- data/lib/ri_cal/core_extensions/object/conversions.rb +20 -0
- data/lib/ri_cal/core_extensions/string.rb +8 -0
- data/lib/ri_cal/core_extensions/string/conversions.rb +57 -0
- data/lib/ri_cal/core_extensions/time.rb +14 -0
- data/lib/ri_cal/core_extensions/time/calculations.rb +153 -0
- data/lib/ri_cal/core_extensions/time/conversions.rb +42 -0
- data/lib/ri_cal/core_extensions/time/tzid_access.rb +50 -0
- data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +55 -0
- data/lib/ri_cal/fast_date_time.rb +234 -0
- data/lib/ri_cal/floating_timezone.rb +32 -0
- data/lib/ri_cal/invalid_property_value.rb +8 -0
- data/lib/ri_cal/invalid_timezone_identifier.rb +20 -0
- data/lib/ri_cal/occurrence_enumerator.rb +265 -0
- data/lib/ri_cal/occurrence_period.rb +17 -0
- data/lib/ri_cal/parser.rb +145 -0
- data/lib/ri_cal/properties.rb +12 -0
- data/lib/ri_cal/properties/alarm.rb +390 -0
- data/lib/ri_cal/properties/calendar.rb +164 -0
- data/lib/ri_cal/properties/event.rb +1523 -0
- data/lib/ri_cal/properties/freebusy.rb +593 -0
- data/lib/ri_cal/properties/journal.rb +1237 -0
- data/lib/ri_cal/properties/timezone.rb +150 -0
- data/lib/ri_cal/properties/timezone_period.rb +416 -0
- data/lib/ri_cal/properties/todo.rb +1559 -0
- data/lib/ri_cal/property_value.rb +159 -0
- data/lib/ri_cal/property_value/array.rb +27 -0
- data/lib/ri_cal/property_value/cal_address.rb +11 -0
- data/lib/ri_cal/property_value/date.rb +184 -0
- data/lib/ri_cal/property_value/date_time.rb +359 -0
- data/lib/ri_cal/property_value/date_time/additive_methods.rb +44 -0
- data/lib/ri_cal/property_value/date_time/time_machine.rb +159 -0
- data/lib/ri_cal/property_value/date_time/timezone_support.rb +100 -0
- data/lib/ri_cal/property_value/duration.rb +110 -0
- data/lib/ri_cal/property_value/geo.rb +11 -0
- data/lib/ri_cal/property_value/integer.rb +12 -0
- data/lib/ri_cal/property_value/occurrence_list.rb +144 -0
- data/lib/ri_cal/property_value/period.rb +86 -0
- data/lib/ri_cal/property_value/recurrence_rule.rb +154 -0
- data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +100 -0
- data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +79 -0
- data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +148 -0
- data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +53 -0
- data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb +135 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb +86 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb +32 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb +52 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb +38 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb +32 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb +69 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb +31 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb +28 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb +80 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb +23 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb +106 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb +23 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb +33 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb +43 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb +28 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb +37 -0
- data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb +57 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +131 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +64 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +33 -0
- data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +53 -0
- data/lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb +42 -0
- data/lib/ri_cal/property_value/recurrence_rule/validations.rb +125 -0
- data/lib/ri_cal/property_value/text.rb +44 -0
- data/lib/ri_cal/property_value/uri.rb +11 -0
- data/lib/ri_cal/property_value/utc_offset.rb +33 -0
- data/lib/ri_cal/property_value/zulu_date_time.rb +34 -0
- data/lib/ri_cal/required_timezones.rb +55 -0
- data/parked_specs/ri_cal/claudio_a_bug_spec.rb +100 -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/ri_cal.gemspec +244 -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 +276 -0
- data/spec/ri_cal/component/alarm_spec.rb +12 -0
- data/spec/ri_cal/component/calendar_spec.rb +88 -0
- data/spec/ri_cal/component/event_spec.rb +735 -0
- data/spec/ri_cal/component/freebusy_spec.rb +12 -0
- data/spec/ri_cal/component/journal_spec.rb +37 -0
- data/spec/ri_cal/component/t_z_info_timezone_spec.rb +60 -0
- data/spec/ri_cal/component/timezone_spec.rb +236 -0
- data/spec/ri_cal/component/todo_spec.rb +112 -0
- data/spec/ri_cal/component_spec.rb +224 -0
- data/spec/ri_cal/core_extensions/string/conversions_spec.rb +78 -0
- data/spec/ri_cal/core_extensions/time/calculations_spec.rb +188 -0
- data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +45 -0
- data/spec/ri_cal/fast_date_time_spec.rb +77 -0
- data/spec/ri_cal/inf_loop_spec.rb +78 -0
- data/spec/ri_cal/occurrence_enumerator_spec.rb +611 -0
- data/spec/ri_cal/parser_spec.rb +337 -0
- data/spec/ri_cal/property_value/date_spec.rb +53 -0
- data/spec/ri_cal/property_value/date_time_spec.rb +383 -0
- data/spec/ri_cal/property_value/duration_spec.rb +126 -0
- data/spec/ri_cal/property_value/occurrence_list_spec.rb +72 -0
- data/spec/ri_cal/property_value/period_spec.rb +63 -0
- data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +21 -0
- data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1814 -0
- data/spec/ri_cal/property_value/text_spec.rb +25 -0
- data/spec/ri_cal/property_value/utc_offset_spec.rb +48 -0
- data/spec/ri_cal/property_value_spec.rb +125 -0
- data/spec/ri_cal/required_timezones_spec.rb +67 -0
- data/spec/ri_cal_spec.rb +53 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +50 -0
- data/tasks/gem_loader/load_active_support.rb +3 -0
- data/tasks/gem_loader/load_tzinfo_gem.rb +2 -0
- data/tasks/ri_cal.rake +412 -0
- data/tasks/spec.rake +102 -0
- metadata +255 -0
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
require 'tzinfo'
|
|
5
|
+
|
|
6
|
+
describe RiCal::Component do
|
|
7
|
+
|
|
8
|
+
context "building blocks" do
|
|
9
|
+
|
|
10
|
+
context "building an empty calendar" do
|
|
11
|
+
before(:each) do
|
|
12
|
+
@it = RiCal.Calendar.to_s
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should have the default prodid" do
|
|
16
|
+
@it.should match(%r{^PRODID;X-RICAL-TZSOURCE=TZINFO:-//com.denhaven2/NONSGML ri_cal gem//EN$})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should have the default calscale" do
|
|
20
|
+
@it.should match(%r{^CALSCALE:GREGORIAN$})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should have the default icalendar version" do
|
|
24
|
+
@it.should match(%r{^VERSION:2\.0$})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "building a calendar with time zones" do
|
|
29
|
+
it 'should allow specifying the time zone identifier' do
|
|
30
|
+
event = RiCal.Event do
|
|
31
|
+
dtstart DateTime.parse("Feb 20, 1962 14:47:39").set_tzid('US/Pacific')
|
|
32
|
+
end
|
|
33
|
+
event.dtstart_property.should == dt_prop(DateTime.parse("Feb 20, 1962 14:47:39"), tzid = 'US/Pacific')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "adding an exception date" do
|
|
37
|
+
|
|
38
|
+
before(:each) do
|
|
39
|
+
@cal = RiCal.Calendar do
|
|
40
|
+
event do
|
|
41
|
+
add_exdate 'US/Eastern', "19620220T144739"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
@event = @cal.events.first
|
|
45
|
+
@prop = @event.exdate_property.first
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should produce an OccurrenceList for the property" do
|
|
49
|
+
@prop.should be_instance_of(RiCal::PropertyValue::OccurrenceList)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should have a property with the right ical representation" do
|
|
53
|
+
@prop.to_s.should == ";TZID=US/Eastern:19620220T144739"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "its ruby_value" do
|
|
57
|
+
it "should have the right value" do
|
|
58
|
+
@prop.ruby_value.should == [DateTime.civil(1962, 2, 20, 14, 47, 39, Rational(-5, 24))]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should have the right tzid" do
|
|
62
|
+
@prop.ruby_value.first.tzid.should == "US/Eastern"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "with a block with 1 parameter" do
|
|
69
|
+
before(:each) do
|
|
70
|
+
@it = RiCal.Event do |event|
|
|
71
|
+
event.description = "MA-6 First US Manned Spaceflight"
|
|
72
|
+
event.dtstart = DateTime.parse("Feb 20, 1962 14:47:39")
|
|
73
|
+
event.dtend = DateTime.parse("Feb 20, 1962 19:43:02")
|
|
74
|
+
event.location = "Cape Canaveral"
|
|
75
|
+
event.add_attendee "john.glenn@nasa.gov"
|
|
76
|
+
event.alarm do
|
|
77
|
+
description "Segment 51"
|
|
78
|
+
end
|
|
79
|
+
event.alarm do |alarm|
|
|
80
|
+
alarm.description = "Second alarm"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should have the right description" do
|
|
86
|
+
@it.description.should == "MA-6 First US Manned Spaceflight"
|
|
87
|
+
end
|
|
88
|
+
it "should have the right dtstart" do
|
|
89
|
+
@it.dtstart.should == DateTime.parse("Feb 20, 1962 14:47:39")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should have a zulu time dtstart property" do
|
|
93
|
+
@it.dtstart_property.tzid.should == "UTC"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should have the right dtend" do
|
|
97
|
+
@it.dtend.should == DateTime.parse("Feb 20, 1962 19:43:02")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should have a zulu time dtend property" do
|
|
101
|
+
@it.dtend_property.tzid.should == "UTC"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should have the right location" do
|
|
105
|
+
@it.location.should == "Cape Canaveral"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should have the right attendee" do
|
|
109
|
+
@it.attendee.should include("john.glenn@nasa.gov")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should have 2 alarms" do
|
|
113
|
+
@it.alarms.length.should == 2
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it ".the alarms should have the right description" do
|
|
117
|
+
@it.alarms.first.description.should == "Segment 51"
|
|
118
|
+
@it.alarms.last.description.should == "Second alarm"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context "building an event for MA-6" do
|
|
123
|
+
before(:each) do
|
|
124
|
+
@it = RiCal.Event do
|
|
125
|
+
description "MA-6 First US Manned Spaceflight"
|
|
126
|
+
dtstart DateTime.parse("Feb 20, 1962 14:47:39")
|
|
127
|
+
dtend DateTime.parse("Feb 20, 1962 19:43:02")
|
|
128
|
+
location "Cape Canaveral"
|
|
129
|
+
add_attendee "john.glenn@nasa.gov"
|
|
130
|
+
alarm do
|
|
131
|
+
description "Segment 51"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should have the right description" do
|
|
137
|
+
@it.description.should == "MA-6 First US Manned Spaceflight"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "should have the right dtstart" do
|
|
141
|
+
@it.dtstart.should == DateTime.parse("Feb 20, 1962 14:47:39")
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should have a zulu time dtstart property" do
|
|
145
|
+
@it.dtstart_property.tzid.should == "UTC"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should have the right dtend" do
|
|
149
|
+
@it.dtend.should == DateTime.parse("Feb 20, 1962 19:43:02")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should have a zulu time dtend property" do
|
|
153
|
+
@it.dtend_property.tzid.should == "UTC"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "should have the right location" do
|
|
157
|
+
@it.location.should == "Cape Canaveral"
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should have the right attendee" do
|
|
161
|
+
@it.attendee.should include("john.glenn@nasa.gov")
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should have 1 alarm" do
|
|
165
|
+
@it.alarms.length.should == 1
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "should have an alarm with the right description" do
|
|
169
|
+
@it.alarms.first.description.should == "Segment 51"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context "building a complex calendar" do
|
|
174
|
+
|
|
175
|
+
before(:each) do
|
|
176
|
+
@it = RiCal.Calendar do
|
|
177
|
+
add_x_property 'x_wr_calname', 'My Personal Calendar', true
|
|
178
|
+
event do
|
|
179
|
+
summary 'A Recurring Event'
|
|
180
|
+
description "This is some really long note content. It should be appropriately folded in the generated file.\nCarriage returns should work, too."
|
|
181
|
+
dtstart DateTime.parse('Feb 20, 2009 20:30:00')
|
|
182
|
+
dtend DateTime.parse('Feb 20, 2009 21:30:00')
|
|
183
|
+
location 'North Carolina'
|
|
184
|
+
dtstamp Time.now
|
|
185
|
+
rrule :freq => 'daily', :interval => 1
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'should have an x_wr_calname property with the value "My Personal Calendar"' do
|
|
191
|
+
@it.x_wr_calname.first.should == "My Personal Calendar"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
context "event with a long description and a dsl built recurence rule" do
|
|
195
|
+
before(:each) do
|
|
196
|
+
@cal = @it
|
|
197
|
+
@it = @cal.events.first
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context "its description" do
|
|
201
|
+
it "should pass through correctly" do
|
|
202
|
+
@it.description.should == "This is some really long note content. It should be appropriately folded in the generated file.\nCarriage returns should work, too."
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
context "its rrule" do
|
|
207
|
+
|
|
208
|
+
it "should have a 1 rrule" do
|
|
209
|
+
@it.rrule.length.should == 1
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should have the right rrule" do
|
|
213
|
+
@it.rrule.first.should == "FREQ=DAILY"
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "should have the right rrule hash" do
|
|
217
|
+
@it.rrule_property.first.to_options_hash.should == {:freq => 'DAILY', :interval => 1}
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
end
|
|
224
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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::CoreExtensions::String::Conversions do
|
|
6
|
+
context "#to_ri_cal_date_time_value" do
|
|
7
|
+
|
|
8
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string" do
|
|
9
|
+
"20090304T123456".to_ri_cal_date_time_value.should == RiCal::PropertyValue::DateTime.new(nil, :value => "20090304T123456")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string with a TZID parameter" do
|
|
13
|
+
"TZID=America/New_York:20090304T123456".to_ri_cal_date_time_value.should == RiCal::PropertyValue::DateTime.new(nil, :params => {"TZID" => "America/New_York"}, :value => "20090304T123456")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should raise an InvalidPropertyValue error if the string is not a valid RFC 2445 datetime string" do
|
|
17
|
+
lambda {"20090304".to_ri_cal_date_time_value}.should raise_error(RiCal::InvalidPropertyValue)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "#to_ri_cal_duration_value" do
|
|
22
|
+
|
|
23
|
+
it "should produce a Duration property for a valid RFC 2445 duration string" do
|
|
24
|
+
"PT1H".to_ri_cal_duration_value.should == RiCal::PropertyValue::Duration.new(nil, :value => "PT1H")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should raise an InvalidPropertyValue error if the string is not a valid RFC 2445 datetime string" do
|
|
28
|
+
lambda {"20090304".to_ri_cal_duration_value}.should raise_error(RiCal::InvalidPropertyValue)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "#to_ri_cal_date_or_date_time_value" do
|
|
33
|
+
|
|
34
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string" do
|
|
35
|
+
"20090304T123456".to_ri_cal_date_or_date_time_value.should == RiCal::PropertyValue::DateTime.new(nil, :value => "20090304T123456")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string with a TZID parameter" do
|
|
39
|
+
"TZID=America/New_York:20090304T123456".to_ri_cal_date_or_date_time_value.should == RiCal::PropertyValue::DateTime.new(nil, :params => {"TZID" => "America/New_York"}, :value => "20090304T123456")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should produce a Date property for a valid RFC 2445 date string" do
|
|
43
|
+
"20090304".to_ri_cal_date_or_date_time_value.should == RiCal::PropertyValue::Date.new(nil, :value => "20090304")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
it "should raise an InvalidPropertyValue error if the string is not a valid RFC 2445 date or datetime string" do
|
|
48
|
+
lambda {"2009/03/04".to_ri_cal_date_or_date_time_value}.should raise_error(RiCal::InvalidPropertyValue)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "#to_ri_cal_occurrence_list_value" do
|
|
53
|
+
|
|
54
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string" do
|
|
55
|
+
"20090304T123456".to_ri_cal_occurrence_list_value.should == RiCal::PropertyValue::DateTime.new(nil, :value => "20090304T123456")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should produce a DateTime property for a valid RFC 2445 datetime string with a TZID parameter" do
|
|
59
|
+
"TZID=America/New_York:20090304T123456".to_ri_cal_occurrence_list_value.should == RiCal::PropertyValue::DateTime.new(nil, :params => {"TZID" => "America/New_York"}, :value => "20090304T123456")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should produce a Date property for a valid RFC 2445 date string" do
|
|
63
|
+
"20090304".to_ri_cal_occurrence_list_value.should == RiCal::PropertyValue::Date.new(nil, :value => "20090304")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should produce a Period property for a valid RFC 2445 period string (two time format)" do
|
|
67
|
+
"20090304T012345/20090304T023456".to_ri_cal_occurrence_list_value.should == RiCal::PropertyValue::Period.new(nil, :value => "20090304T012345/20090304T023456")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should produce a Period property for a valid RFC 2445 period string (time and duration format)" do
|
|
71
|
+
"20090304T012345/PT1H".to_ri_cal_occurrence_list_value.should == RiCal::PropertyValue::Period.new(nil, :value => "20090304T012345/PT1H")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should raise an InvalidPropertyValue error if the string is not a valid RFC 2445 date or datetime string" do
|
|
75
|
+
lambda {"foobar".to_ri_cal_date_or_date_time_value}.should raise_error(RiCal::InvalidPropertyValue)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,188 @@
|
|
|
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::CoreExtensions::Time::Calculations do
|
|
6
|
+
|
|
7
|
+
describe ".iso_week_num" do
|
|
8
|
+
|
|
9
|
+
it "should calculate week 1 for January 1, 2001 for a wkst of 1 (Monday)" do
|
|
10
|
+
Date.new(2001, 1,1).iso_week_num(1).should == 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should calculate week 1 for January 7, 2001 for a wkst of 1 (Monday)" do
|
|
14
|
+
Date.new(2001, 1,7).iso_week_num(1).should == 1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should calculate week 2 for January 8, 2001 for a wkst of 1 (Monday)" do
|
|
18
|
+
Date.new(2001, 1,8).iso_week_num(1).should == 2
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should calculate week 52 for December 31, 2000 for a wkst of 1 (Monday)" do
|
|
22
|
+
Date.new(2000, 12,31).iso_week_num(1).should == 52
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should calculate week 52 for January 1, 2001 for a wkst of 2 (Tuesday)" do
|
|
26
|
+
Date.new(2001, 1, 1).iso_week_num(2).should == 52
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should calculate week 1 for Dec 31, 2003 for a wkst of 1 (Monday)" do
|
|
30
|
+
Date.new(2003, 12, 31).iso_week_num(1).should == 1
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe ".iso_year" do
|
|
35
|
+
it "should be 1999 for January 2 2000" do
|
|
36
|
+
Date.new(2000, 1, 2).iso_year(1).should == 1999
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should be 1998 for December 29, 1997" do
|
|
40
|
+
Date.new(1997, 12, 29).iso_year(1).should == 1998
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe ".iso_year_start" do
|
|
45
|
+
|
|
46
|
+
it "should calculate January 4 1999 for January 2 2000 for a wkst of 1 (Monday)" do
|
|
47
|
+
Date.new(2000, 1, 2).iso_year_start(1).to_s.should == Date.new(1999, 1, 4).to_s
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should calculate January 3 2000 for January 3 2000 for a wkst of 1 (Monday)" do
|
|
51
|
+
Date.new(2000, 1, 3).iso_year_start(1).to_s.should == Date.new(2000, 1, 3).to_s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should calculate January 3 2000 for January 4 2000 for a wkst of 1 (Monday)" do
|
|
55
|
+
Date.new(2000, 1, 4).iso_year_start(1).to_s.should == Date.new(2000, 1, 3).to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should calculate January 3 2000 for December 31 2000 for a wkst of 1 (Monday)" do
|
|
59
|
+
Date.new(2000, 12, 31).iso_year_start(1).to_s.should == Date.new(2000, 1, 3).to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should calculate week January 1, 2001 for January 1, 2001 for a wkst of 1 (Monday)" do
|
|
63
|
+
Date.new(2001, 1,1).iso_year_start(1).should == Date.new(2001, 1, 1)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should calculate week January 1, 2001 for July 4, 2001 for a wkst of 1 (Monday)" do
|
|
67
|
+
Date.new(2001, 7,4).iso_year_start(1).should == Date.new(2001, 1, 1)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should calculate January 3 2000 for January 3 2000" do
|
|
71
|
+
Date.new(2000, 1, 3).iso_year_start(1).to_s.should == Date.new(2000, 1, 3).to_s
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should calculate January 3 2000 for January 4 2000" do
|
|
75
|
+
Date.new(2000, 1, 4).iso_year_start(1).to_s.should == Date.new(2000, 1, 3).to_s
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# it "should calculate week 1 for January 7, 2001 for a wkst of 1 (Monday)" do
|
|
79
|
+
# Date.new(2001, 1,7).iso_week_num(1).should == 1
|
|
80
|
+
# end
|
|
81
|
+
#
|
|
82
|
+
# it "should calculate week 2 for January 8, 2001 for a wkst of 1 (Monday)" do
|
|
83
|
+
# Date.new(2001, 1,8).iso_week_num(1).should == 2
|
|
84
|
+
# end
|
|
85
|
+
#
|
|
86
|
+
# it "should calculate week 52 for December 31, 2000 for a wkst of 1 (Monday)" do
|
|
87
|
+
# Date.new(2000, 12,31).iso_week_num(1).should == 52
|
|
88
|
+
# end
|
|
89
|
+
#
|
|
90
|
+
# it "should calculate week 52 for January 1, 2001 for a wkst of 2 (Tuesday)" do
|
|
91
|
+
# Date.new(2001, 1, 1).iso_week_num(2).should == 52
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
# it "should calculate week 1 for Dec 31, 2003 for a wkst of 1 (Monday)" do
|
|
95
|
+
# Date.new(2003, 12, 31).iso_week_num(1).should == 1
|
|
96
|
+
# end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "#iso_week_one" do
|
|
100
|
+
|
|
101
|
+
before(:each) do
|
|
102
|
+
@it = RiCal::CoreExtensions::Time::Calculations
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "with a monday week start" do
|
|
106
|
+
it "should return Jan 3, 2000 for 2000" do
|
|
107
|
+
@it.iso_week_one(2000, 1).should == Date.new(2000, 1, 3)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should return Jan 1, 2001 for 2001" do
|
|
111
|
+
@it.iso_week_one(2001, 1).should == Date.new(2001, 1,1)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should return Dec 31, 2001 for 2002" do
|
|
115
|
+
@it.iso_week_one(2002, 1).should == Date.new(2001, 12, 31)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "should return Dec 30, 2002 for 2003" do
|
|
119
|
+
@it.iso_week_one(2003, 1).should == Date.new(2002, 12, 30)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should return Dec 29, 2003 for 2004" do
|
|
123
|
+
@it.iso_week_one(2004, 1).should == Date.new(2003, 12, 29)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should return Jan 2, 2001 for 2001 with a Tuesday week start" do
|
|
128
|
+
@it.iso_week_one(2001, 2).should == Date.new(2001, 1, 2)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should return Jan 3, 2001 for 2001 with a Wednesday week start" do
|
|
132
|
+
@it.iso_week_one(2001, 3).should == Date.new(2001, 1, 3)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should return Jan 4, 2001 for 2001 with a Thursday week start" do
|
|
136
|
+
@it.iso_week_one(2001, 4).should == Date.new(2001, 1, 4)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should return Dec 29, 2000 for 2001 with a Friday week start" do
|
|
140
|
+
@it.iso_week_one(2001, 5).should == Date.new(2000, 12, 29)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should return Dec 30, 2000 for 2001 with a Saturday week start" do
|
|
144
|
+
@it.iso_week_one(2001, 6).should == Date.new(2000, 12, 30)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should return Dec 31, 2000 for 2001 with a Sunday week start" do
|
|
148
|
+
@it.iso_week_one(2001, 0).should == Date.new(2000, 12, 31)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe ".leap_year?" do
|
|
153
|
+
it "should return true for 2000" do
|
|
154
|
+
Date.parse("1/3/2000").should be_leap_year
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "should return false for 2007" do
|
|
158
|
+
Date.parse("1/3/2007").should_not be_leap_year
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should return true for 2008" do
|
|
162
|
+
Date.parse("1/3/2008").should be_leap_year
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "should return false for 2100" do
|
|
166
|
+
Date.parse("1/3/2100").should_not be_leap_year
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
describe ".days_in_month" do
|
|
171
|
+
|
|
172
|
+
it "should return 29 for February in a leap year" do
|
|
173
|
+
Date.new(2008, 2, 1).days_in_month.should == 29
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "should return 28 for February in a non-leap year" do
|
|
177
|
+
Date.new(2009, 2, 1).days_in_month.should == 28
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "should return 31 for January in a leap year" do
|
|
181
|
+
Date.new(2008, 1, 1).days_in_month.should == 31
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "should return 31 for January in a non-leap year" do
|
|
185
|
+
Date.new(2009, 1, 1).days_in_month.should == 31
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|