runt 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baseexpressiontest'
4
+
5
+ # Unit tests for BeforeTE class
6
+ # Author:: Matthew Lipper
7
+
8
+ class BeforeTETest < BaseExpressionTest
9
+
10
+ include TExpr
11
+
12
+ def test_include_inclusive
13
+ expr = BeforeTE.new(@pdate_20071030, true)
14
+ assert expr.include?(@date_20050101), "Should include an earlier date"
15
+ assert !expr.include?(@pdate_20071114), "Should not include a later date"
16
+ assert expr.include?(@pdate_20071030), "Should include the same date"
17
+ end
18
+
19
+ def test_include_non_inclusive
20
+ expr = BeforeTE.new(@pdate_20071030)
21
+ assert expr.include?(@date_20050101), "Should include an earlier date"
22
+ assert !expr.include?(@pdate_20071114), "Should not include a later date"
23
+ assert !expr.include?(@pdate_20071030), "Should not include the same date"
24
+ end
25
+
26
+ def test_to_s
27
+ expr = BeforeTE.new(@pdate_20071114)
28
+ assert_equal "before #{Runt.format_date(@pdate_20071114)}", expr.to_s
29
+ end
30
+
31
+ end
@@ -1,89 +1,89 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
6
-
7
- # Unit tests for DateRange class
8
- #
9
- # Author:: Matthew Lipper
10
- class DateRangeTest < Test::Unit::TestCase
11
-
12
- include Runt
13
-
14
- def test_sub_range
15
- r_start = PDate.sec(2004,2,29,16,24,12)
16
- r_end = PDate.sec(2004,3,2,4,22,58)
17
- range = DateRange.new(r_start,r_end)
18
- assert(range.min==r_start)
19
- assert(range.max==r_end)
20
- assert(range.include?(r_start+1))
21
- assert(range.include?(r_end-1))
22
- sub_range = DateRange.new((r_start+1),(r_end-1))
23
- assert(range.include?(sub_range))
24
- end
25
-
26
- def test_date
27
- r_start = PDate.min(1979,12,31,23,57)
28
- r_end = PDate.min(1980,1,1,0,2)
29
- range = DateRange.new(r_start,r_end)
30
- assert(range.min==r_start)
31
- assert(range.max==r_end)
32
- assert(range.include?(r_start+1))
33
- assert(range.include?(r_end-1))
34
- sub_range = DateRange.new((r_start+1),(r_end-1))
35
- assert(range.include?(sub_range))
36
- end
37
-
38
- def test_spaceship_operator
39
- r_start = PDate.min(1984,8,31,22,00)
40
- r_end = PDate.min(1984,9,15,0,2)
41
- range = DateRange.new(r_start,r_end)
42
- assert(-1==(range<=>(DateRange.new(r_start+2,r_end+5))))
43
- assert(1==(range<=>(DateRange.new(r_start-24,r_end+5))))
44
- assert(0==(range<=>(DateRange.new(r_start,r_end))))
45
- end
46
-
47
- def test_overlap
48
- r_start = PDate.month(2010,12)
49
- r_end = PDate.month(2011,12)
50
- range = DateRange.new(r_start,r_end)
51
- o_start = PDate.month(2010,11)
52
- o_end = PDate.month(2012,2)
53
- o_range = DateRange.new(o_start,o_end)
54
- assert(range.overlap?(o_range))
55
- assert(o_range.overlap?(range))
56
- assert(o_range.overlap?(DateRange.new(r_start,o_end)))
57
- assert(o_range.overlap?(DateRange.new(o_start,r_end)))
58
-
59
- # September 18th - 19th, 2005, 8am - 10am
60
- expr1=DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))
61
- # September 19th - 20th, 2005, 9am - 11am
62
- expr2=DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))
63
-
64
- assert(expr1.overlap?(expr2))
65
- end
66
-
67
- def test_empty
68
- r_start = PDate.hour(2004,2,10,0)
69
- r_end = PDate.hour(2004,2,9,23)
70
- empty_range = DateRange.new(r_start,r_end)
71
- assert(empty_range.empty?)
72
- assert(DateRange::EMPTY.empty?)
73
- # start == end should be empty
74
- assert DateRange.new(r_start,r_start).empty?, "Range should be empty when start == end"
75
- end
76
-
77
- def test_gap
78
- r_start = PDate.day(2000,6,12)
79
- r_end = PDate.day(2000,6,14)
80
- range = DateRange.new(r_start,r_end)
81
- g_start = PDate.day(2000,6,18)
82
- g_end = PDate.day(2000,6,20)
83
- g_range = DateRange.new(g_start,g_end)
84
- the_gap=range.gap(g_range)
85
- assert(the_gap.start_expr==(r_end+1))
86
- assert(the_gap.end_expr==(g_start-1))
87
- end
88
-
89
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+ require 'date'
6
+
7
+ # Unit tests for DateRange class
8
+ #
9
+ # Author:: Matthew Lipper
10
+ class DateRangeTest < Test::Unit::TestCase
11
+
12
+ include Runt
13
+
14
+ def test_sub_range
15
+ r_start = PDate.sec(2004,2,29,16,24,12)
16
+ r_end = PDate.sec(2004,3,2,4,22,58)
17
+ range = DateRange.new(r_start,r_end)
18
+ assert(range.min==r_start)
19
+ assert(range.max==r_end)
20
+ assert(range.include?(r_start+1))
21
+ assert(range.include?(r_end-1))
22
+ sub_range = DateRange.new((r_start+1),(r_end-1))
23
+ assert(range.include?(sub_range))
24
+ end
25
+
26
+ def test_date
27
+ r_start = PDate.min(1979,12,31,23,57)
28
+ r_end = PDate.min(1980,1,1,0,2)
29
+ range = DateRange.new(r_start,r_end)
30
+ assert(range.min==r_start)
31
+ assert(range.max==r_end)
32
+ assert(range.include?(r_start+1))
33
+ assert(range.include?(r_end-1))
34
+ sub_range = DateRange.new((r_start+1),(r_end-1))
35
+ assert(range.include?(sub_range))
36
+ end
37
+
38
+ def test_spaceship_operator
39
+ r_start = PDate.min(1984,8,31,22,00)
40
+ r_end = PDate.min(1984,9,15,0,2)
41
+ range = DateRange.new(r_start,r_end)
42
+ assert(-1==(range<=>(DateRange.new(r_start+2,r_end+5))))
43
+ assert(1==(range<=>(DateRange.new(r_start-24,r_end+5))))
44
+ assert(0==(range<=>(DateRange.new(r_start,r_end))))
45
+ end
46
+
47
+ def test_overlap
48
+ r_start = PDate.month(2010,12)
49
+ r_end = PDate.month(2011,12)
50
+ range = DateRange.new(r_start,r_end)
51
+ o_start = PDate.month(2010,11)
52
+ o_end = PDate.month(2012,2)
53
+ o_range = DateRange.new(o_start,o_end)
54
+ assert(range.overlap?(o_range))
55
+ assert(o_range.overlap?(range))
56
+ assert(o_range.overlap?(DateRange.new(r_start,o_end)))
57
+ assert(o_range.overlap?(DateRange.new(o_start,r_end)))
58
+
59
+ # September 18th - 19th, 2005, 8am - 10am
60
+ expr1=DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))
61
+ # September 19th - 20th, 2005, 9am - 11am
62
+ expr2=DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))
63
+
64
+ assert(expr1.overlap?(expr2))
65
+ end
66
+
67
+ def test_empty
68
+ r_start = PDate.hour(2004,2,10,0)
69
+ r_end = PDate.hour(2004,2,9,23)
70
+ empty_range = DateRange.new(r_start,r_end)
71
+ assert(empty_range.empty?)
72
+ assert(DateRange::EMPTY.empty?)
73
+ # start == end should be empty
74
+ assert DateRange.new(r_start,r_start).empty?, "Range should be empty when start == end"
75
+ end
76
+
77
+ def test_gap
78
+ r_start = PDate.day(2000,6,12)
79
+ r_end = PDate.day(2000,6,14)
80
+ range = DateRange.new(r_start,r_end)
81
+ g_start = PDate.day(2000,6,18)
82
+ g_end = PDate.day(2000,6,20)
83
+ g_range = DateRange.new(g_start,g_end)
84
+ the_gap=range.gap(g_range)
85
+ assert(the_gap.start_expr==(r_end+1))
86
+ assert(the_gap.end_expr==(g_start-1))
87
+ end
88
+
89
+ end
@@ -1,55 +1,58 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
6
-
7
- # Unit tests for DPrecision class
8
- #
9
- # Author:: Matthew Lipper
10
-
11
- class DPrecisionTest < Test::Unit::TestCase
12
-
13
- include Runt
14
-
15
- def test_comparable
16
- assert(DPrecision::YEAR<DPrecision::MONTH, "DPrecision.year was not less than DPrecision.month")
17
- assert(DPrecision::MONTH<DPrecision::DAY, "DPrecision.month was not less than DPrecision.day")
18
- assert(DPrecision::DAY<DPrecision::HOUR, "DPrecision.day was not less than DPrecision.hour")
19
- assert(DPrecision::HOUR<DPrecision::MIN, "DPrecision.hour was not less than DPrecision.min")
20
- assert(DPrecision::MIN<DPrecision::SEC, "DPrecision.min was not less than DPrecision.sec")
21
- assert(DPrecision::SEC<DPrecision::MILLI, "DPrecision.sec was not less than DPrecision.millisec")
22
- end
23
-
24
- def test_pseudo_singleton_instance
25
- assert(DPrecision::YEAR.object_id==DPrecision::YEAR.object_id, "Object Id's not equal.")
26
- assert(DPrecision::MONTH.object_id==DPrecision::MONTH.object_id, "Object Id's not equal.")
27
- assert(DPrecision::DAY.object_id==DPrecision::DAY.object_id, "Object Id's not equal.")
28
- assert(DPrecision::HOUR.object_id==DPrecision::HOUR.object_id, "Object Id's not equal.")
29
- assert(DPrecision::MIN.object_id==DPrecision::MIN.object_id, "Object Id's not equal.")
30
- assert(DPrecision::SEC.object_id==DPrecision::SEC.object_id, "Object Id's not equal.")
31
- assert(DPrecision::MILLI.object_id==DPrecision::MILLI.object_id, "Object Id's not equal.")
32
- end
33
-
34
- def test_to_precision
35
- #February 29th, 2004
36
- no_prec_date = PDate.civil(2004,2,29)
37
- month_prec = PDate.month(2004,2,29)
38
- assert(month_prec==DPrecision.to_p(no_prec_date,DPrecision::MONTH))
39
- #11:59:59 am, February 29th, 2004
40
- no_prec_datetime = PDate.civil(2004,2,29,23,59,59)
41
- #puts "-->#{no_prec_datetime.date_precision}<--"
42
- assert(month_prec==DPrecision.to_p(no_prec_datetime,DPrecision::MONTH))
43
- end
44
-
45
- def test_label
46
- assert_equal(DPrecision::YEAR.label,"YEAR")
47
- assert_equal(DPrecision::MONTH.label,"MONTH")
48
- assert_equal(DPrecision::DAY.label,"DAY")
49
- assert_equal(DPrecision::HOUR.label,"HOUR")
50
- assert_equal(DPrecision::MIN.label,"MINUTE")
51
- assert_equal(DPrecision::SEC.label,"SECOND")
52
- assert_equal(DPrecision::MILLI.label,"MILLISECOND")
53
- end
54
-
55
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+ require 'date'
6
+
7
+ # Unit tests for DPrecision class
8
+ #
9
+ # Author:: Matthew Lipper
10
+
11
+ class DPrecisionTest < Test::Unit::TestCase
12
+
13
+ include Runt
14
+
15
+ def test_comparable
16
+ assert(DPrecision::YEAR<DPrecision::MONTH, "DPrecision.year was not less than DPrecision.month")
17
+ assert(DPrecision::MONTH<DPrecision::WEEK, "DPrecision.month was not less than DPrecision.week")
18
+ assert(DPrecision::WEEK<DPrecision::DAY, "DPrecision.week was not less than DPrecision.day")
19
+ assert(DPrecision::DAY<DPrecision::HOUR, "DPrecision.day was not less than DPrecision.hour")
20
+ assert(DPrecision::HOUR<DPrecision::MIN, "DPrecision.hour was not less than DPrecision.min")
21
+ assert(DPrecision::MIN<DPrecision::SEC, "DPrecision.min was not less than DPrecision.sec")
22
+ assert(DPrecision::SEC<DPrecision::MILLI, "DPrecision.sec was not less than DPrecision.millisec")
23
+ end
24
+
25
+ def test_pseudo_singleton_instance
26
+ assert(DPrecision::YEAR.object_id==DPrecision::YEAR.object_id, "Object Id's not equal.")
27
+ assert(DPrecision::MONTH.object_id==DPrecision::MONTH.object_id, "Object Id's not equal.")
28
+ assert(DPrecision::WEEK.object_id==DPrecision::WEEK.object_id, "Object Id's not equal.")
29
+ assert(DPrecision::DAY.object_id==DPrecision::DAY.object_id, "Object Id's not equal.")
30
+ assert(DPrecision::HOUR.object_id==DPrecision::HOUR.object_id, "Object Id's not equal.")
31
+ assert(DPrecision::MIN.object_id==DPrecision::MIN.object_id, "Object Id's not equal.")
32
+ assert(DPrecision::SEC.object_id==DPrecision::SEC.object_id, "Object Id's not equal.")
33
+ assert(DPrecision::MILLI.object_id==DPrecision::MILLI.object_id, "Object Id's not equal.")
34
+ end
35
+
36
+ def test_to_precision
37
+ #February 29th, 2004
38
+ no_prec_date = PDate.civil(2004,2,29)
39
+ month_prec = PDate.month(2004,2,29)
40
+ assert(month_prec==DPrecision.to_p(no_prec_date,DPrecision::MONTH))
41
+ #11:59:59 am, February 29th, 2004
42
+ no_prec_datetime = PDate.civil(2004,2,29,23,59,59)
43
+ #puts "-->#{no_prec_datetime.date_precision}<--"
44
+ assert(month_prec==DPrecision.to_p(no_prec_datetime,DPrecision::MONTH))
45
+ end
46
+
47
+ def test_label
48
+ assert_equal(DPrecision::YEAR.label,"YEAR")
49
+ assert_equal(DPrecision::MONTH.label,"MONTH")
50
+ assert_equal(DPrecision::WEEK.label,"WEEK")
51
+ assert_equal(DPrecision::DAY.label,"DAY")
52
+ assert_equal(DPrecision::HOUR.label,"HOUR")
53
+ assert_equal(DPrecision::MIN.label,"MINUTE")
54
+ assert_equal(DPrecision::SEC.label,"SECOND")
55
+ assert_equal(DPrecision::MILLI.label,"MILLISECOND")
56
+ end
57
+
58
+ 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
@@ -63,9 +63,7 @@ class ICalendarTest < Test::Unit::TestCase
63
63
  DateTime.parse("US-Eastern:19971002T090000"), #Oct 02
