demingfactor-ri_cal 0.9.0
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.
- checksums.yaml +7 -0
- 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/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/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/timezone.rb +197 -0
- data/lib/ri_cal/component/todo.rb +42 -0
- data/lib/ri_cal/component.rb +256 -0
- data/lib/ri_cal/core_extensions/array/conversions.rb +15 -0
- data/lib/ri_cal/core_extensions/array.rb +7 -0
- data/lib/ri_cal/core_extensions/date/conversions.rb +56 -0
- data/lib/ri_cal/core_extensions/date.rb +13 -0
- data/lib/ri_cal/core_extensions/date_time/conversions.rb +50 -0
- data/lib/ri_cal/core_extensions/date_time.rb +15 -0
- data/lib/ri_cal/core_extensions/object/conversions.rb +20 -0
- data/lib/ri_cal/core_extensions/object.rb +8 -0
- data/lib/ri_cal/core_extensions/string/conversions.rb +57 -0
- data/lib/ri_cal/core_extensions/string.rb +8 -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/core_extensions/time.rb +14 -0
- data/lib/ri_cal/core_extensions.rb +11 -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 +148 -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/properties.rb +12 -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/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/date_time.rb +359 -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/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/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/occurrence_incrementer.rb +135 -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/recurrence_rule.rb +154 -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/property_value.rb +159 -0
- data/lib/ri_cal/required_timezones.rb +55 -0
- data/lib/ri_cal.rb +187 -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 +246 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
|
4
|
+
|
5
|
+
describe RiCal::PropertyValue::Text do
|
6
|
+
|
7
|
+
context ".ruby_value" do
|
8
|
+
|
9
|
+
it "should handle escapes according to RFC2445 Sec 4.3.11 p 45" do
|
10
|
+
expected = "this\\ has\, \nescaped\;\n\\x characters"
|
11
|
+
it = RiCal::PropertyValue::Text.new(nil, :value => 'this\\ has\, \nescaped\;\N\x characters')
|
12
|
+
it.ruby_value.should == expected
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context ".convert" do
|
17
|
+
|
18
|
+
it "should handle escapes according to RFC2445 Sec 4.3.11 p 45" do
|
19
|
+
expected = ':this has\, \nescaped\;\n characters\ncr\nnlcr\ncrnl'
|
20
|
+
it = RiCal::PropertyValue::Text.convert(nil, "this\ has, \nescaped;\n characters\rcr\n\rnlcr\r\ncrnl")
|
21
|
+
it.to_s.should == expected
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
|
4
|
+
|
5
|
+
describe RiCal::PropertyValue::UtcOffset do
|
6
|
+
|
7
|
+
describe "with a positive sign and seconds" do
|
8
|
+
before(:each) do
|
9
|
+
@it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "+013015")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have +1 as its sign" do
|
13
|
+
@it.sign.should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have 1 as its hours" do
|
17
|
+
@it.hours.should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have 30 as its minutes" do
|
21
|
+
@it.minutes.should == 30
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have 15 as its seconds" do
|
25
|
+
@it.seconds.should == 15
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with seconds omitted" do
|
30
|
+
before(:each) do
|
31
|
+
@it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "+0130")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have 0 as its seconds" do
|
35
|
+
@it.seconds.should == 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "with a negative sign" do
|
39
|
+
before(:each) do
|
40
|
+
@it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "-013015")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have +1 as its sign" do
|
44
|
+
@it.sign.should == -1
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
|
2
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
3
|
+
require 'tzinfo'
|
4
|
+
|
5
|
+
describe RiCal::PropertyValue do
|
6
|
+
|
7
|
+
describe ".initialize" do
|
8
|
+
|
9
|
+
it "should reject a value starting with ';'" do
|
10
|
+
lambda {RiCal::PropertyValue.new(nil, :value => ";bogus")}.should raise_error {|err| err.message.should == "Invalid property value \";bogus\""}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#date_or_date_time" do
|
15
|
+
|
16
|
+
it "should raise an exception on an invalid date" do
|
17
|
+
lambda {RiCal::PropertyValue.date_or_date_time(nil, :value => "foo")}.should raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe "rfc 2445 section 4.3.4 p 34" do
|
22
|
+
before(:each) do
|
23
|
+
@prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a PropertyValue::Date" do
|
27
|
+
@prop.should be_kind_of(RiCal::PropertyValue::Date)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the correct date" do
|
31
|
+
@prop.to_ri_cal_ruby_value.should == Date.parse("Jul 14, 1997")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "rfc 2445 section 4.3.5 p 35" do
|
36
|
+
describe "FORM #1 date with local time p 36" do
|
37
|
+
before(:each) do
|
38
|
+
@prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return a PropertyValue::DateTime" do
|
42
|
+
@prop.should be_kind_of(RiCal::PropertyValue::DateTime)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have the right ruby value" do
|
46
|
+
@prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have the right value" do
|
50
|
+
@prop.value.should == "19970714T123456"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have a nil tzid" do
|
54
|
+
@prop.tzid.should == nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "FORM #2 date with UTC time p 36" do
|
59
|
+
before(:each) do
|
60
|
+
@prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456Z")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return a PropertyValue::DateTime" do
|
64
|
+
@prop.should be_kind_of(RiCal::PropertyValue::DateTime)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have the right value" do
|
68
|
+
@prop.value.should == "19970714T123456Z"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have the right ruby value" do
|
72
|
+
@prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456Z")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have a tzid of UTC" do
|
76
|
+
@prop.tzid.should == "UTC"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "FORM #3 date with local time and time zone reference p 36" do
|
82
|
+
before(:each) do
|
83
|
+
timezone = mock("Timezone",
|
84
|
+
:rational_utc_offset => Rational(-4, 24),
|
85
|
+
:local_to_utc => RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T163456Z"),
|
86
|
+
:name => 'US-Eastern'
|
87
|
+
)
|
88
|
+
timezone_finder = mock("tz_finder", :find_timezone => timezone)
|
89
|
+
@prop = RiCal::PropertyValue.date_or_date_time(timezone_finder, :value => "19970714T123456", :params => {'TZID' => 'US-Eastern'})
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a PropertyValue::DateTime" do
|
93
|
+
@prop.should be_kind_of(RiCal::PropertyValue::DateTime)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should have the right value" do
|
97
|
+
@prop.value.should == "19970714T123456"
|
98
|
+
end
|
99
|
+
|
100
|
+
context "it's Ruby value" do
|
101
|
+
before(:each) do
|
102
|
+
@it = @prop.ruby_value
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be the right DateTime" do
|
106
|
+
@it.should == DateTime.civil(1997,7, 14, 12, 34, 56, Rational(-4, 24))
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have the right tzid" do
|
110
|
+
@it.tzid.should == "US-Eastern"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should have the right tzid" do
|
115
|
+
@prop.tzid.should == "US-Eastern"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should raise an error if combined with a zulu time" do
|
119
|
+
lambda {RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456Z", :params => {:tzid => 'US-Eastern'})}.should raise_error
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
4
|
+
|
5
|
+
require 'tzinfo'
|
6
|
+
|
7
|
+
describe RiCal::RequiredTimezones::RequiredTimezone do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@tzid = "America/New_York"
|
11
|
+
@it = RiCal::RequiredTimezones::RequiredTimezone.new(@tzid)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have the right timezone" do
|
15
|
+
@it.timezone.identifier.should == @tzid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set the first_time to the first date_time added" do
|
19
|
+
dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
|
20
|
+
@it.add_datetime(dt1)
|
21
|
+
@it.first_time.should == dt1
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the first_time to the earliest time added" do
|
25
|
+
dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
|
26
|
+
dt2 = dt_prop(DateTime.parse("Mar 22, 2009 9:00"))
|
27
|
+
dt3 = dt_prop(DateTime.parse("Mar 22, 2009 10:00"))
|
28
|
+
@it.add_datetime(dt1)
|
29
|
+
@it.add_datetime(dt2)
|
30
|
+
@it.add_datetime(dt3)
|
31
|
+
@it.first_time.should == dt2
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set the last_time to the first date_time added" do
|
35
|
+
dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
|
36
|
+
@it.add_datetime(dt1)
|
37
|
+
@it.last_time.should == dt1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should set the first_time to the earliest time added" do
|
41
|
+
dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
|
42
|
+
dt2 = dt_prop(DateTime.parse("Mar 22, 2009 9:00"))
|
43
|
+
dt3 = dt_prop(DateTime.parse("Mar 22, 2009 10:00"))
|
44
|
+
@it.add_datetime(dt1)
|
45
|
+
@it.add_datetime(dt2)
|
46
|
+
@it.add_datetime(dt3)
|
47
|
+
@it.last_time.should == dt1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe RiCal::RequiredTimezones do
|
52
|
+
before(:each) do
|
53
|
+
@it = RiCal::RequiredTimezones.new
|
54
|
+
end
|
55
|
+
|
56
|
+
def localtime_and_zone(date_time, tzid = "US/Eastern")
|
57
|
+
[dt_prop(DateTime.parse(date_time), tzid), tzid]
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
it "should create a RequiredTimezone for each new timezone presented" do
|
62
|
+
@it.add_datetime(*localtime_and_zone("Mar 22, 2009 1:00"))
|
63
|
+
@it.add_datetime(*localtime_and_zone("Apr 16, 2008 12:00", "US/Central"))
|
64
|
+
@it.add_datetime(*localtime_and_zone("Apr 16, 2008 12:00"))
|
65
|
+
@it.required_zones.map {|zone| zone.tzid}.sort.should == ["US/Central", "US/Eastern"]
|
66
|
+
end
|
67
|
+
end
|
data/spec/ri_cal_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
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 do
|
6
|
+
|
7
|
+
|
8
|
+
describe "#parse" do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@mock_parser = mock("parser", :parse => [])
|
12
|
+
RiCal::Parser.stub!(:new).and_return(@mock_parser)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create a parser using the io parameter" do
|
16
|
+
io = StringIO.new("")
|
17
|
+
RiCal::Parser.should_receive(:new).with(io).and_return(@mock_parser)
|
18
|
+
RiCal.parse(io)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should delegate to the parser" do
|
22
|
+
io = StringIO.new("")
|
23
|
+
@mock_parser.should_receive(:parse)
|
24
|
+
RiCal.parse(io)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the results of the parse" do
|
28
|
+
io = StringIO.new("")
|
29
|
+
@mock_parser.stub!(:parse).and_return(:parse_result)
|
30
|
+
RiCal.parse(io).should == :parse_result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#parse_string" do
|
35
|
+
before(:each) do
|
36
|
+
@mock_io = :mock_io
|
37
|
+
StringIO.stub!(:new).and_return(@mock_io)
|
38
|
+
RiCal.stub!(:parse)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create a StringIO from the string" do
|
42
|
+
string = "test string"
|
43
|
+
StringIO.should_receive(:new).with(string)
|
44
|
+
RiCal.parse_string(string)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should parse" do
|
48
|
+
RiCal.should_receive(:parse).with(@mock_io)
|
49
|
+
RiCal.parse_string("")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ri_cal]))
|
4
|
+
require 'cgi'
|
5
|
+
require 'tzinfo'
|
6
|
+
|
7
|
+
|
8
|
+
module Kernel
|
9
|
+
if ENV.keys.find {|env_var| env_var.match(/^TM_/)}
|
10
|
+
def rputs(*args)
|
11
|
+
puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"])
|
12
|
+
end
|
13
|
+
else
|
14
|
+
alias_method :rputs, :puts
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def date_time_with_zone(date_time, tzid = "US/Eastern")
|
19
|
+
date_time.dup.set_tzid(tzid)
|
20
|
+
end
|
21
|
+
|
22
|
+
def dt_prop(date_time, tzid = "US/Eastern")
|
23
|
+
RiCal::PropertyValue::DateTime.convert(nil, date_time_with_zone(date_time, tzid))
|
24
|
+
end
|
25
|
+
|
26
|
+
def offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate)
|
27
|
+
tz = TZInfo::Timezone.get(tzid) rescue nil
|
28
|
+
if tz
|
29
|
+
Rational(tz.period_for_local(DateTime.civil(year, month, day, hour, min, sec)).utc_total_offset, 86400)
|
30
|
+
else
|
31
|
+
provided_offset
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def rectify_ical(string)
|
36
|
+
string.gsub(/^\s+/, "")
|
37
|
+
end
|
38
|
+
|
39
|
+
if RiCal::TimeWithZone
|
40
|
+
def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
|
41
|
+
DateTime.civil(year, month, day, hour, min, sec,
|
42
|
+
offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate_offset)).in_time_zone(tzid)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
|
46
|
+
DateTime.civil(year, month, day, hour, min, sec,
|
47
|
+
offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate_offset)).set_tzid(tzid)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|