runt19 0.7.6

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.
Files changed (63) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/History.txt +153 -0
  4. data/LICENSE +22 -0
  5. data/LICENSE.txt +44 -0
  6. data/Manifest.txt +112 -0
  7. data/README.md +29 -0
  8. data/README.txt +106 -0
  9. data/Rakefile +2 -0
  10. data/TODO +13 -0
  11. data/examples/payment_report.rb +59 -0
  12. data/examples/payment_reporttest.rb +49 -0
  13. data/examples/reminder.rb +63 -0
  14. data/examples/schedule_tutorial.rb +59 -0
  15. data/examples/schedule_tutorialtest.rb +52 -0
  16. data/lib/runt.rb +249 -0
  17. data/lib/runt/daterange.rb +74 -0
  18. data/lib/runt/dprecision.rb +150 -0
  19. data/lib/runt/expressionbuilder.rb +65 -0
  20. data/lib/runt/pdate.rb +165 -0
  21. data/lib/runt/schedule.rb +88 -0
  22. data/lib/runt/sugar.rb +171 -0
  23. data/lib/runt/temporalexpression.rb +795 -0
  24. data/lib/runt/version.rb +3 -0
  25. data/lib/runt19.rb +1 -0
  26. data/runt19.gemspec +17 -0
  27. data/setup.rb +1331 -0
  28. data/site/blue-robot3.css +132 -0
  29. data/site/dcl-small.gif +0 -0
  30. data/site/index.html +72 -0
  31. data/site/logohover.png +0 -0
  32. data/site/runt-logo.gif +0 -0
  33. data/site/runt-logo.psd +0 -0
  34. data/test/aftertetest.rb +31 -0
  35. data/test/baseexpressiontest.rb +110 -0
  36. data/test/beforetetest.rb +31 -0
  37. data/test/collectiontest.rb +63 -0
  38. data/test/combinedexpressionstest.rb +158 -0
  39. data/test/daterangetest.rb +89 -0
  40. data/test/dayintervaltetest.rb +37 -0
  41. data/test/difftest.rb +37 -0
  42. data/test/dimonthtest.rb +59 -0
  43. data/test/diweektest.rb +32 -0
  44. data/test/dprecisiontest.rb +58 -0
  45. data/test/everytetest.rb +36 -0
  46. data/test/expressionbuildertest.rb +64 -0
  47. data/test/icalendartest.rb +1104 -0
  48. data/test/intersecttest.rb +34 -0
  49. data/test/pdatetest.rb +147 -0
  50. data/test/redaytest.rb +40 -0
  51. data/test/remonthtest.rb +37 -0
  52. data/test/reweektest.rb +51 -0
  53. data/test/reyeartest.rb +99 -0
  54. data/test/rspectest.rb +25 -0
  55. data/test/runttest.rb +98 -0
  56. data/test/scheduletest.rb +148 -0
  57. data/test/spectest.rb +36 -0
  58. data/test/sugartest.rb +104 -0
  59. data/test/temporalexpressiontest.rb +76 -0
  60. data/test/uniontest.rb +36 -0
  61. data/test/wimonthtest.rb +54 -0
  62. data/test/yeartetest.rb +22 -0
  63. metadata +137 -0
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baseexpressiontest'
4
+
5
+ # Unit tests for EveryTE class
6
+ # Author:: Matthew Lipper
7
+
8
+ class EveryTETest < BaseExpressionTest
9
+
10
+
11
+ def test_every_2_minutes
12
+ date = @pdate_200401282100
13
+ expr=EveryTE.new(date, 2)
14
+ assert expr.include?(date + 2), "Expression #{expr.to_s} should include #{(date + 2).to_s}"
15
+ assert expr.include?(date + 4), "Expression #{expr.to_s} should include #{(date + 4).to_s}"
16
+ assert !expr.include?(date - 2), "Expression #{expr.to_s} should not include #{(date - 2).to_s}"
17
+ end
18
+
19
+ def test_every_3_days
20
+ # Match every 3 days begining 2007-11-14
21
+ date = @pdate_20071114
22
+ expr=EveryTE.new(date, 3)
23
+ assert expr.include?(date + 6), "Expression #{expr.to_s} should include #{(date + 6).to_s}"
24
+ assert expr.include?(date + 9), "Expression #{expr.to_s} should include #{(date + 9).to_s}"
25
+ assert !expr.include?(date + 1), "Expression #{expr.to_s} should not include #{(date + 1).to_s}"
26
+ assert !expr.include?(date - 3), "Expression #{expr.to_s} should not include #{(date - 3).to_s}"
27
+ end
28
+
29
+
30
+ def test_to_s
31
+ date=@pdate_20071116100030
32
+ every_thirty_seconds=EveryTE.new(date, 30)
33
+ assert_equal "every 30 seconds starting #{Runt.format_date(date)}", every_thirty_seconds.to_s
34
+ end
35
+
36
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+
6
+ class ExpressionBuilderTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @builder = ExpressionBuilder.new
10
+ end
11
+
12
+ def test_define_should_instance_eval_a_block
13
+ @builder.define do
14
+ @ctx = "meow"
15
+ end
16
+ assert_equal "meow", @builder.ctx, "Expected instance variable @ctx to be set by block"
17
+ end
18
+
19
+ def test_add_should_initialize_empty_ctx_with_expression
20
+ result = @builder.add('expr',:to_s)
21
+ assert_equal 'expr', result, "Result should equal string given to add method"
22
+ assert_equal 'expr', @builder.ctx, "Builder context should equal result"
23
+ end
24
+
25
+ def test_add_should_send_op_to_ctx_with_expression
26
+ @builder.add('abc',:to_s)
27
+ result = @builder.add('def',:concat)
28
+ assert_equal 'abcdef', result, "Result should equal concatenated strings given to add method"
29
+ assert_equal 'abcdef', @builder.ctx, "Builder context should equal result"
30
+ end
31
+
32
+ def test_on_should_call_add_with_expression_and_ampersand
33
+ @builder.add(1,:to_s)
34
+ result = @builder.on(3) # result = 1 & 3
35
+ assert_equal 1, result, "Result should equal 1 == 1 & 3"
36
+ assert_equal 1, @builder.ctx, "Builder context should equal result"
37
+ end
38
+
39
+ def test_except_should_call_add_with_expression_and_minus
40
+ @builder.add(1,:to_s)
41
+ result = @builder.except(3) # result = 1 - 3
42
+ assert_equal -2, result, "Result should equal -2 == 1 - 3"
43
+ assert_equal -2, @builder.ctx, "Builder context should equal result"
44
+ end
45
+
46
+ def test_possibly_should_call_add_with_expression_and_pipe
47
+ @builder.add(1, :to_s)
48
+ result = @builder.possibly(2) # result = 1 | 2
49
+ assert_equal 3, result, "Result should equal 3 == 1 | 2"
50
+ assert_equal 3, @builder.ctx, "Builder context should equal result"
51
+ end
52
+
53
+ def test_builder_created_expression_should_equal_manually_created_expression
54
+ manual = Runt::REDay.new(8,45,9,30) & Runt::DIWeek.new(Runt::Friday) | \
55
+ Runt::DIWeek.new(Runt::Saturday) - Runt::DIMonth.new(Runt::Last, Runt::Friday)
56
+ expression = @builder.define do
57
+ on daily_8_45am_to_9_30am
58
+ on friday
59
+ possibly saturday
60
+ except last_friday
61
+ end
62
+ assert_equal manual.to_s, expression.to_s, "Expected #{manual.to_s} but was #{expression.to_s}"
63
+ end
64
+ end
@@ -0,0 +1,1104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'date'
5
+ require 'runt'
6
+ require 'set'
7
+
8
+ include Runt
9
+
10
+ # RFC 2445 is the iCalendar specification. It includes dozens of
11
+ # specific examples that make great tests for Runt temporal expressions.
12
+ class ICalendarTest < Test::Unit::TestCase
13
+
14
+ # "Daily for 10 occurences"
15
+ def test_example_1
16
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
17
+ end_date = start_date + 365 #Sep 2, 1998
18
+
19
+ #rrule = RecurrenceRule.new("FREQ=DAILY;COUNT=10")
20
+ te = REWeek.new(Sun, Sat)
21
+
22
+ expected = ICalendarTest.get_date_range(start_date, DateTime.parse("US-Eastern:19970911T090000"))
23
+ results = te.dates(DateRange.new(start_date, end_date), 10)
24
+ assert_equal(expected, results)
25
+ end
26
+
27
+ # "Daily until December 24, 1997"
28
+ def test_example_2
29
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
30
+ end_date = start_date + 365
31
+
32
+ #rrule = RecurrenceRule.new("FREQ=DAILY;UNTIL=19971224T000000Z")
33
+ te = BeforeTE.new(DateTime.parse("19971224T090000"), true) & REWeek.new(Sun, Sat)
34
+
35
+ expected = ICalendarTest.get_date_range(start_date, DateTime.parse("19971224T090000"))
36
+ results = te.dates(DateRange.new(start_date, end_date))
37
+ assert_equal(expected, results)
38
+ end
39
+
40
+ # "Every other day - forever"
41
+ def test_example_3
42
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2
43
+ end_date = DateTime.parse("US-Eastern:19971003T090000") #Oct 3
44
+
45
+ #rrule = RecurrenceRule.new("FREQ=DAILY;INTERVAL=2")
46
+
47
+ expected = [
48
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
49
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
50
+ DateTime.parse("US-Eastern:19970906T090000"), #Sep 6
51
+ DateTime.parse("US-Eastern:19970908T090000"), #Sep 8
52
+ DateTime.parse("US-Eastern:19970910T090000"), #Sep 10
53
+ DateTime.parse("US-Eastern:19970912T090000"), #Sep 12
54
+ DateTime.parse("US-Eastern:19970914T090000"), #Sep 14
55
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
56
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
57
+ DateTime.parse("US-Eastern:19970920T090000"), #Sep 20
58
+ DateTime.parse("US-Eastern:19970922T090000"), #Sep 22
59
+ DateTime.parse("US-Eastern:19970924T090000"), #Sep 24
60
+ DateTime.parse("US-Eastern:19970926T090000"), #Sep 26
61
+ DateTime.parse("US-Eastern:19970928T090000"), #Sep 28
62
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
63
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 02
64
+ ]
65
+
66
+ te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 2, DPrecision::DAY)
67
+ results = te.dates(DateRange.new(start_date, end_date))
68
+ assert_equal(expected, results)
69
+
70
+ #alternatively we could use the DayIntervalTE
71
+ te = DayIntervalTE.new(start_date, 2)
72
+ results = te.dates(DateRange.new(start_date, end_date))
73
+ assert_equal(expected, results)
74
+ end
75
+
76
+ # "Every 10 days, 5 occurrences"
77
+ def test_example_4
78
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
79
+ end_date = start_date + 180 #Mar 1, 1998 (halved the normal test range because EveryTE is pretty slow)
80
+
81
+ #rrule = RecurrenceRule.new("FREQ=DAILY;INTERVAL=10;COUNT=5")
82
+
83
+ expected = [
84
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
85
+ DateTime.parse("US-Eastern:19970912T090000"), #Sep 12
86
+ DateTime.parse("US-Eastern:19970922T090000"), #Sep 22
87
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
88
+ DateTime.parse("US-Eastern:19971012T090000"), #Oct 12
89
+ ]
90
+
91
+ te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 10, DPrecision::DAY)
92
+ results = te.dates(DateRange.new(start_date, end_date), 5)
93
+ assert_equal(expected, results)
94
+
95
+ #alternatively we could use the DayIntervalTE
96
+ te = DayIntervalTE.new(start_date, 10)
97
+ results = te.dates(DateRange.new(start_date, end_date), 5 )
98
+ assert_equal(expected, results)
99
+ end
100
+
101
+ # "Every day in January, for 3 years" (first example, yearly byday)
102
+ def test_example_5_a
103
+ start_date = DateTime.parse("US-Eastern:19980101T090000") #Jan 1, 1998
104
+ end_date = start_date + 365 + 365 + 366 + 31 #Feb 1, 2001
105
+
106
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA")
107
+
108
+ expected = []
109
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19980101T090000"), DateTime.parse("US-Eastern:19980131T090000"))
110
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19990101T090000"), DateTime.parse("US-Eastern:19990131T090000"))
111
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:20000101T090000"), DateTime.parse("US-Eastern:20000131T090000"))
112
+
113
+ te = BeforeTE.new(DateTime.parse("20000131T090000"), true) & REYear.new(1) & (DIWeek.new(Sun) | DIWeek.new(Mon) | DIWeek.new(Tue) | DIWeek.new(Wed) | DIWeek.new(Thu) | DIWeek.new(Fri) | DIWeek.new(Sat))
114
+ results = te.dates(DateRange.new(start_date, end_date))
115
+ assert_equal(expected, results)
116
+ end
117
+
118
+ # "Every day in January, for 3 years" (second example, daily bymonth)
119
+ def test_example_5_b
120
+ start_date = DateTime.parse("US-Eastern:19980101T090000")
121
+ end_date = start_date + 365 + 365 + 366 + 31 #Feb 1, 2001
122
+
123
+ #rrule = RecurrenceRule.new("FREQ=DAILY;UNTIL=20000131T090000Z;BYMONTH=1")
124
+
125
+ expected = []
126
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19980101T090000"), DateTime.parse("US-Eastern:19980131T090000"))
127
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19990101T090000"), DateTime.parse("US-Eastern:19990131T090000"))
128
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:20000101T090000"), DateTime.parse("US-Eastern:20000131T090000"))
129
+
130
+ te = BeforeTE.new(DateTime.parse("20000131T090000"), true) & REWeek.new(Sun, Sat) & REYear.new(1)
131
+ results = te.dates(DateRange.new(start_date, end_date))
132
+ assert_equal(expected, results)
133
+ end
134
+
135
+ # "Weekly for 10 occurrences"
136
+ def test_example_6
137
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
138
+ end_date = start_date + 365 #Sep 2, 1998
139
+
140
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;COUNT=10")
141
+
142
+ expected = [
143
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
144
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
145
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
146
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
147
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
148
+ DateTime.parse("US-Eastern:19971007T090000"), #Oct 7
149
+ DateTime.parse("US-Eastern:19971014T090000"), #Oct 14
150
+ DateTime.parse("US-Eastern:19971021T090000"), #Oct 21
151
+ DateTime.parse("US-Eastern:19971028T090000"), #Oct 28
152
+ DateTime.parse("US-Eastern:19971104T090000"), #Nov 4
153
+ ]
154
+
155
+ te = EveryTE.new(start_date, 7, DPrecision::DAY)
156
+ results = te.dates(DateRange.new(start_date, end_date), 10)
157
+ assert_equal(expected, results)
158
+ end
159
+
160
+ # "Weekly until December 24th, 1997"
161
+ def test_example_7
162
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
163
+ end_date = start_date + 365 #Sep 2, 1998
164
+
165
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;UNTIL=19971224T000000Z")
166
+
167
+ expected = [
168
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
169
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
170
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
171
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
172
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
173
+ DateTime.parse("US-Eastern:19971007T090000"), #Oct 7
174
+ DateTime.parse("US-Eastern:19971014T090000"), #Oct 14
175
+ DateTime.parse("US-Eastern:19971021T090000"), #Oct 21
176
+ DateTime.parse("US-Eastern:19971028T090000"), #Oct 28
177
+ DateTime.parse("US-Eastern:19971104T090000"), #Nov 4
178
+ DateTime.parse("US-Eastern:19971111T090000"), #Nov 11
179
+ DateTime.parse("US-Eastern:19971118T090000"), #Nov 18
180
+ DateTime.parse("US-Eastern:19971125T090000"), #Nov 25
181
+ DateTime.parse("US-Eastern:19971202T090000"), #Dec 2
182
+ DateTime.parse("US-Eastern:19971209T090000"), #Dec 9
183
+ DateTime.parse("US-Eastern:19971216T090000"), #Dec 16
184
+ DateTime.parse("US-Eastern:19971223T090000"), #Dec 23
185
+ ]
186
+
187
+ te = BeforeTE.new(DateTime.parse("19971224T000000"), true) & EveryTE.new(start_date, 7, DPrecision::DAY)
188
+ results = te.dates(DateRange.new(start_date, end_date))
189
+ assert_equal(expected, results)
190
+ end
191
+
192
+ # "Every other week - forever"
193
+ def test_example_8
194
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
195
+ end_date = DateTime.parse("US-Eastern:19980201T090000") # Feb 1st, 1998
196
+
197
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;INTERVAL=2;WKST=SU")
198
+
199
+ expected = [
200
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
201
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
202
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
203
+ DateTime.parse("US-Eastern:19971014T090000"), #Oct 14
204
+ DateTime.parse("US-Eastern:19971028T090000"), #Oct 28
205
+ DateTime.parse("US-Eastern:19971111T090000"), #Nov 11
206
+ DateTime.parse("US-Eastern:19971125T090000"), #Nov 25
207
+ DateTime.parse("US-Eastern:19971209T090000"), #Dec 9
208
+ DateTime.parse("US-Eastern:19971223T090000"), #Dec 23
209
+ DateTime.parse("US-Eastern:19980106T090000"), #Jan 6
210
+ DateTime.parse("US-Eastern:19980120T090000"), #Jan 20
211
+ ]
212
+
213
+ te = EveryTE.new(start_date, 7*2, DPrecision::DAY)
214
+ results = te.dates(DateRange.new(start_date, end_date))
215
+ assert_equal(expected, results)
216
+ end
217
+
218
+ # "Weekly on Tuesday and Thursday for 5 weeks (first example, using until)"
219
+ def test_example_9_a
220
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
221
+ end_date = DateTime.parse("US-Eastern:19980101T090000") # Jan 1st, 1998
222
+
223
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH")
224
+
225
+ expected = [
226
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
227
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
228
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
229
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11
230
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
231
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
232
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
233
+ DateTime.parse("US-Eastern:19970925T090000"), #Sep 25
234
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
235
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
236
+ ]
237
+
238
+ te = BeforeTE.new(DateTime.parse("19971007T000000Z"), true) & (DIWeek.new(Tue) | DIWeek.new(Thu))
239
+ results = te.dates(DateRange.new(start_date, end_date))
240
+ assert_equal(expected, results)
241
+ end
242
+
243
+ # "Weekly on Tuesday and Thursday for 5 weeks (second example, using count)"
244
+ def test_example_9_b
245
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
246
+ end_date = DateTime.parse("US-Eastern:19980101T090000") # Jan 1st, 1998
247
+
248
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH")
249
+
250
+ expected = [
251
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
252
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
253
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
254
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11
255
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
256
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
257
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
258
+ DateTime.parse("US-Eastern:19970925T090000"), #Sep 25
259
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
260
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
261
+ ]
262
+
263
+ te = DIWeek.new(Tue) | DIWeek.new(Thu)
264
+ results = te.dates(DateRange.new(start_date, end_date), 10)
265
+ assert_equal(expected, results)
266
+ end
267
+
268
+ # "Every other week on Monday, Wednesday, and Friday until December 24, 1997
269
+ # but starting on Tuesday, September 2, 1997"
270
+ def test_example_10
271
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
272
+ end_date = DateTime.parse("US-Eastern:19980201T090000") # Feb 1st, 1998
273
+
274
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR")
275
+
276
+ expected = [
277
+ #LJK: note that Sep 2nd is listed in the example, but it does not match the given RRULE.
278
+ # It definitely is not rendered by the TE below, so I'm just commenting it out for more research.
279
+ #DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
280
+
281
+ DateTime.parse("US-Eastern:19970903T090000"), #Sep 3
282
+ DateTime.parse("US-Eastern:19970905T090000"), #Sep 5
283
+ DateTime.parse("US-Eastern:19970915T090000"), #Sep 15
284
+ DateTime.parse("US-Eastern:19970917T090000"), #Sep 17
285
+ DateTime.parse("US-Eastern:19970919T090000"), #Sep 19
286
+ DateTime.parse("US-Eastern:19970929T090000"), #Sep 29
287
+ DateTime.parse("US-Eastern:19971001T090000"), #Oct 1
288
+ DateTime.parse("US-Eastern:19971003T090000"), #Oct 3
289
+ DateTime.parse("US-Eastern:19971013T090000"), #Oct 13
290
+ DateTime.parse("US-Eastern:19971015T090000"), #Oct 15
291
+ DateTime.parse("US-Eastern:19971017T090000"), #Oct 17
292
+ DateTime.parse("US-Eastern:19971027T090000"), #Oct 27
293
+ DateTime.parse("US-Eastern:19971029T090000"), #Oct 29
294
+ DateTime.parse("US-Eastern:19971031T090000"), #Oct 31
295
+ DateTime.parse("US-Eastern:19971110T090000"), #Nov 10
296
+ DateTime.parse("US-Eastern:19971112T090000"), #Nov 12
297
+ DateTime.parse("US-Eastern:19971114T090000"), #Nov 14
298
+ DateTime.parse("US-Eastern:19971124T090000"), #Nov 24
299
+ DateTime.parse("US-Eastern:19971126T090000"), #Nov 26
300
+ DateTime.parse("US-Eastern:19971128T090000"), #Nov 28
301
+ DateTime.parse("US-Eastern:19971208T090000"), #Dec 8
302
+ DateTime.parse("US-Eastern:19971210T090000"), #Dec 10
303
+ DateTime.parse("US-Eastern:19971212T090000"), #Dec 12
304
+ DateTime.parse("US-Eastern:19971222T090000"), #Dec 22
305
+ ]
306
+
307
+ te = BeforeTE.new(DateTime.parse("19971224T000000Z"), true) & (DIWeek.new(Mon) | DIWeek.new(Wed) | DIWeek.new(Fri)) & EveryTE.new(start_date, 2, DPrecision::WEEK)
308
+ results = te.dates(DateRange.new(start_date, end_date))
309
+ assert_equal(expected, results)
310
+ end
311
+
312
+ # "Every other week on Tuesday and Thursday, for 8 occurences"
313
+ def test_example_11
314
+ start_date = DateTime.parse("US-Eastern:19970902T090000") # Sep 2nd, 1997
315
+ end_date = DateTime.parse("US-Eastern:19980201T090000") # Feb 1st, 1998
316
+
317
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH")
318
+
319
+ expected = [
320
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
321
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
322
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
323
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
324
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
325
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
326
+ DateTime.parse("US-Eastern:19971014T090000"), #Oct 14
327
+ DateTime.parse("US-Eastern:19971016T090000"), #Oct 16
328
+ ]
329
+
330
+ te = EveryTE.new(start_date, 2, DPrecision::WEEK) & (DIWeek.new(Tue) | DIWeek.new(Thu))
331
+ results = te.dates(DateRange.new(start_date, end_date), 8)
332
+ assert_equal(expected, results)
333
+ end
334
+
335
+ # "Monthly on the 1st Friday for ten occurences"
336
+ def test_example_12
337
+ start_date = DateTime.parse("US-Eastern:19970905T090000") #Sep 5, 1997
338
+ end_date = start_date + 365 #Sep 5, 1998
339
+
340
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYDAY=1FR")
341
+
342
+ expected = [
343
+ DateTime.parse("US-Eastern:19970905T090000"), #Sep 5
344
+ DateTime.parse("US-Eastern:19971003T090000"), #Oct 3
345
+ DateTime.parse("US-Eastern:19971107T090000"), #Nov 7
346
+ DateTime.parse("US-Eastern:19971205T090000"), #Dec 5
347
+ DateTime.parse("US-Eastern:19980102T090000"), #Jan 2
348
+ DateTime.parse("US-Eastern:19980206T090000"), #Feb 6
349
+ DateTime.parse("US-Eastern:19980306T090000"), #Mar 6
350
+ DateTime.parse("US-Eastern:19980403T090000"), #Apr 3
351
+ DateTime.parse("US-Eastern:19980501T090000"), #May 1
352
+ DateTime.parse("US-Eastern:19980605T090000"), #Jun 5
353
+ ]
354
+
355
+ te = DIMonth.new(1,5) #first friday
356
+ results = te.dates(DateRange.new(start_date, end_date), 10)
357
+ assert_equal(expected, results)
358
+ end
359
+
360
+ # "Monthly on the 1st Friday until December 24, 1997"
361
+ def test_example_13
362
+ start_date = DateTime.parse("US-Eastern:19970905T090000") #Sep 5, 1997
363
+ end_date = start_date + 365 #Sep 5, 1998
364
+
365
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;UNTIL=19971224T000000;BYDAY=1FR")
366
+
367
+ expected = [
368
+ DateTime.parse("US-Eastern:19970905T090000"), #Sep 5
369
+ DateTime.parse("US-Eastern:19971003T090000"), #Oct 3
370
+ DateTime.parse("US-Eastern:19971107T090000"), #Nov 7
371
+ DateTime.parse("US-Eastern:19971205T090000"), #Dec 5
372
+ ]
373
+
374
+ te = BeforeTE.new(DateTime.parse("US-Eastern:19971224T000000")) & DIMonth.new(1,5) #first friday
375
+ results = te.dates(DateRange.new(start_date, end_date))
376
+ assert_equal(expected, results)
377
+ end
378
+
379
+ # "Every other month on the 1st and last Sunday of the month for 10 occurences"
380
+ def test_example_14
381
+ start_date = DateTime.parse("US-Eastern:19970907T090000") #Sep 7, 1997
382
+ end_date = start_date + 365 #Sep 7, 1998
383
+
384
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU")
385
+
386
+ expected = [
387
+ DateTime.parse("US-Eastern:19970907T090000"), #Sep 5
388
+ DateTime.parse("US-Eastern:19970928T090000"), #Sep 28
389
+ DateTime.parse("US-Eastern:19971102T090000"), #Nov 2
390
+ DateTime.parse("US-Eastern:19971130T090000"), #Nov 30
391
+ DateTime.parse("US-Eastern:19980104T090000"), #Jan 4
392
+ DateTime.parse("US-Eastern:19980125T090000"), #Jan 25
393
+ DateTime.parse("US-Eastern:19980301T090000"), #Mar 1
394
+ DateTime.parse("US-Eastern:19980329T090000"), #Mar 29
395
+ DateTime.parse("US-Eastern:19980503T090000"), #May 3
396
+ DateTime.parse("US-Eastern:19980531T090000"), #May 31
397
+ ]
398
+
399
+ te = EveryTE.new(start_date, 2, DPrecision::MONTH) & (DIMonth.new(1,0) | DIMonth.new(-1,0)) #first and last Sundays
400
+ results = te.dates(DateRange.new(start_date, end_date), 10)
401
+ assert_equal(expected, results)
402
+ end
403
+
404
+ # "Monthly on the second to last Monday of the month for 6 months"
405
+ def test_example_15
406
+ start_date = DateTime.parse("US-Eastern:19970922T090000") #Sep 22, 1997
407
+ end_date = start_date + 365 #Sep 22, 1998
408
+
409
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=6;BYDAY=-2MO")
410
+
411
+ expected = [
412
+ DateTime.parse("US-Eastern:19970922T090000"), #Sep 22
413
+ DateTime.parse("US-Eastern:19971020T090000"), #Oct 20
414
+ DateTime.parse("US-Eastern:19971117T090000"), #Nov 17
415
+ DateTime.parse("US-Eastern:19971222T090000"), #Dec 22
416
+ DateTime.parse("US-Eastern:19980119T090000"), #Jan 19
417
+ DateTime.parse("US-Eastern:19980216T090000"), #Feb 16
418
+ ]
419
+
420
+ te = DIMonth.new(-2,1) #second to last Monday
421
+ results = te.dates(DateRange.new(start_date, end_date), 6)
422
+ assert_equal(expected, results)
423
+ end
424
+
425
+ =begin
426
+ #### NOTE: Runt does not currently support negative day of month references!
427
+ # "Monthly on the third to the last day of the month, forever"
428
+ def test_example_16
429
+ start_date = DateTime.parse("US-Eastern:19970922T090000") #Sep 22, 1997
430
+ end_date = DateTime.parse("US-Eastern:19980301T090000"), #Mar 1, 1998
431
+
432
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;BYMONTHDAY=-3")
433
+
434
+ expected = [
435
+ DateTime.parse("US-Eastern:19970928T090000"), #Sep 28
436
+ DateTime.parse("US-Eastern:19971029T090000"), #Oct 29
437
+ DateTime.parse("US-Eastern:19971128T090000"), #Nov 28
438
+ DateTime.parse("US-Eastern:19971229T090000"), #Dec 29
439
+ DateTime.parse("US-Eastern:19980129T090000"), #Jan 29
440
+ DateTime.parse("US-Eastern:19980226T090000"), #Feb 26
441
+ ]
442
+
443
+ te = REMonth.new(-3) #third to last day of the month
444
+ results = te.dates(DateRange.new(start_date, end_date))
445
+ assert_equal(expected, results)
446
+ end
447
+ =end
448
+
449
+ # "Monthly on the 2nd and 15th of the month for 10 occurences"
450
+ def test_example_17
451
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
452
+ end_date = start_date + 365 #Sep 2, 1998
453
+
454
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15")
455
+
456
+ expected = [
457
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
458
+ DateTime.parse("US-Eastern:19970915T090000"), #Sep 15
459
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
460
+ DateTime.parse("US-Eastern:19971015T090000"), #Oct 15
461
+ DateTime.parse("US-Eastern:19971102T090000"), #Nov 2
462
+ DateTime.parse("US-Eastern:19971115T090000"), #Nov 15
463
+ DateTime.parse("US-Eastern:19971202T090000"), #Dec 2
464
+ DateTime.parse("US-Eastern:19971215T090000"), #Dec 15
465
+ DateTime.parse("US-Eastern:19980102T090000"), #Jan 2
466
+ DateTime.parse("US-Eastern:19980115T090000"), #Jan 15
467
+ ]
468
+
469
+ te = REMonth.new(2) | REMonth.new(15) #second or fifteenth of the month
470
+ results = te.dates(DateRange.new(start_date, end_date), 10)
471
+ assert_equal(expected, results)
472
+ end
473
+
474
+ =begin
475
+ #### NOTE: Runt does not currently support negative day of month references!
476
+ # "Monthly on the first and last day of the month for 10 occurences"
477
+ def test_example_18
478
+ start_date = DateTime.parse("US-Eastern:19970930T090000") #Sep 30, 1997
479
+ end_date = start_date + 365 #Sep 30, 1998
480
+
481
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1")
482
+
483
+ expected = [
484
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
485
+ DateTime.parse("US-Eastern:19971001T090000"), #Oct 1
486
+ DateTime.parse("US-Eastern:19971031T090000"), #Oct 31
487
+ DateTime.parse("US-Eastern:19971101T090000"), #Nov 1
488
+ DateTime.parse("US-Eastern:19971130T090000"), #Nov 30
489
+ DateTime.parse("US-Eastern:19971201T090000"), #Dec 1
490
+ DateTime.parse("US-Eastern:19971231T090000"), #Dec 31
491
+ DateTime.parse("US-Eastern:19980101T090000"), #Jan 1
492
+ DateTime.parse("US-Eastern:19980131T090000"), #Jan 31
493
+ DateTime.parse("US-Eastern:19980201T090000"), #Feb 1
494
+ ]
495
+
496
+ te = REMonth.new(1) | REMonth.new(-1) #first and last days of the month
497
+ results = te.dates(DateRange.new(start_date, end_date), 10)
498
+ assert_equal(expected, results)
499
+ end
500
+ =end
501
+
502
+ # "Every 18 months on the 10th thru 15th of the month for 10 occurrences"
503
+ def test_example_19
504
+ start_date = DateTime.parse("US-Eastern:19970910T090000") #Sep 10, 1997
505
+ end_date = start_date + 365 + 365 #Sep 10, 1999
506
+
507
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15")
508
+
509
+ expected = [
510
+ DateTime.parse("US-Eastern:19970910T090000"), #Sep 10, 1997
511
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11, 1997
512
+ DateTime.parse("US-Eastern:19970912T090000"), #Sep 12, 1997
513
+ DateTime.parse("US-Eastern:19970913T090000"), #Sep 13, 1997
514
+ DateTime.parse("US-Eastern:19970914T090000"), #Sep 14, 1997
515
+ DateTime.parse("US-Eastern:19970915T090000"), #Sep 15, 1997
516
+ DateTime.parse("US-Eastern:19990310T090000"), #Mar 10, 1999
517
+ DateTime.parse("US-Eastern:19990311T090000"), #Mar 11, 1999
518
+ DateTime.parse("US-Eastern:19990312T090000"), #Mar 12, 1999
519
+ DateTime.parse("US-Eastern:19990313T090000"), #Mar 13, 1999
520
+ ]
521
+
522
+ te = REMonth.new(10,15) & EveryTE.new(start_date, 18, DPrecision::MONTH) #tenth through the fifteenth
523
+ results = te.dates(DateRange.new(start_date, end_date), 10)
524
+ assert_equal(expected, results)
525
+ end
526
+
527
+ # "Every Tuesday, every other month"
528
+ def test_example_20
529
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
530
+ end_date = start_date + 220 #Oct 4, 1998
531
+
532
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=2;BYDAY=TU)
533
+
534
+ expected = [
535
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 02, 1997
536
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 09, 1997
537
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16, 1997
538
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23, 1997
539
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30, 1997
540
+ DateTime.parse("US-Eastern:19971104T090000"), #Nov 04, 1997
541
+ DateTime.parse("US-Eastern:19971111T090000"), #Nov 11, 1997
542
+ DateTime.parse("US-Eastern:19971118T090000"), #Nov 18, 1997
543
+ DateTime.parse("US-Eastern:19971125T090000"), #Nov 25, 1997
544
+ DateTime.parse("US-Eastern:19980106T090000"), #Jan 06, 1998
545
+ DateTime.parse("US-Eastern:19980113T090000"), #Jan 13, 1998
546
+ DateTime.parse("US-Eastern:19980120T090000"), #Jan 20, 1998
547
+ DateTime.parse("US-Eastern:19980127T090000"), #Jan 27, 1998
548
+ DateTime.parse("US-Eastern:19980303T090000"), #Mar 03, 1998
549
+ DateTime.parse("US-Eastern:19980310T090000"), #Mar 10, 1998
550
+ DateTime.parse("US-Eastern:19980317T090000"), #Mar 17, 1998
551
+ DateTime.parse("US-Eastern:19980324T090000"), #Mar 24, 1998
552
+ DateTime.parse("US-Eastern:19980331T090000"), #Mar 31, 1998
553
+ ]
554
+
555
+ te = EveryTE.new(start_date, 2, DPrecision::MONTH) & DIWeek.new(Tuesday)
556
+ results = te.dates(DateRange.new(start_date, end_date))
557
+ assert_equal(expected, results)
558
+ end
559
+
560
+ # "Yearly in June and July for 10 occurrences"
561
+ def test_example_21
562
+ start_date = DateTime.parse("US-Eastern:19970610T090000") #June 10, 1997
563
+ end_date = DateTime.parse("US-Eastern:20020725T090000") #July 25, 2002
564
+
565
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;COUNT=10;BYMONTH=6,7)
566
+
567
+ expected = [
568
+ DateTime.parse("US-Eastern:19970610T090000"), #Jun 10, 1997
569
+ DateTime.parse("US-Eastern:19970710T090000"), #Jul 10, 1997
570
+
571
+ DateTime.parse("US-Eastern:19980610T090000"), #Jun 10, 1998
572
+ DateTime.parse("US-Eastern:19980710T090000"), #Jul 10, 1998
573
+
574
+ DateTime.parse("US-Eastern:19990610T090000"), #Jun 10, 1999
575
+ DateTime.parse("US-Eastern:19990710T090000"), #Jul 10, 1999
576
+
577
+ DateTime.parse("US-Eastern:20000610T090000"), #Jun 10, 2000
578
+ DateTime.parse("US-Eastern:20000710T090000"), #Jul 10, 2000
579
+
580
+ DateTime.parse("US-Eastern:20010610T090000"), #Jun 10, 2001
581
+ DateTime.parse("US-Eastern:20010710T090000"), #Jul 10, 2001
582
+ ]
583
+
584
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
585
+ results = te.dates(DateRange.new(start_date, end_date), 10)
586
+ assert_equal(expected, results)
587
+ end
588
+
589
+ # "Every other year on January, February, and March for 10 occurrences"
590
+ def test_example_22
591
+ start_date = DateTime.parse("US-Eastern:19970310T090000") #Mar 10, 1997
592
+ end_date = DateTime.parse("US-Eastern:20040401T090000") #Apr 1, 2004
593
+
594
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3")
595
+
596
+ expected = [
597
+ DateTime.parse("US-Eastern:19970310T090000"), #Mar 10, 1997
598
+ DateTime.parse("US-Eastern:19990110T090000"), #Jan 10, 1999
599
+ DateTime.parse("US-Eastern:19990210T090000"), #Feb 10, 1999
600
+ DateTime.parse("US-Eastern:19990310T090000"), #Mar 10, 1999
601
+ DateTime.parse("US-Eastern:20010110T090000"), #Jan 10, 2001
602
+ DateTime.parse("US-Eastern:20010210T090000"), #Feb 10, 2001
603
+ DateTime.parse("US-Eastern:20010310T090000"), #Mar 10, 2001
604
+ DateTime.parse("US-Eastern:20030110T090000"), #Jan 10, 2003
605
+ DateTime.parse("US-Eastern:20030210T090000"), #Feb 10, 2003
606
+ DateTime.parse("US-Eastern:20030310T090000"), #Mar 10, 2003
607
+ ]
608
+
609
+ te = REMonth.new(start_date.day) & (REYear.new(1) | REYear.new(2) | REYear.new(3)) & EveryTE.new(start_date, 2, DPrecision::YEAR)
610
+ results = te.dates(DateRange.new(start_date, end_date), 10)
611
+ assert_equal(expected, results)
612
+ end
613
+
614
+ =begin
615
+ # "Every 3rd year on the 1st, 100th, and 200th day for 10 occurrences"
616
+ def test_example_23
617
+ start_date = DateTime.parse("US-Eastern:19970101T090000") #Jan 1, 1997
618
+ end_date = DateTime.parse("US-Eastern:20070401T090000") #Apr 1, 2007
619
+
620
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200")
621
+
622
+ expected = [
623
+ DateTime.parse("US-Eastern:19970101T090000"), #Jan 1, 1997
624
+ DateTime.parse("US-Eastern:19970410T090000"), #Apr 10, 1997
625
+ DateTime.parse("US-Eastern:19970719T090000"), #Jul 19, 1997
626
+ DateTime.parse("US-Eastern:20000101T090000"), #Jan 1, 2000
627
+ DateTime.parse("US-Eastern:20000409T090000"), #Apr 9, 2000
628
+ DateTime.parse("US-Eastern:20000718T090000"), #Jul 18, 2000
629
+ DateTime.parse("US-Eastern:20030101T090000"), #Jan 1, 2003
630
+ DateTime.parse("US-Eastern:20030410T090000"), #Apr 10, 2003
631
+ DateTime.parse("US-Eastern:20030719T090000"), #Jul 19, 2003
632
+ DateTime.parse("US-Eastern:20060101T090000"), #Jan 1, 2006
633
+ ]
634
+
635
+ te = EveryTE.new(start_date, 3, DPrecision::YEAR) & (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
636
+ results = te.dates(DateRange.new(start_date, end_date), 10)
637
+ assert_equal(expected, results)
638
+ end
639
+
640
+ # "Every 20th Monday of the year, forever"
641
+ def test_example_24
642
+ start_date = DateTime.parse("US-Eastern:19970519T090000") #May 19, 1997
643
+ end_date = DateTime.parse("US-Eastern:20000101T090000") #Jan 1, 2000
644
+
645
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;BYDAY=20MO")
646
+
647
+ expected = [
648
+ DateTime.parse("US-Eastern:19970519T090000"), #May 19, 1997
649
+ DateTime.parse("US-Eastern:19980518T090000"), #May 18, 1998
650
+ DateTime.parse("US-Eastern:19990517T090000"), #May 17, 1999
651
+ ]
652
+
653
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
654
+ results = te.dates(DateRange.new(start_date, end_date))
655
+ assert_equal(expected, results)
656
+ end
657
+
658
+ # "Monday of week number 20 (where the default start of the week is Monday), forever"
659
+ def test_example_25
660
+ start_date = DateTime.parse("US-Eastern:19970512T090000") #May 12, 1997
661
+ end_date = DateTime.parse("US-Eastern:20000101T090000") #Jan 1, 2000
662
+
663
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO")
664
+
665
+ expected = [
666
+ DateTime.parse("US-Eastern:19970512T090000"), #May 12, 1997
667
+ DateTime.parse("US-Eastern:19980511T090000"), #May 11, 1998
668
+ DateTime.parse("US-Eastern:19990517T090000"), #May 17, 1999
669
+ ]
670
+
671
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
672
+ results = te.dates(DateRange.new(start_date, end_date), 10)
673
+ assert_equal(expected, results)
674
+ end
675
+ =end
676
+
677
+ # "Every Thursday in March, forever"
678
+ def test_example_26
679
+ start_date = DateTime.parse("US-Eastern:19970313T090000") #Mar 13, 1997
680
+ end_date = DateTime.parse("US-Eastern:20000101T090000") #Jan 1, 2000
681
+
682
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;BYMONTH=3;BYDAY=TH")
683
+
684
+ expected = [
685
+ DateTime.parse("US-Eastern:19970313T090000"), #Mar 13, 1997
686
+ DateTime.parse("US-Eastern:19970320T090000"), #Mar 20, 1997
687
+ DateTime.parse("US-Eastern:19970327T090000"), #Mar 27, 1997
688
+ DateTime.parse("US-Eastern:19980305T090000"), #Mar 5, 1998
689
+ DateTime.parse("US-Eastern:19980312T090000"), #Mar 12, 1998
690
+ DateTime.parse("US-Eastern:19980319T090000"), #Mar 19, 1998
691
+ DateTime.parse("US-Eastern:19980326T090000"), #Mar 26, 1998
692
+ DateTime.parse("US-Eastern:19990304T090000"), #Mar 4, 1999
693
+ DateTime.parse("US-Eastern:19990311T090000"), #Mar 11, 1999
694
+ DateTime.parse("US-Eastern:19990318T090000"), #Mar 18, 1999
695
+ DateTime.parse("US-Eastern:19990325T090000"), #Mar 25, 1999
696
+ ]
697
+
698
+ te = REYear.new(3) & DIWeek.new(Thursday)
699
+ results = te.dates(DateRange.new(start_date, end_date))
700
+ assert_equal(expected, results)
701
+ end
702
+
703
+ # "Every Thursday, but only during June, July, and August, forever"
704
+ def test_example_27
705
+ start_date = DateTime.parse("US-Eastern:19970605T090000") #Jun 5, 1997
706
+ end_date = DateTime.parse("US-Eastern:20000101T090000") #Jan 1, 2000
707
+
708
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8")
709
+
710
+ expected = [
711
+ DateTime.parse("US-Eastern:19970605T090000"), #Jun 5, 1997
712
+ DateTime.parse("US-Eastern:19970612T090000"), #Jun 12, 1997
713
+ DateTime.parse("US-Eastern:19970619T090000"), #Jun 19, 1997
714
+ DateTime.parse("US-Eastern:19970626T090000"), #Jun 26, 1997
715
+ DateTime.parse("US-Eastern:19970703T090000"), #Jul 3, 1997
716
+ DateTime.parse("US-Eastern:19970710T090000"), #Jul 10, 1997
717
+ DateTime.parse("US-Eastern:19970717T090000"), #Jul 17, 1997
718
+ DateTime.parse("US-Eastern:19970724T090000"), #Jul 24, 1997
719
+ DateTime.parse("US-Eastern:19970731T090000"), #Jul 31, 1997
720
+ DateTime.parse("US-Eastern:19970807T090000"), #Aug 7, 1997
721
+ DateTime.parse("US-Eastern:19970814T090000"), #Aug 14, 1997
722
+ DateTime.parse("US-Eastern:19970821T090000"), #Aug 21, 1997
723
+ DateTime.parse("US-Eastern:19970828T090000"), #Aug 28, 1997
724
+ DateTime.parse("US-Eastern:19980604T090000"), #Jun 4, 1998
725
+ DateTime.parse("US-Eastern:19980611T090000"), #Jun 11, 1998
726
+ DateTime.parse("US-Eastern:19980618T090000"), #Jun 18, 1998
727
+ DateTime.parse("US-Eastern:19980625T090000"), #Jun 25, 1998
728
+ DateTime.parse("US-Eastern:19980702T090000"), #Jul 2, 1998
729
+ DateTime.parse("US-Eastern:19980709T090000"), #Jul 9, 1998
730
+ DateTime.parse("US-Eastern:19980716T090000"), #Jul 16, 1998
731
+ DateTime.parse("US-Eastern:19980723T090000"), #Jul 23, 1998
732
+ DateTime.parse("US-Eastern:19980730T090000"), #Jul 30, 1998
733
+ DateTime.parse("US-Eastern:19980806T090000"), #Aug 6, 1998
734
+ DateTime.parse("US-Eastern:19980813T090000"), #Aug 13, 1998
735
+ DateTime.parse("US-Eastern:19980820T090000"), #Aug 20, 1998
736
+ DateTime.parse("US-Eastern:19980827T090000"), #Aug 27, 1998
737
+ DateTime.parse("US-Eastern:19990603T090000"), #Jun 3, 1999
738
+ DateTime.parse("US-Eastern:19990610T090000"), #Jun 10, 1999
739
+ DateTime.parse("US-Eastern:19990617T090000"), #Jun 17, 1999
740
+ DateTime.parse("US-Eastern:19990624T090000"), #Jun 24, 1999
741
+ DateTime.parse("US-Eastern:19990701T090000"), #Jul 1, 1999
742
+ DateTime.parse("US-Eastern:19990708T090000"), #Jul 8, 1999
743
+ DateTime.parse("US-Eastern:19990715T090000"), #Jul 15, 1999
744
+ DateTime.parse("US-Eastern:19990722T090000"), #Jul 22, 1999
745
+ DateTime.parse("US-Eastern:19990729T090000"), #Jul 29, 1999
746
+ DateTime.parse("US-Eastern:19990805T090000"), #Aug 5, 1999
747
+ DateTime.parse("US-Eastern:19990812T090000"), #Aug 12, 1999
748
+ DateTime.parse("US-Eastern:19990819T090000"), #Aug 19, 1999
749
+ DateTime.parse("US-Eastern:19990826T090000"), #Aug 26, 1999
750
+ ]
751
+
752
+ te = (REYear.new(6) | REYear.new(7) | REYear.new(8)) & DIWeek.new(Thursday)
753
+ results = te.dates(DateRange.new(start_date, end_date))
754
+ assert_equal(expected, results)
755
+ end
756
+
757
+ # "Every Friday the 13th, forever"
758
+ # (LJK: aka the "Jason example") (yes, I know it's bad, but someone had to say it)
759
+ def test_example_28
760
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
761
+ end_date = DateTime.parse("US-Eastern:20001014T090000") #Oct 14, 2000
762
+
763
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13")
764
+
765
+ expected = [
766
+ DateTime.parse("US-Eastern:19980213T090000"), #Feb 13, 1998
767
+ DateTime.parse("US-Eastern:19980313T090000"), #Mar 13, 1998
768
+ DateTime.parse("US-Eastern:19981113T090000"), #Nov 13, 1998
769
+ DateTime.parse("US-Eastern:19990813T090000"), #Aug 13, 1999
770
+ DateTime.parse("US-Eastern:20001013T090000"), #Oct 13, 2000
771
+ ]
772
+
773
+ te = REMonth.new(13) & DIWeek.new(Friday)
774
+ results = te.dates(DateRange.new(start_date, end_date))
775
+ assert_equal(expected, results)
776
+ end
777
+
778
+ # "The first Saturday that follows the first Sunday of the month, forever"
779
+ def test_example_29
780
+ start_date = DateTime.parse("US-Eastern:19970913T090000") #Sep 13, 1997
781
+ end_date = DateTime.parse("US-Eastern:19980614T090000") #Jun 14, 1998
782
+
783
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13")
784
+
785
+ expected = [
786
+ DateTime.parse("US-Eastern:19970913T090000"), #Sep 13, 1997
787
+ DateTime.parse("US-Eastern:19971011T090000"), #Oct 11, 1997
788
+ DateTime.parse("US-Eastern:19971108T090000"), #Nov 8, 1997
789
+ DateTime.parse("US-Eastern:19971213T090000"), #Dec 13, 1997
790
+ DateTime.parse("US-Eastern:19980110T090000"), #Jan 10, 1998
791
+ DateTime.parse("US-Eastern:19980207T090000"), #Feb 7, 1998
792
+ DateTime.parse("US-Eastern:19980307T090000"), #Mar 7, 1998
793
+ DateTime.parse("US-Eastern:19980411T090000"), #Apr 11, 1998
794
+ DateTime.parse("US-Eastern:19980509T090000"), #May 9, 1998
795
+ DateTime.parse("US-Eastern:19980613T090000"), #Jun 13, 1998
796
+ ]
797
+
798
+ te = (REMonth.new(7) | REMonth.new(8) | REMonth.new(9) | REMonth.new(10) | REMonth.new(11) | REMonth.new(12) | REMonth.new(13)) & DIWeek.new(Saturday)
799
+ results = te.dates(DateRange.new(start_date, end_date))
800
+ assert_equal(expected, results)
801
+ end
802
+
803
+ # "Every four years, the first Tuesday after a Monday in November, forever
804
+ # (U.S. Presidential Election day)"
805
+ def test_example_30
806
+ start_date = DateTime.parse("US-Eastern:19961105T090000") #May 11, 1996
807
+ end_date = DateTime.parse("US-Eastern:20050101T090000") #Jan 1, 2005
808
+
809
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8")
810
+
811
+ expected = [
812
+ DateTime.parse("US-Eastern:19961105T090000"), #Nov 5, 1996
813
+ DateTime.parse("US-Eastern:20001107T090000"), #Nov 7, 2000
814
+ DateTime.parse("US-Eastern:20041102T090000"), #Nov 2, 2004
815
+ ]
816
+
817
+ te = (REMonth.new(2) | REMonth.new(3) | REMonth.new(4) | REMonth.new(5) | REMonth.new(6) | REMonth.new(7) | REMonth.new(8)) & DIWeek.new(Tuesday) & REYear.new(11) & EveryTE.new(start_date, 4, DPrecision::YEAR)
818
+ results = te.dates(DateRange.new(start_date, end_date))
819
+ assert_equal(expected, results)
820
+ end
821
+
822
+ =begin
823
+ # "The 3rd instance into the month of one of Tuesday, Wednesday, or Thursday, for the next three months"
824
+ def test_example_31
825
+ start_date = DateTime.parse("US-Eastern:19970904T090000") #Sep 4, 1997
826
+ end_date = DateTime.parse("US-Eastern:19971115T090000") #Nov 15, 1997 (LJK: my 22nd birthday)
827
+
828
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3")
829
+
830
+ expected = [
831
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4, 1997
832
+ DateTime.parse("US-Eastern:19971007T090000"), #Oct 7, 1997
833
+ DateTime.parse("US-Eastern:19971106T090000"), #Nov 6, 1997
834
+ ]
835
+
836
+ te = DIMonth.new(3, Tuesday) | DIMonth.new(3, Wednesday) | DIMonth.new(3,Thursday)
837
+ results = te.dates(DateRange.new(start_date, end_date), 3)
838
+ debug(expected, results)
839
+ assert_equal(expected, results)
840
+ end
841
+
842
+ # "The 2nd to last weekday of the month"
843
+ def test_example_32
844
+ start_date = DateTime.parse("US-Eastern:19970929T090000") #Sep 29, 1997
845
+ end_date = DateTime.parse("US-Eastern:19980401T090000") #Apr 1, 1998
846
+
847
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2")
848
+
849
+ expected = [
850
+ DateTime.parse("US-Eastern:19970929T090000"), #Sep 29, 1997
851
+ DateTime.parse("US-Eastern:19971030T090000"), #Oct 30, 1997
852
+ DateTime.parse("US-Eastern:19971127T090000"), #Nov 27, 1997
853
+ DateTime.parse("US-Eastern:19971230T090000"), #Dec 30, 1997
854
+ DateTime.parse("US-Eastern:19980129T090000"), #Jan 29, 1998
855
+ DateTime.parse("US-Eastern:19980226T090000"), #Feb 26, 1998
856
+ DateTime.parse("US-Eastern:19980330T090000"), #Mar 30, 1998
857
+ ]
858
+
859
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
860
+ results = te.dates(DateRange.new(start_date, end_date), 3)
861
+ assert_equal(expected, results)
862
+ end
863
+
864
+ # "Every 3 hours from 9:00 AM to 5:00 PM on a specific day"
865
+ def test_example_33
866
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997 at 9am
867
+ end_date = DateTime.parse("US-Eastern:19970902T170000") #Sep 2, 1997 at 5pm
868
+
869
+ #rrule = RecurrenceRule.new("FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z")
870
+
871
+ expected = [
872
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2, 1997 at 9am
873
+ DateTime.parse("US-Eastern:19970902T120000"), #Sep 2, 1997 at 12pm
874
+ DateTime.parse("US-Eastern:19970902T150000"), #Sep 2, 1997 at 3pm
875
+ ]
876
+
877
+ te = EveryTE.new(start_date, 3, DPrecision::HOUR) & BeforeTE.new(DateTime.parse("19970902T170000Z"))
878
+ results = te.hours(HourRange.new(start_date, end_date))
879
+ assert_equal(expected, results)
880
+ end
881
+
882
+ # "Every 15 minutes for 6 occurrences"
883
+ def test_example_34
884
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997 at 9am
885
+ end_date = DateTime.parse("US-Eastern:19970903T090000") #Sep 3, 1997 at 9am
886
+
887
+ #rrule = RecurrenceRule.new("FREQ=MINUTELY;INTERVAL=15;COUNT=6")
888
+
889
+ expected = [
890
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2, 1997 at 9:00 am
891
+ DateTime.parse("US-Eastern:19970902T091500"), #Sep 2, 1997 at 9:15 am
892
+ DateTime.parse("US-Eastern:19970902T093000"), #Sep 2, 1997 at 9:30 am
893
+ DateTime.parse("US-Eastern:19970902T094500"), #Sep 2, 1997 at 9:45 am
894
+ DateTime.parse("US-Eastern:19970902T100000"), #Sep 2, 1997 at 10:00 am
895
+ DateTime.parse("US-Eastern:19970902T101500"), #Sep 2, 1997 at 10:15 am
896
+ ]
897
+
898
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
899
+ results = te.hours(HourRange.new(start_date, end_date), 6)
900
+ assert_equal(expected, results)
901
+ end
902
+
903
+ # "Every hour and a half for 4 occurrences"
904
+ def test_example_35
905
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997 at 9am
906
+ end_date = DateTime.parse("US-Eastern:19970903T090000") #Sep 3, 1997 at 9am
907
+
908
+ #rrule = RecurrenceRule.new("FREQ=MINUTELY;INTERVAL=90;COUNT=4")
909
+
910
+ expected = [
911
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2, 1997 at 9:00 am
912
+ DateTime.parse("US-Eastern:19970902T091500"), #Sep 2, 1997 at 10:30 am
913
+ DateTime.parse("US-Eastern:19970902T093000"), #Sep 2, 1997 at 12:00 pm
914
+ DateTime.parse("US-Eastern:19970902T094500"), #Sep 2, 1997 at 1:30 pm
915
+ ]
916
+
917
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
918
+ results = te.hours(HourRange.new(start_date, end_date), 6)
919
+ assert_equal(expected, results)
920
+ end
921
+
922
+ # "Every 20 minutes from 9:00 AM to 4:40PM every day"
923
+ # (using a daily rule)
924
+ def test_example_36_a
925
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997 at 9am
926
+ end_date = DateTime.parse("US-Eastern:19970904T080000") #Sep 4, 1997 at 8am
927
+
928
+ #rrule = RecurrenceRule.new("FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40")
929
+
930
+ expected = [
931
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2, 1997 at 9:00 am
932
+ DateTime.parse("US-Eastern:19970902T092000"), #Sep 2, 1997 at 9:20 am
933
+ DateTime.parse("US-Eastern:19970902T094000"), #Sep 2, 1997 at 9:40 am
934
+ DateTime.parse("US-Eastern:19970902T100000"), #Sep 2, 1997 at 10:00 am
935
+ DateTime.parse("US-Eastern:19970902T102000"), #Sep 2, 1997 at 10:20 am
936
+ DateTime.parse("US-Eastern:19970902T104000"), #Sep 2, 1997 at 10:40 am
937
+ DateTime.parse("US-Eastern:19970902T110000"), #Sep 2, 1997 at 11:00 am
938
+ DateTime.parse("US-Eastern:19970902T112000"), #Sep 2, 1997 at 11:20 am
939
+ DateTime.parse("US-Eastern:19970902T114000"), #Sep 2, 1997 at 11:40 am
940
+ DateTime.parse("US-Eastern:19970902T120000"), #Sep 2, 1997 at 12:00 pm
941
+ DateTime.parse("US-Eastern:19970902T122000"), #Sep 2, 1997 at 12:20 pm
942
+ DateTime.parse("US-Eastern:19970902T124000"), #Sep 2, 1997 at 12:40 pm
943
+ DateTime.parse("US-Eastern:19970902T130000"), #Sep 2, 1997 at 13:00 pm
944
+ DateTime.parse("US-Eastern:19970902T132000"), #Sep 2, 1997 at 13:20 pm
945
+ DateTime.parse("US-Eastern:19970902T134000"), #Sep 2, 1997 at 13:40 pm
946
+ DateTime.parse("US-Eastern:19970902T140000"), #Sep 2, 1997 at 14:00 pm
947
+ DateTime.parse("US-Eastern:19970902T142000"), #Sep 2, 1997 at 14:20 pm
948
+ DateTime.parse("US-Eastern:19970902T144000"), #Sep 2, 1997 at 14:40 pm
949
+ DateTime.parse("US-Eastern:19970902T150000"), #Sep 2, 1997 at 15:00 pm
950
+ DateTime.parse("US-Eastern:19970902T152000"), #Sep 2, 1997 at 15:20 pm
951
+ DateTime.parse("US-Eastern:19970902T154000"), #Sep 2, 1997 at 15:40 pm
952
+ DateTime.parse("US-Eastern:19970902T160000"), #Sep 2, 1997 at 16:00 pm
953
+ DateTime.parse("US-Eastern:19970902T162000"), #Sep 2, 1997 at 16:20 pm
954
+ DateTime.parse("US-Eastern:19970902T164000"), #Sep 2, 1997 at 16:40 pm
955
+ DateTime.parse("US-Eastern:19970903T090000"), #Sep 3, 1997 at 9:00 am
956
+ DateTime.parse("US-Eastern:19970903T092000"), #Sep 3, 1997 at 9:20 am
957
+ DateTime.parse("US-Eastern:19970903T094000"), #Sep 3, 1997 at 9:40 am
958
+ DateTime.parse("US-Eastern:19970903T100000"), #Sep 3, 1997 at 10:00 am
959
+ DateTime.parse("US-Eastern:19970903T102000"), #Sep 3, 1997 at 10:20 am
960
+ DateTime.parse("US-Eastern:19970903T104000"), #Sep 3, 1997 at 10:40 am
961
+ DateTime.parse("US-Eastern:19970903T110000"), #Sep 3, 1997 at 11:00 am
962
+ DateTime.parse("US-Eastern:19970903T112000"), #Sep 3, 1997 at 11:20 am
963
+ DateTime.parse("US-Eastern:19970903T114000"), #Sep 3, 1997 at 11:40 am
964
+ DateTime.parse("US-Eastern:19970903T120000"), #Sep 3, 1997 at 12:00 pm
965
+ DateTime.parse("US-Eastern:19970903T122000"), #Sep 3, 1997 at 12:20 pm
966
+ DateTime.parse("US-Eastern:19970903T124000"), #Sep 3, 1997 at 12:40 pm
967
+ DateTime.parse("US-Eastern:19970903T130000"), #Sep 3, 1997 at 13:00 pm
968
+ DateTime.parse("US-Eastern:19970903T132000"), #Sep 3, 1997 at 13:20 pm
969
+ DateTime.parse("US-Eastern:19970903T134000"), #Sep 3, 1997 at 13:40 pm
970
+ DateTime.parse("US-Eastern:19970903T140000"), #Sep 3, 1997 at 14:00 pm
971
+ DateTime.parse("US-Eastern:19970903T142000"), #Sep 3, 1997 at 14:20 pm
972
+ DateTime.parse("US-Eastern:19970903T144000"), #Sep 3, 1997 at 14:40 pm
973
+ DateTime.parse("US-Eastern:19970903T150000"), #Sep 3, 1997 at 15:00 pm
974
+ DateTime.parse("US-Eastern:19970903T152000"), #Sep 3, 1997 at 15:20 pm
975
+ DateTime.parse("US-Eastern:19970903T154000"), #Sep 3, 1997 at 15:40 pm
976
+ DateTime.parse("US-Eastern:19970903T160000"), #Sep 3, 1997 at 16:00 pm
977
+ DateTime.parse("US-Eastern:19970903T162000"), #Sep 3, 1997 at 16:20 pm
978
+ DateTime.parse("US-Eastern:19970903T164000"), #Sep 3, 1997 at 16:40 pm
979
+ ]
980
+
981
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
982
+ results = te.hours(HourRange.new(start_date, end_date), 6)
983
+ assert_equal(expected, results)
984
+ end
985
+
986
+ # "Every 20 minutes from 9:00 AM to 4:40PM every day"
987
+ # (using a minute-based rule)
988
+ def test_example_36_b
989
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997 at 9am
990
+ end_date = DateTime.parse("US-Eastern:19970904T080000") #Sep 4, 1997 at 8am
991
+
992
+ #rrule = RecurrenceRule.new("FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16")
993
+
994
+ expected = [
995
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2, 1997 at 9:00 am
996
+ DateTime.parse("US-Eastern:19970902T092000"), #Sep 2, 1997 at 9:20 am
997
+ DateTime.parse("US-Eastern:19970902T094000"), #Sep 2, 1997 at 9:40 am
998
+ DateTime.parse("US-Eastern:19970902T100000"), #Sep 2, 1997 at 10:00 am
999
+ DateTime.parse("US-Eastern:19970902T102000"), #Sep 2, 1997 at 10:20 am
1000
+ DateTime.parse("US-Eastern:19970902T104000"), #Sep 2, 1997 at 10:40 am
1001
+ DateTime.parse("US-Eastern:19970902T110000"), #Sep 2, 1997 at 11:00 am
1002
+ DateTime.parse("US-Eastern:19970902T112000"), #Sep 2, 1997 at 11:20 am
1003
+ DateTime.parse("US-Eastern:19970902T114000"), #Sep 2, 1997 at 11:40 am
1004
+ DateTime.parse("US-Eastern:19970902T120000"), #Sep 2, 1997 at 12:00 pm
1005
+ DateTime.parse("US-Eastern:19970902T122000"), #Sep 2, 1997 at 12:20 pm
1006
+ DateTime.parse("US-Eastern:19970902T124000"), #Sep 2, 1997 at 12:40 pm
1007
+ DateTime.parse("US-Eastern:19970902T130000"), #Sep 2, 1997 at 13:00 pm
1008
+ DateTime.parse("US-Eastern:19970902T132000"), #Sep 2, 1997 at 13:20 pm
1009
+ DateTime.parse("US-Eastern:19970902T134000"), #Sep 2, 1997 at 13:40 pm
1010
+ DateTime.parse("US-Eastern:19970902T140000"), #Sep 2, 1997 at 14:00 pm
1011
+ DateTime.parse("US-Eastern:19970902T142000"), #Sep 2, 1997 at 14:20 pm
1012
+ DateTime.parse("US-Eastern:19970902T144000"), #Sep 2, 1997 at 14:40 pm
1013
+ DateTime.parse("US-Eastern:19970902T150000"), #Sep 2, 1997 at 15:00 pm
1014
+ DateTime.parse("US-Eastern:19970902T152000"), #Sep 2, 1997 at 15:20 pm
1015
+ DateTime.parse("US-Eastern:19970902T154000"), #Sep 2, 1997 at 15:40 pm
1016
+ DateTime.parse("US-Eastern:19970902T160000"), #Sep 2, 1997 at 16:00 pm
1017
+ DateTime.parse("US-Eastern:19970902T162000"), #Sep 2, 1997 at 16:20 pm
1018
+ DateTime.parse("US-Eastern:19970902T164000"), #Sep 2, 1997 at 16:40 pm
1019
+ DateTime.parse("US-Eastern:19970903T090000"), #Sep 3, 1997 at 9:00 am
1020
+ DateTime.parse("US-Eastern:19970903T092000"), #Sep 3, 1997 at 9:20 am
1021
+ DateTime.parse("US-Eastern:19970903T094000"), #Sep 3, 1997 at 9:40 am
1022
+ DateTime.parse("US-Eastern:19970903T100000"), #Sep 3, 1997 at 10:00 am
1023
+ DateTime.parse("US-Eastern:19970903T102000"), #Sep 3, 1997 at 10:20 am
1024
+ DateTime.parse("US-Eastern:19970903T104000"), #Sep 3, 1997 at 10:40 am
1025
+ DateTime.parse("US-Eastern:19970903T110000"), #Sep 3, 1997 at 11:00 am
1026
+ DateTime.parse("US-Eastern:19970903T112000"), #Sep 3, 1997 at 11:20 am
1027
+ DateTime.parse("US-Eastern:19970903T114000"), #Sep 3, 1997 at 11:40 am
1028
+ DateTime.parse("US-Eastern:19970903T120000"), #Sep 3, 1997 at 12:00 pm
1029
+ DateTime.parse("US-Eastern:19970903T122000"), #Sep 3, 1997 at 12:20 pm
1030
+ DateTime.parse("US-Eastern:19970903T124000"), #Sep 3, 1997 at 12:40 pm
1031
+ DateTime.parse("US-Eastern:19970903T130000"), #Sep 3, 1997 at 13:00 pm
1032
+ DateTime.parse("US-Eastern:19970903T132000"), #Sep 3, 1997 at 13:20 pm
1033
+ DateTime.parse("US-Eastern:19970903T134000"), #Sep 3, 1997 at 13:40 pm
1034
+ DateTime.parse("US-Eastern:19970903T140000"), #Sep 3, 1997 at 14:00 pm
1035
+ DateTime.parse("US-Eastern:19970903T142000"), #Sep 3, 1997 at 14:20 pm
1036
+ DateTime.parse("US-Eastern:19970903T144000"), #Sep 3, 1997 at 14:40 pm
1037
+ DateTime.parse("US-Eastern:19970903T150000"), #Sep 3, 1997 at 15:00 pm
1038
+ DateTime.parse("US-Eastern:19970903T152000"), #Sep 3, 1997 at 15:20 pm
1039
+ DateTime.parse("US-Eastern:19970903T154000"), #Sep 3, 1997 at 15:40 pm
1040
+ DateTime.parse("US-Eastern:19970903T160000"), #Sep 3, 1997 at 16:00 pm
1041
+ DateTime.parse("US-Eastern:19970903T162000"), #Sep 3, 1997 at 16:20 pm
1042
+ DateTime.parse("US-Eastern:19970903T164000"), #Sep 3, 1997 at 16:40 pm
1043
+ ]
1044
+
1045
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
1046
+ results = te.hours(HourRange.new(start_date, end_date), 6)
1047
+ assert_equal(expected, results)
1048
+ end
1049
+
1050
+ # "An example where the days generated makes a difference because of WKST"
1051
+ # (start of week day == Monday)
1052
+ def test_example_37_a
1053
+ start_date = DateTime.parse("US-Eastern:19970805T090000") #Aug 5, 1997
1054
+ end_date = DateTime.parse("US-Eastern:19970901T080000") #Sep 1, 1997
1055
+
1056
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO")
1057
+
1058
+ expected = [
1059
+ DateTime.parse("US-Eastern:19970805T090000"), #Aug 5, 1997
1060
+ DateTime.parse("US-Eastern:19970810T090000"), #Aug 10, 1997
1061
+ DateTime.parse("US-Eastern:19970819T090000"), #Aug 19, 1997
1062
+ DateTime.parse("US-Eastern:19970824T090000"), #Aug 24, 1997
1063
+ ]
1064
+
1065
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
1066
+ results = te.dates(DateRange.new(start_date, end_date), 6)
1067
+ assert_equal(expected, results)
1068
+ end
1069
+
1070
+ # "An example where the days generated makes a difference because of WKST"
1071
+ # (start of week day == Sunday)
1072
+ def test_example_37_b
1073
+ start_date = DateTime.parse("US-Eastern:19970805T090000") #Aug 5, 1997
1074
+ end_date = DateTime.parse("US-Eastern:19970901T080000") #Sep 1, 1997
1075
+
1076
+ #rrule = RecurrenceRule.new("FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU")
1077
+
1078
+ expected = [
1079
+ DateTime.parse("US-Eastern:19970805T090000"), #Aug 5, 1997
1080
+ DateTime.parse("US-Eastern:19970817T090000"), #Aug 17, 1997
1081
+ DateTime.parse("US-Eastern:19970819T090000"), #Aug 19, 1997
1082
+ DateTime.parse("US-Eastern:19970831T090000"), #Aug 31, 1997
1083
+ ]
1084
+
1085
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
1086
+ results = te.dates(DateRange.new(start_date, end_date), 6)
1087
+ assert_equal(expected, results)
1088
+ end
1089
+ =end
1090
+
1091
+ def debug(expected, results)
1092
+ puts "expected:"
1093
+ expected.each {|date| puts date}
1094
+ puts "results:"
1095
+ results.each {|date| puts date}
1096
+ end
1097
+
1098
+ #convenience method for creating an array of dates, one per day, from a start to an end date
1099
+ def self.get_date_range(start_date, end_date)
1100
+ dates = []
1101
+ start_date.upto(end_date) {|date| dates << date}
1102
+ dates
1103
+ end
1104
+ end