64
64
  ]
65
65
 
66
- #we have to set the precision for use in EveryTE
67
- start_date.date_precision = DPrecision::DAY
68
- te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 2)
66
+ te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 2, DPrecision::DAY)
69
67
  results = te.dates(DateRange.new(start_date, end_date))
70
68
  assert_equal(expected, results)
71
69
 
@@ -90,9 +88,7 @@ class ICalendarTest < Test::Unit::TestCase
90
88
  DateTime.parse("US-Eastern:19971012T090000"), #Oct 12
91
89
  ]
92
90
 
93
- #we have to set the precision for use in EveryTE
94
- start_date.date_precision = DPrecision::DAY
95
- te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 10)
91
+ te = REWeek.new(Sun,Sat) & EveryTE.new(start_date, 10, DPrecision::DAY)
96
92
  results = te.dates(DateRange.new(start_date, end_date), 5)
97
93
  assert_equal(expected, results)
98
94
 
@@ -136,11 +132,12 @@ class ICalendarTest < Test::Unit::TestCase
136
132
  assert_equal(expected, results)
137
133
  end
138
134
 
139
- =begin
140
135
  # "Weekly for 10 occurrences"
141
136
  def test_example_6
142
- start_date = DateTime.parse("US-Eastern:19970902T090000")
143
- rrule = RecurrenceRule.new("FREQ=WEEKLY;COUNT=10")
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")
144
141
 
