micahwedemeyer-ri_cal 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/.rvmrc +2 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +21 -0
  4. data/History.txt +402 -0
  5. data/Manifest.txt +161 -0
  6. data/README.txt +410 -0
  7. data/Rakefile +66 -0
  8. data/VERSION +1 -0
  9. data/bin/ri_cal +8 -0
  10. data/component_attributes/alarm.yml +10 -0
  11. data/component_attributes/calendar.yml +4 -0
  12. data/component_attributes/component_property_defs.yml +180 -0
  13. data/component_attributes/event.yml +45 -0
  14. data/component_attributes/freebusy.yml +16 -0
  15. data/component_attributes/journal.yml +35 -0
  16. data/component_attributes/timezone.yml +3 -0
  17. data/component_attributes/timezone_period.yml +11 -0
  18. data/component_attributes/todo.yml +46 -0
  19. data/copyrights.txt +1 -0
  20. data/docs/draft-ietf-calsify-2446bis-08.txt +7280 -0
  21. data/docs/draft-ietf-calsify-rfc2445bis-09.txt +10416 -0
  22. data/docs/incrementers.txt +7 -0
  23. data/docs/rfc2445.pdf +0 -0
  24. data/lib/ri_cal/component/alarm.rb +19 -0
  25. data/lib/ri_cal/component/calendar.rb +257 -0
  26. data/lib/ri_cal/component/event.rb +58 -0
  27. data/lib/ri_cal/component/freebusy.rb +16 -0
  28. data/lib/ri_cal/component/journal.rb +27 -0
  29. data/lib/ri_cal/component/non_standard.rb +33 -0
  30. data/lib/ri_cal/component/t_z_info_timezone.rb +153 -0
  31. data/lib/ri_cal/component/timezone/daylight_period.rb +25 -0
  32. data/lib/ri_cal/component/timezone/standard_period.rb +23 -0
  33. data/lib/ri_cal/component/timezone/timezone_period.rb +76 -0
  34. data/lib/ri_cal/component/timezone.rb +197 -0
  35. data/lib/ri_cal/component/todo.rb +42 -0
  36. data/lib/ri_cal/component.rb +256 -0
  37. data/lib/ri_cal/core_extensions/array/conversions.rb +15 -0
  38. data/lib/ri_cal/core_extensions/array.rb +7 -0
  39. data/lib/ri_cal/core_extensions/date/conversions.rb +56 -0
  40. data/lib/ri_cal/core_extensions/date.rb +13 -0
  41. data/lib/ri_cal/core_extensions/date_time/conversions.rb +50 -0
  42. data/lib/ri_cal/core_extensions/date_time.rb +15 -0
  43. data/lib/ri_cal/core_extensions/object/conversions.rb +20 -0
  44. data/lib/ri_cal/core_extensions/object.rb +8 -0
  45. data/lib/ri_cal/core_extensions/string/conversions.rb +57 -0
  46. data/lib/ri_cal/core_extensions/string.rb +8 -0
  47. data/lib/ri_cal/core_extensions/time/calculations.rb +153 -0
  48. data/lib/ri_cal/core_extensions/time/conversions.rb +42 -0
  49. data/lib/ri_cal/core_extensions/time/tzid_access.rb +50 -0
  50. data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +55 -0
  51. data/lib/ri_cal/core_extensions/time.rb +14 -0
  52. data/lib/ri_cal/core_extensions.rb +11 -0
  53. data/lib/ri_cal/fast_date_time.rb +234 -0
  54. data/lib/ri_cal/floating_timezone.rb +32 -0
  55. data/lib/ri_cal/invalid_property_value.rb +8 -0
  56. data/lib/ri_cal/invalid_timezone_identifier.rb +20 -0
  57. data/lib/ri_cal/occurrence_enumerator.rb +265 -0
  58. data/lib/ri_cal/occurrence_period.rb +17 -0
  59. data/lib/ri_cal/parser.rb +145 -0
  60. data/lib/ri_cal/properties/alarm.rb +390 -0
  61. data/lib/ri_cal/properties/calendar.rb +164 -0
  62. data/lib/ri_cal/properties/event.rb +1523 -0
  63. data/lib/ri_cal/properties/freebusy.rb +593 -0
  64. data/lib/ri_cal/properties/journal.rb +1237 -0
  65. data/lib/ri_cal/properties/timezone.rb +150 -0
  66. data/lib/ri_cal/properties/timezone_period.rb +416 -0
  67. data/lib/ri_cal/properties/todo.rb +1559 -0
  68. data/lib/ri_cal/properties.rb +12 -0
  69. data/lib/ri_cal/property_value/array.rb +27 -0
  70. data/lib/ri_cal/property_value/cal_address.rb +11 -0
  71. data/lib/ri_cal/property_value/date.rb +184 -0
  72. data/lib/ri_cal/property_value/date_time/additive_methods.rb +44 -0
  73. data/lib/ri_cal/property_value/date_time/time_machine.rb +159 -0
  74. data/lib/ri_cal/property_value/date_time/timezone_support.rb +100 -0
  75. data/lib/ri_cal/property_value/date_time.rb +359 -0
  76. data/lib/ri_cal/property_value/duration.rb +110 -0
  77. data/lib/ri_cal/property_value/geo.rb +11 -0
  78. data/lib/ri_cal/property_value/integer.rb +12 -0
  79. data/lib/ri_cal/property_value/occurrence_list.rb +144 -0
  80. data/lib/ri_cal/property_value/period.rb +86 -0
  81. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +100 -0
  82. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +79 -0
  83. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +148 -0
  84. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +53 -0
  85. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +31 -0
  86. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb +86 -0
  87. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb +31 -0
  88. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb +32 -0
  89. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb +52 -0
  90. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb +31 -0
  91. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb +38 -0
  92. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb +32 -0
  93. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb +69 -0
  94. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb +31 -0
  95. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb +28 -0
  96. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb +80 -0
  97. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb +23 -0
  98. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb +106 -0
  99. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb +23 -0
  100. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb +33 -0
  101. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb +43 -0
  102. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb +28 -0
  103. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb +37 -0
  104. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb +57 -0
  105. data/lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb +135 -0
  106. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +131 -0
  107. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +64 -0
  108. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +33 -0
  109. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +53 -0
  110. data/lib/ri_cal/property_value/recurrence_rule/time_manipulation.rb +42 -0
  111. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +125 -0
  112. data/lib/ri_cal/property_value/recurrence_rule.rb +154 -0
  113. data/lib/ri_cal/property_value/text.rb +44 -0
  114. data/lib/ri_cal/property_value/uri.rb +11 -0
  115. data/lib/ri_cal/property_value/utc_offset.rb +33 -0
  116. data/lib/ri_cal/property_value/zulu_date_time.rb +34 -0
  117. data/lib/ri_cal/property_value.rb +159 -0
  118. data/lib/ri_cal/required_timezones.rb +55 -0
  119. data/lib/ri_cal.rb +187 -0
  120. data/micahwedemeyer-ri_cal.gemspec +227 -0
  121. data/parked_specs/ri_cal/claudio_a_bug_spec.rb +100 -0
  122. data/performance/empty_propval/subject.rb +43 -0
  123. data/performance/paris_eastern/subject.rb +90 -0
  124. data/performance/penultimate_weekday/subject.rb +15 -0
  125. data/performance/psm_big_enum/ical.ics +3171 -0
  126. data/performance/psm_big_enum/subject.rb +16 -0
  127. data/performance/utah_cycling/subject.rb +55 -0
  128. data/sample_ical_files/from_ical_dot_app/test1.ics +38 -0
  129. data/script/benchmark_subject +23 -0
  130. data/script/console +10 -0
  131. data/script/destroy +14 -0
  132. data/script/generate +14 -0
  133. data/script/profile_subject +29 -0
  134. data/script/txt2html +71 -0
  135. data/spec/ri_cal/bugreports_spec.rb +287 -0
  136. data/spec/ri_cal/component/alarm_spec.rb +12 -0
  137. data/spec/ri_cal/component/calendar_spec.rb +88 -0
  138. data/spec/ri_cal/component/event_spec.rb +735 -0
  139. data/spec/ri_cal/component/freebusy_spec.rb +12 -0
  140. data/spec/ri_cal/component/journal_spec.rb +37 -0
  141. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +60 -0
  142. data/spec/ri_cal/component/timezone_spec.rb +236 -0
  143. data/spec/ri_cal/component/todo_spec.rb +112 -0
  144. data/spec/ri_cal/component_spec.rb +224 -0
  145. data/spec/ri_cal/core_extensions/string/conversions_spec.rb +78 -0
  146. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +188 -0
  147. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +45 -0
  148. data/spec/ri_cal/fast_date_time_spec.rb +77 -0
  149. data/spec/ri_cal/inf_loop_spec.rb +78 -0
  150. data/spec/ri_cal/occurrence_enumerator_spec.rb +611 -0
  151. data/spec/ri_cal/parser_spec.rb +337 -0
  152. data/spec/ri_cal/property_value/date_spec.rb +53 -0
  153. data/spec/ri_cal/property_value/date_time_spec.rb +383 -0
  154. data/spec/ri_cal/property_value/duration_spec.rb +126 -0
  155. data/spec/ri_cal/property_value/occurrence_list_spec.rb +72 -0
  156. data/spec/ri_cal/property_value/period_spec.rb +63 -0
  157. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +21 -0
  158. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1814 -0
  159. data/spec/ri_cal/property_value/text_spec.rb +25 -0
  160. data/spec/ri_cal/property_value/utc_offset_spec.rb +48 -0
  161. data/spec/ri_cal/property_value_spec.rb +125 -0
  162. data/spec/ri_cal/required_timezones_spec.rb +67 -0
  163. data/spec/ri_cal_spec.rb +53 -0
  164. data/spec/spec.opts +4 -0
  165. data/spec/spec_helper.rb +50 -0
  166. data/tasks/gem_loader/load_active_support.rb +3 -0
  167. data/tasks/gem_loader/load_tzinfo_gem.rb +2 -0
  168. data/tasks/ri_cal.rake +412 -0
  169. data/tasks/spec.rake +102 -0
  170. data/website/images/rubytrends.png +0 -0
  171. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  172. data/website/stylesheets/screen.css +159 -0
  173. metadata +307 -0
