runt 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +1,87 @@
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
- end
74
-
75
- def test_gap
76
- r_start = PDate.day(2000,6,12)
77
- r_end = PDate.day(2000,6,14)
78
- range = DateRange.new(r_start,r_end)
79
- g_start = PDate.day(2000,6,18)
80
- g_end = PDate.day(2000,6,20)
81
- g_range = DateRange.new(g_start,g_end)
82
- the_gap=range.gap(g_range)
83
- assert(the_gap.start_expr==(r_end+1))
84
- assert(the_gap.end_expr==(g_start-1))
85
- end
86
-
87
- 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
+ end
74
+
75
+ def test_gap
76
+ r_start = PDate.day(2000,6,12)
77
+ r_end = PDate.day(2000,6,14)
78
+ range = DateRange.new(r_start,r_end)
79
+ g_start = PDate.day(2000,6,18)
80
+ g_end = PDate.day(2000,6,20)
81
+ g_range = DateRange.new(g_start,g_end)
82
+ the_gap=range.gap(g_range)
83
+ assert(the_gap.start_expr==(r_end+1))
84
+ assert(the_gap.end_expr==(g_start-1))
85
+ end
86
+
87
+ end
@@ -1,45 +1,55 @@
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
- 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::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
@@ -0,0 +1,524 @@
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
+ #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)
69
+ results = te.dates(DateRange.new(start_date, end_date))
70
+ assert_equal(expected, results)
71
+
72
+ #alternatively we could use the DayIntervalTE
73
+ te = DayIntervalTE.new(start_date, 2)
74
+ results = te.dates(DateRange.new(start_date, end_date))
75
+ assert_equal(expected, results)
76
+ end
77
+
78
+ # "Every 10 days, 5 occurrences"
79
+ def test_example_4
80
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
81
+ end_date = start_date + 180 #Mar 1, 1998 (halved the normal test range because EveryTE is pretty slow)
82
+
83
+ #rrule = RecurrenceRule.new("FREQ=DAILY;INTERVAL=10;COUNT=5")
84
+
85
+ expected = [
86
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
87
+ DateTime.parse("US-Eastern:19970912T090000"), #Sep 12
88
+ DateTime.parse("US-Eastern:19970922T090000"), #Sep 22
89
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
90
+ DateTime.parse("US-Eastern:19971012T090000"), #Oct 12
91
+ ]
92
+
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)
96
+ results = te.dates(DateRange.new(start_date, end_date), 5)
97
+ assert_equal(expected, results)
98
+
99
+ #alternatively we could use the DayIntervalTE
100
+ te = DayIntervalTE.new(start_date, 10)
101
+ results = te.dates(DateRange.new(start_date, end_date), 5 )
102
+ assert_equal(expected, results)
103
+ end
104
+
105
+ # "Every day in January, for 3 years" (first example, yearly byday)
106
+ def test_example_5_a
107
+ start_date = DateTime.parse("US-Eastern:19980101T090000") #Jan 1, 1998
108
+ end_date = start_date + 365 + 365 + 366 + 31 #Feb 1, 2001
109
+
110
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA")
111
+
112
+ expected = []
113
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19980101T090000"), DateTime.parse("US-Eastern:19980131T090000"))
114
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19990101T090000"), DateTime.parse("US-Eastern:19990131T090000"))
115
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:20000101T090000"), DateTime.parse("US-Eastern:20000131T090000"))
116
+
117
+ 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))
118
+ results = te.dates(DateRange.new(start_date, end_date))
119
+ assert_equal(expected, results)
120
+ end
121
+
122
+ # "Every day in January, for 3 years" (second example, daily bymonth)
123
+ def test_example_5_b
124
+ start_date = DateTime.parse("US-Eastern:19980101T090000")
125
+ end_date = start_date + 365 + 365 + 366 + 31 #Feb 1, 2001
126
+
127
+ #rrule = RecurrenceRule.new("FREQ=DAILY;UNTIL=20000131T090000Z;BYMONTH=1")
128
+
129
+ expected = []
130
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19980101T090000"), DateTime.parse("US-Eastern:19980131T090000"))
131
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:19990101T090000"), DateTime.parse("US-Eastern:19990131T090000"))
132
+ expected += ICalendarTest.get_date_range(DateTime.parse("US-Eastern:20000101T090000"), DateTime.parse("US-Eastern:20000131T090000"))
133
+
134
+ te = BeforeTE.new(DateTime.parse("20000131T090000"), true) & REWeek.new(Sun, Sat) & REYear.new(1)
135
+ results = te.dates(DateRange.new(start_date, end_date))
136
+ assert_equal(expected, results)
137
+ end
138
+
139
+ =begin
140
+ # "Weekly for 10 occurrences"
141
+ def test_example_6
142
+ start_date = DateTime.parse("US-Eastern:19970902T090000")
143
+ rrule = RecurrenceRule.new("FREQ=WEEKLY;COUNT=10")
144
+
145
+ expected = [
146
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
147
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
148
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
149
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
150
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
151
+ DateTime.parse("US-Eastern:19971007T090000"), #Oct 7
152
+ DateTime.parse("US-Eastern:19971014T090000"), #Oct 14
153
+ DateTime.parse("US-Eastern:19971021T090000"), #Oct 21
154
+ DateTime.parse("US-Eastern:19971028T090000"), #Oct 28
155
+ DateTime.parse("US-Eastern:19971104T090000"), #Nov 4
156
+ ]
157
+ results = te.dates(DateRange.new(start_date, END_DATE))
158
+
159
+ assert_equal(expected, results)
160
+ end
161
+
162
+ # "Weekly until December 24th, 1997"
163
+ def test_example_7
164
+ start_date = DateTime.parse("US-Eastern:19970902T090000")
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
+ results = te.dates(DateRange.new(start_date, END_DATE))
187
+
188
+ assert_equal(expected, results)
189
+ end
190
+
191
+ # "Every other week - forever"
192
+ def test_example_8
193
+ end
194
+
195
+ # "Weekly on Tuesday and Thursday for 5 weeks (first example, using until)"
196
+ 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")
199
+
200
+ expected = [
201
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
202
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
203
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
204
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11
205
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
206
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
207
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
208
+ DateTime.parse("US-Eastern:19970925T090000"), #Sep 25
209
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
210
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
211
+ ]
212
+ results = te.dates(DateRange.new(start_date, END_DATE))
213
+
214
+ assert_equal(expected, results)
215
+ end
216
+
217
+ # "Weekly on Tuesday and Thursday for 5 weeks (second example, using count)"
218
+ 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")
221
+
222
+ expected = [
223
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
224
+ DateTime.parse("US-Eastern:19970904T090000"), #Sep 4
225
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 9
226
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11
227
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16
228
+ DateTime.parse("US-Eastern:19970918T090000"), #Sep 18
229
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23
230
+ DateTime.parse("US-Eastern:19970925T090000"), #Sep 25
231
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
232
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
233
+ ]
234
+ results = te.dates(DateRange.new(start_date, END_DATE))
235
+
236
+ assert_equal(expected, results)
237
+ end
238
+
239
+ # "Every other week on Monday, Wednesday, and Friday until December 24, 1997
240
+ # but starting on Tuesday, September 2, 1997"
241
+ def test_example_10
242
+ end
243
+
244
+ # "Every other week on Tuesday and Thursday, for 8 occurences"
245
+ def test_example_11
246
+ end
247
+ =end
248
+
249
+ # "Monthly on the 1st Friday for ten occurences"
250
+ def test_example_12
251
+ start_date = DateTime.parse("US-Eastern:19970905T090000") #Sep 5, 1997
252
+ end_date = start_date + 365 #Sep 5, 1998
253
+
254
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYDAY=1FR")
255
+
256
+ expected = [
257
+ DateTime.parse("US-Eastern:19970905T090000"), #Sep 5
258
+ DateTime.parse("US-Eastern:19971003T090000"), #Oct 3
259
+ DateTime.parse("US-Eastern:19971107T090000"), #Nov 7
260
+ DateTime.parse("US-Eastern:19971205T090000"), #Dec 5
261
+ DateTime.parse("US-Eastern:19980102T090000"), #Jan 2
262
+ DateTime.parse("US-Eastern:19980206T090000"), #Feb 6
263
+ DateTime.parse("US-Eastern:19980306T090000"), #Mar 6
264
+ DateTime.parse("US-Eastern:19980403T090000"), #Apr 3
265
+ DateTime.parse("US-Eastern:19980501T090000"), #May 1
266
+ DateTime.parse("US-Eastern:19980605T090000"), #Jun 5
267
+ ]
268
+
269
+ te = DIMonth.new(1,5) #first friday
270
+ results = te.dates(DateRange.new(start_date, end_date), 10)
271
+ assert_equal(expected, results)
272
+ end
273
+
274
+ # "Monthly on the 1st Friday until December 24, 1997"
275
+ def test_example_13
276
+ start_date = DateTime.parse("US-Eastern:19970905T090000") #Sep 5, 1997
277
+ end_date = start_date + 365 #Sep 5, 1998
278
+
279
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;UNTIL=19971224T000000;BYDAY=1FR")
280
+
281
+ expected = [
282
+ DateTime.parse("US-Eastern:19970905T090000"), #Sep 5
283
+ DateTime.parse("US-Eastern:19971003T090000"), #Oct 3
284
+ DateTime.parse("US-Eastern:19971107T090000"), #Nov 7
285
+ DateTime.parse("US-Eastern:19971205T090000"), #Dec 5
286
+ ]
287
+
288
+ te = BeforeTE.new(DateTime.parse("US-Eastern:19971224T000000")) & DIMonth.new(1,5) #first friday
289
+ results = te.dates(DateRange.new(start_date, end_date))
290
+ assert_equal(expected, results)
291
+ end
292
+
293
+ # "Every other month on the 1st and last Sunday of the month for 10 occurences"
294
+ def test_example_14
295
+ start_date = DateTime.parse("US-Eastern:19970907T090000") #Sep 7, 1997
296
+ end_date = start_date + 365 #Sep 7, 1998
297
+
298
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU")
299
+
300
+ expected = [
301
+ DateTime.parse("US-Eastern:19970907T090000"), #Sep 5
302
+ DateTime.parse("US-Eastern:19970928T090000"), #Sep 28
303
+ DateTime.parse("US-Eastern:19971102T090000"), #Nov 2
304
+ DateTime.parse("US-Eastern:19971130T090000"), #Nov 30
305
+ DateTime.parse("US-Eastern:19980104T090000"), #Jan 4
306
+ DateTime.parse("US-Eastern:19980125T090000"), #Jan 25
307
+ DateTime.parse("US-Eastern:19980301T090000"), #Mar 1
308
+ DateTime.parse("US-Eastern:19980329T090000"), #Mar 29
309
+ DateTime.parse("US-Eastern:19980503T090000"), #May 3
310
+ DateTime.parse("US-Eastern:19980531T090000"), #May 31
311
+ ]
312
+
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
316
+ results = te.dates(DateRange.new(start_date, end_date), 10)
317
+ assert_equal(expected, results)
318
+ end
319
+
320
+ # "Monthly on the second to last Monday of the month for 6 months"
321
+ def test_example_15
322
+ start_date = DateTime.parse("US-Eastern:19970922T090000") #Sep 22, 1997
323
+ end_date = start_date + 365 #Sep 22, 1998
324
+
325
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=6;BYDAY=-2MO")
326
+
327
+ expected = [
328
+ DateTime.parse("US-Eastern:19970922T090000"), #Sep 22
329
+ DateTime.parse("US-Eastern:19971020T090000"), #Oct 20
330
+ DateTime.parse("US-Eastern:19971117T090000"), #Nov 17
331
+ DateTime.parse("US-Eastern:19971222T090000"), #Dec 22
332
+ DateTime.parse("US-Eastern:19980119T090000"), #Jan 19
333
+ DateTime.parse("US-Eastern:19980216T090000"), #Feb 16
334
+ ]
335
+
336
+ te = DIMonth.new(-2,1) #second to last Monday
337
+ results = te.dates(DateRange.new(start_date, end_date), 6)
338
+ assert_equal(expected, results)
339
+ end
340
+
341
+ =begin
342
+ #### NOTE: Runt does not currently support negative day of month references!
343
+ # "Monthly on the third to the last day of the month, forever"
344
+ def test_example_16
345
+ start_date = DateTime.parse("US-Eastern:19970922T090000") #Sep 22, 1997
346
+ end_date = DateTime.parse("US-Eastern:19980301T090000"), #Mar 1, 1998
347
+
348
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;BYMONTHDAY=-3")
349
+
350
+ expected = [
351
+ DateTime.parse("US-Eastern:19970928T090000"), #Sep 28
352
+ DateTime.parse("US-Eastern:19971029T090000"), #Oct 29
353
+ DateTime.parse("US-Eastern:19971128T090000"), #Nov 28
354
+ DateTime.parse("US-Eastern:19971229T090000"), #Dec 29
355
+ DateTime.parse("US-Eastern:19980129T090000"), #Jan 29
356
+ DateTime.parse("US-Eastern:19980226T090000"), #Feb 26
357
+ ]
358
+
359
+ te = REMonth.new(-3) #third to last day of the month
360
+ results = te.dates(DateRange.new(start_date, end_date))
361
+ assert_equal(expected, results)
362
+ end
363
+ =end
364
+
365
+ # "Monthly on the 2nd and 15th of the month for 10 occurences"
366
+ def test_example_17
367
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
368
+ end_date = start_date + 365 #Sep 2, 1998
369
+
370
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15")
371
+
372
+ expected = [
373
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 2
374
+ DateTime.parse("US-Eastern:19970915T090000"), #Sep 15
375
+ DateTime.parse("US-Eastern:19971002T090000"), #Oct 2
376
+ DateTime.parse("US-Eastern:19971015T090000"), #Oct 15
377
+ DateTime.parse("US-Eastern:19971102T090000"), #Nov 2
378
+ DateTime.parse("US-Eastern:19971115T090000"), #Nov 15
379
+ DateTime.parse("US-Eastern:19971202T090000"), #Dec 2
380
+ DateTime.parse("US-Eastern:19971215T090000"), #Dec 15
381
+ DateTime.parse("US-Eastern:19980102T090000"), #Jan 2
382
+ DateTime.parse("US-Eastern:19980115T090000"), #Jan 15
383
+ ]
384
+
385
+ te = REMonth.new(2) | REMonth.new(15) #second or fifteenth of the month
386
+ results = te.dates(DateRange.new(start_date, end_date), 10)
387
+ assert_equal(expected, results)
388
+ end
389
+
390
+ =begin
391
+ #### NOTE: Runt does not currently support negative day of month references!
392
+ # "Monthly on the first and last day of the month for 10 occurences"
393
+ def test_example_18
394
+ start_date = DateTime.parse("US-Eastern:19970930T090000") #Sep 30, 1997
395
+ end_date = start_date + 365 #Sep 30, 1998
396
+
397
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1")
398
+
399
+ expected = [
400
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30
401
+ DateTime.parse("US-Eastern:19971001T090000"), #Oct 1
402
+ DateTime.parse("US-Eastern:19971031T090000"), #Oct 31
403
+ DateTime.parse("US-Eastern:19971101T090000"), #Nov 1
404
+ DateTime.parse("US-Eastern:19971130T090000"), #Nov 30
405
+ DateTime.parse("US-Eastern:19971201T090000"), #Dec 1
406
+ DateTime.parse("US-Eastern:19971231T090000"), #Dec 31
407
+ DateTime.parse("US-Eastern:19980101T090000"), #Jan 1
408
+ DateTime.parse("US-Eastern:19980131T090000"), #Jan 31
409
+ DateTime.parse("US-Eastern:19980201T090000"), #Feb 1
410
+ ]
411
+
412
+ te = REMonth.new(1) | REMonth.new(-1) #first and last days of the month
413
+ results = te.dates(DateRange.new(start_date, end_date), 10)
414
+ assert_equal(expected, results)
415
+ end
416
+ =end
417
+
418
+ # "Every 18 months on the 10th thru 15th of the month for 10 occurrences"
419
+ def test_example_19
420
+ start_date = DateTime.parse("US-Eastern:19970910T090000") #Sep 10, 1997
421
+ end_date = start_date + 365 + 365 #Sep 10, 1999
422
+
423
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15")
424
+
425
+ expected = [
426
+ DateTime.parse("US-Eastern:19970910T090000"), #Sep 10, 1997
427
+ DateTime.parse("US-Eastern:19970911T090000"), #Sep 11, 1997
428
+ DateTime.parse("US-Eastern:19970912T090000"), #Sep 12, 1997
429
+ DateTime.parse("US-Eastern:19970913T090000"), #Sep 13, 1997
430
+ DateTime.parse("US-Eastern:19970914T090000"), #Sep 14, 1997
431
+ DateTime.parse("US-Eastern:19970915T090000"), #Sep 15, 1997
432
+ DateTime.parse("US-Eastern:19990310T090000"), #Mar 10, 1999
433
+ DateTime.parse("US-Eastern:19990311T090000"), #Mar 11, 1999
434
+ DateTime.parse("US-Eastern:19990312T090000"), #Mar 12, 1999
435
+ DateTime.parse("US-Eastern:19990313T090000"), #Mar 13, 1999
436
+ ]
437
+
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
441
+ results = te.dates(DateRange.new(start_date, end_date), 10)
442
+ assert_equal(expected, results)
443
+ end
444
+
445
+ # "Every Tuesday, every other month"
446
+ def test_example_20
447
+ start_date = DateTime.parse("US-Eastern:19970902T090000") #Sep 2, 1997
448
+ end_date = start_date + 220 #Oct 4, 1998
449
+
450
+ #rrule = RecurrenceRule.new("FREQ=MONTHLY;INTERVAL=2;BYDAY=TU)
451
+
452
+ expected = [
453
+ DateTime.parse("US-Eastern:19970902T090000"), #Sep 02, 1997
454
+ DateTime.parse("US-Eastern:19970909T090000"), #Sep 09, 1997
455
+ DateTime.parse("US-Eastern:19970916T090000"), #Sep 16, 1997
456
+ DateTime.parse("US-Eastern:19970923T090000"), #Sep 23, 1997
457
+ DateTime.parse("US-Eastern:19970930T090000"), #Sep 30, 1997
458
+ DateTime.parse("US-Eastern:19971104T090000"), #Nov 04, 1997
459
+ DateTime.parse("US-Eastern:19971111T090000"), #Nov 11, 1997
460
+ DateTime.parse("US-Eastern:19971118T090000"), #Nov 18, 1997
461
+ DateTime.parse("US-Eastern:19971125T090000"), #Nov 25, 1997
462
+ DateTime.parse("US-Eastern:19980106T090000"), #Jan 06, 1998
463
+ DateTime.parse("US-Eastern:19980113T090000"), #Jan 13, 1998
464
+ DateTime.parse("US-Eastern:19980120T090000"), #Jan 20, 1998
465
+ 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
471
+ ]
472
+
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)
476
+ results = te.dates(DateRange.new(start_date, end_date))
477
+ assert_equal(expected, results)
478
+ end
479
+
480
+ # "Yearly in June and July for 10 occurrences"
481
+ def test_example_21
482
+ start_date = DateTime.parse("US-Eastern:19970610T090000") #June 10, 1997
483
+ end_date = DateTime.parse("US-Eastern:20020725T090000") #July 25, 2002
484
+
485
+ #rrule = RecurrenceRule.new("FREQ=YEARLY;COUNT=10;BYMONTH=6,7)
486
+
487
+ expected = [
488
+ DateTime.parse("US-Eastern:19970610T090000"), #Jun 10, 1997
489
+ DateTime.parse("US-Eastern:19970710T090000"), #Jul 10, 1997
490
+
491
+ DateTime.parse("US-Eastern:19980610T090000"), #Jun 10, 1998
492
+ DateTime.parse("US-Eastern:19980710T090000"), #Jul 10, 1998
493
+
494
+ DateTime.parse("US-Eastern:19990610T090000"), #Jun 10, 1999
495
+ DateTime.parse("US-Eastern:19990710T090000"), #Jul 10, 1999
496
+
497
+ DateTime.parse("US-Eastern:20000610T090000"), #Jun 10, 2000
498
+ DateTime.parse("US-Eastern:20000710T090000"), #Jul 10, 2000
499
+
500
+ DateTime.parse("US-Eastern:20010610T090000"), #Jun 10, 2001
501
+ DateTime.parse("US-Eastern:20010710T090000"), #Jul 10, 2001
502
+ ]
503
+
504
+ #we have to set the precision for use in EveryTE
505
+ start_date.date_precision = DPrecision::YEAR
506
+ te = (REYear.new(6) | REYear.new(7)) & REMonth.new(start_date.day)
507
+ results = te.dates(DateRange.new(start_date, end_date), 10)
508
+ assert_equal(expected, results)
509
+ end
510
+
511
+ def debug(expected, results)
512
+ puts "expected:"
513
+ expected.each {|date| puts date}
514
+ puts "results:"
515
+ results.each {|date| puts date}
516
+ end
517
+
518
+ #convenience method for creating an array of dates, one per day, from a start to an end date
519
+ def self.get_date_range(start_date, end_date)
520
+ dates = []
521
+ start_date.upto(end_date) {|date| dates << date}
522
+ dates
523
+ end
524
+ end