145
142
  expected = [
146
143
  DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
@@ -154,15 +151,18 @@ class ICalendarTest < Test::Unit::TestCase
154
151
  DateTime.parse("US-Eastern:19971028T090000"), #Oct 28
155
152
  DateTime.parse("US-Eastern:19971104T090000"), #Nov 4
156
153
  ]
157
- results = te.dates(DateRange.new(start_date, END_DATE))
158
154
 
155
+ te = EveryTE.new(start_date, 7, DPrecision::DAY)
156
+ results = te.dates(DateRange.new(start_date, end_date), 10)
159
157
  assert_equal(expected, results)
160
158
  end
161
-
159
+
162
160
  # "Weekly until December 24th, 1997"
163
161
  def test_example_7
164
- start_date = DateTime.parse("US-Eastern:19970902T090000")
165
- rrule = RecurrenceRule.new("FREQ=WEEKLY;UNTIL=19971224T000000Z")
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
166
 
167
167
  expected = [
168
168
  DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
@@ -183,19 +183,44 @@ class ICalendarTest < Test::Unit::TestCase
183
183
  DateTime.parse("US-Eastern:19971216T090000"), #Dec 16
184
184
  DateTime.parse("US-Eastern:19971223T090000"), #Dec 23
185
185
  ]
186
- results = te.dates(DateRange.new(start_date, END_DATE))
187
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))
188
189
  assert_equal(expected, results)