@@ -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
@@ -0,0 +1,45 @@
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::WeekDayPredicates do
6
+
7
+ describe ".nth_wday_in_month" do
8
+ it "should return Feb 28, 2005 for the 4th Monday for a date in February 2005" do
9
+ expected = RiCal::PropertyValue::Date.new(nil, :value => "20050228")
10
+ it = Date.parse("Feb 7, 2005").nth_wday_in_month(4, 1)
11
+ it.should == expected
12
+ end
13
+ end
14
+
15
+ describe ".nth_wday_in_month?" do
16
+ it "should return true for Feb 28, 2005 for the 4th Monday" do
17
+ Date.parse("Feb 28, 2005").nth_wday_in_month?(4, 1).should be
18
+ end
19
+ end
20
+
21
+ describe ".start_of_week_with_wkst" do
22
+ describe "for Wednesday Sept 10 1997" do
23
+ before(:each) do
24
+ @date = Date.parse("Sept 10, 1997")
25
+ end
26
+
27
+ it "should return a Date of Sept 7, 1997 00:00 for a wkst of 0 - Sunday" do
28
+ @date.start_of_week_with_wkst(0).should == Date.parse("Sept 7, 1997")
29
+ end
30
+
31
+ it "should return a Date of Sept 8, 1997 00:00 for a wkst of 1 - Monday" do
32
+ @date.start_of_week_with_wkst(1).should == Date.parse("Sept 8, 1997")
33
+ end
34
+
35
+ it "should return a Date of Sept 10, 1997 00:00 for a wkst of 3 - Wednesday" do
36
+ @date.start_of_week_with_wkst(3).should == Date.parse("Sept 10, 1997")
37
+ end
38
+
39
+ it "should return a Date of Sept 4, 1997 00:00 for a wkst of 4 - Thursday" do
40
+ @date.start_of_week_with_wkst(4).should == Date.parse("Sept 4, 1997")
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,77 @@
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
+ module RiCal
6
+
7
+ describe RiCal::FastDateTime do
8
+ context "#utc" do
9
+ it "should not change if it is already UTC" do
10
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).utc.should == FastDateTime.new(2009, 5, 29, 19, 3, 0, 0)
11
+ end
12
+
13
+ it "should change the time by the offset" do
14
+ FastDateTime.new(2010, 4, 15, 16, 3, 0, -4*60*60).utc.should == FastDateTime.new(2010, 4, 15, 20, 3, 0, 0)
15
+ end
16
+ end
17
+
18
+ context "#==" do
19
+ it "should detect equal FastDateTimes" do
20
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).should ==
21
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0)
22
+ end
23
+
24
+ it "should detect unequal FastDateTimes" do
25
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).should_not ==
26
+ FastDateTime.new(2009, 5, 29, 19, 3, 10, 0)
27
+ end
28
+
29
+ context "#advance" do
30
+ it "should advance one second" do
31
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:seconds => 1).should ==
32
+ FastDateTime.new(2009, 5, 29, 19, 3, 1, 0)
33
+ end
34
+
35
+ it "should advance minus one second" do
36
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:seconds => -1).should ==
37
+ FastDateTime.new(2009, 5, 29, 19, 2, 59, 0)
38
+ end
39
+
40
+ it "should advance 70 seconds" do
41
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:seconds => 70).should ==
42
+ FastDateTime.new(2009, 5, 29, 19, 4, 10, 0)
43
+ end
44
+
45
+ it "should advance -70 seconds" do
46
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:seconds => -70).should ==
47
+ FastDateTime.new(2009, 5, 29, 19, 1, 50, 0)
48
+ end
49
+
50
+ it "should advance one minute" do
51
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:minutes => 1).should ==
52
+ FastDateTime.new(2009, 5, 29, 19, 4, 0, 0)
53
+ end
54
+
55
+ it "should advance minus one minute" do
56
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:minutes => -1).should ==
57
+ FastDateTime.new(2009, 5, 29, 19, 2, 0, 0)
58
+ end
59
+
60
+ it "should advance 70 minutes" do
61
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:minutes => 70).should ==
62
+ FastDateTime.new(2009, 5, 29, 20, 13, 0, 0)
63
+ end
64
+
65
+ it "should advance -70 minutes" do
66
+ FastDateTime.new(2009, 5, 29, 19, 3, 0, 0).advance(:minutes => -70).should ==
67
+ FastDateTime.new(2009, 5, 29, 17, 53, 0, 0)
68
+ end
69
+
70
+ it "should advance properly over a date" do
71
+ FastDateTime.new(2009, 5, 29, 23, 3, 0, 0).advance(:minutes => 70).should ==
72
+ FastDateTime.new(2009, 5, 30, 0, 13, 0, 0)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,78 @@
1
+ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
2
+
3
+ require 'rubygems'
4
+ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
+
6
+ describe "an event with unneeded by parts" do
7
+ before(:each) do
8
+ rawdata = <<END_STR
9
+ BEGIN:VCALENDAR
10
+ PRODID:-//Google Inc//Google Calendar 70.9054//EN
11
+ VERSION:2.0
12
+ CALSCALE:GREGORIAN
13
+ METHOD:PUBLISH
14
+ X-WR-CALNAME:RICal teste
15
+ X-WR-TIMEZONE:America/Sao_Paulo
16
+ X-WR-CALDESC:
17
+ BEGIN:VTIMEZONE
18
+ TZID:America/Sao_Paulo
19
+ X-LIC-LOCATION:America/Sao_Paulo
20
+ BEGIN:DAYLIGHT
21
+ TZOFFSETFROM:-0300
22
+ TZOFFSETTO:-0200
23
+ TZNAME:BRST
24
+ DTSTART:19701018T000000
25
+ RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=3SU
26
+ END:DAYLIGHT
27
+ BEGIN:STANDARD
28
+ TZOFFSETFROM:-0300
29
+ TZOFFSETTO:-0300
30
+ TZNAME:BRT
31
+ DTSTART:19700215T000000
32
+ RRULE:FREQ=YEARLY;BYMONTH=2;BYDAY=3SU
33
+ END:STANDARD
34
+ END:VTIMEZONE
35
+ BEGIN:VEVENT
36
+ DTSTART;VALUE=DATE:19400713
37
+ DTEND;VALUE=DATE:19400714
38
+ RRULE:FREQ=YEARLY;BYMONTH=7;BYMONTHDAY=13
39
+ DTSTAMP:20091109T161426Z
40
+ UID:CD0000008B9511D182D800C04FB1625DF48568F41595384496C2570C025DC032
41
+ CREATED:20090924T160743Z
42
+ DESCRIPTION: Description test 12
43
+ LAST-MODIFIED:20090924T160945Z
44
+ LOCATION: Location test 12
45
+ SEQUENCE:0
46
+ STATUS:CONFIRMED
47
+ SUMMARY: Event test 12
48
+ TRANSP:TRANSPARENT
49
+ END:VEVENT
50
+ END:VCALENDAR
51
+ END_STR
52
+ @cal = RiCal.parse_string(rawdata).first
53
+ @event = @cal.events.first
54
+ end
55
+
56
+ it "should enumerate 10 events from July 13, 1940 to July 13, 1949 when count is 10" do
57
+ @event.occurrences(:count => 10).map {|occurrence| occurrence.dtstart}.should == (0..9).map {|y|
58
+ Date.parse("July 13, #{1940+y}")
59
+ }
60
+ end
61
+
62
+ # describe "with a dtstart outside the recurrence rule" do
63
+ # before(:each) do
64
+ # @event.dtstart = Date.parse("July 12, 1940")
65
+ # end
66
+ #
67
+ # it "should enumerate 10 events first July 12, 1940, July 13, 1940, July 13, 1941 when count is 3" do
68
+ # @event.occurrences(:count => 3).map {|occurrence| occurrence.dtstart.to_s}.should == [
69
+ # Date.parse("July 12, 1940").to_s,
70
+ # Date.parse("July 13, 1940").to_s,
71
+ # Date.parse("July 13, 1941").to_s
72
+ # ]
73
+ #
74
+ # end
75
+ #
76
+ # end
77
+
78
+ end