189
190
  end
190
-
191
+
191
192
  # "Every other week - forever"
192
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)
193
216
  end
194
-
217
+
195
218
  # "Weekly on Tuesday and Thursday for 5 weeks (first example, using until)"
196
219
  def test_example_9_a
197
- start_date = DateTime.parse("US-Eastern:19970902T090000")
198
- rrule = RecurrenceRule.new("FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH")
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")
199
224
 
200
225
  expected = [
201
226
  DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
@@ -209,15 +234,18 @@ class ICalendarTest < Test::Unit::TestCase
209
234
  DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
210
235
  DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
211
236
  ]
212
- results = te.dates(DateRange.new(start_date, END_DATE))
213
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))
214
240
  assert_equal(expected, results)
215
241
  end
216
242
 
217
243
  # "Weekly on Tuesday and Thursday for 5 weeks (second example, using count)"
218
244
  def test_example_9_b
219
- start_date = DateTime.parse("US-Eastern:19970902T090000")
220
- rrule = RecurrenceRule.new("FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH")
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")
221
249
 
222
250
  expected = [
223
251
  DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
@@ -231,20 +259,78 @@ class ICalendarTest < Test::Unit::TestCase
231
259
  DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
232
260
  DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
233
261
  ]
234
- results = te.dates(DateRange.new(start_date, END_DATE))
235
262
 
263
+ te = DIWeek.new(Tue) | DIWeek.new(Thu)
264
+ results = te.dates(DateRange.new(start_date, end_date), 10)
236
265
  assert_equal(expected, results)
237
266
  end
238
-
267
+
239
268
  # "Every other week on Monday, Wednesday, and Friday until December 24, 1997
240
269
  # but starting on Tuesday, September 2, 1997"
241
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)
242
310
  end
243
311
 
244
312
  # "Every other week on Tuesday and Thursday, for 8 occurences"
245
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)
246
333
  end
247
- =end
248
334
 
249
335
  # "Monthly on the 1st Friday for ten occurences"
250
336
  def test_example_12
@@ -310,9 +396,7 @@ class ICalendarTest < Test::Unit::TestCase
310
396
  DateTime.parse("US-Eastern:19980531T090000"), #May 31
311
397
  ]
312
398
 
313
- #set the date precision for the EveryTe
314
- start_date.date_precision = DPrecision::MONTH
315
- te = EveryTE.new(start_date, 2) & (DIMonth.new(1,0) | DIMonth.new(-1,0)) #first and last Sundays
399
+ te = EveryTE.new(start_date, 2, DPrecision::MONTH) & (DIMonth.new(1,0) | DIMonth.new(-1,0)) #first and last Sundays
316
400
  results = te.dates(DateRange.new(start_date, end_date), 10)
317
401
  assert_equal(expected, results)
318
402
  end
@@ -435,9 +519,7 @@ class ICalendarTest < Test::Unit::TestCase
435
519
  DateTime.parse("US-Eastern:19990313T090000"), #Mar 13, 1999
436
520
  ]
437
521
 
438
- #we have to set the precision for use in EveryTE
439
- start_date.date_precision = DPrecision::MONTH
440
- te = EveryTE.new(start_date, 18) & REMonth.new(10,15) #tenth through the fifteenth
522
+ te = REMonth.new(10,15) & EveryTE.new(start_date, 18, DPrecision::MONTH) #tenth through the fifteenth
441
523
  results = te.dates(DateRange.new(start_date, end_date), 10)
442
524
  assert_equal(expected, results)
443
525
  end
@@ -458,21 +540,19 @@ class ICalendarTest < Test::Unit::TestCase
458
540
  DateTime.parse("US-Eastern:19971104T090000"), #Nov 04, 1997
459
541
  DateTime.parse("US-Eastern:19971111T090000"), #Nov 11, 1997
460
542
  DateTime.parse("US-Eastern:19971118T090000"), #Nov 18, 1997
461
- DateTime.parse("US-Eastern:19971125T090000"), #Nov 25, 1997
543
+ DateTime.parse("US-Eastern:19971125T090000"), #Nov 25, 1997
462
544
  DateTime.parse("US-Eastern:19980106T090000"), #Jan 06, 1998
463
545
  DateTime.parse("US-Eastern:19980113T090000"), #Jan 13, 1998
464
546
  DateTime.parse("US-Eastern:19980120T090000"), #Jan 20, 1998
465
547
  DateTime.parse("US-Eastern:19980127T090000"), #Jan 27, 1998
466
- DateTime.parse("US-Eastern:19980303T090000"), #Mar 03, 1998
467
- DateTime.parse("US-Eastern:19980310T090000"), #Mar 10, 1998
468
- DateTime.parse("US-Eastern:19980317T090000"), #Mar 17, 1998
469
- DateTime.parse("US-Eastern:19980324T090000"), #Mar 24, 1998
470
- DateTime.parse("US-Eastern:19980331T090000"), #Mar 31, 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
471
553
  ]
472
554
 
473
- #we have to set the precision for use in EveryTE
474
- start_date.date_precision = DPrecision::MONTH
475
- te = EveryTE.new(start_date, 2) & DIWeek.new(Tuesday)
555
+ te = EveryTE.new(start_date, 2, DPrecision::MONTH) & DIWeek.new(Tuesday)
476
556
  results = te.dates(DateRange.new(start_date, end_date))
477
557
  assert_equal(expected, results)
478
558
  end
@@ -501,13 +581,513 @@ class ICalendarTest < Test::Unit::TestCase
501
581
  DateTime.parse("US-Eastern:20010710T090000"), #Jul 10, 2001
502
582
  ]
503
583
 
504
- #we have to set the precision for use in EveryTE
505
- start_date.date_precision = DPrecision::YEAR
506
584
  te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
507
585
  results = te.dates(DateRange.new(start_date, end_date), 10)
508
586
  assert_equal(expected, results)
509
587
  end
510
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
+
511
1091
  def debug(expected, results)
512
1092
  puts "expected:"
513
1093
  expected.each {|date| puts date}