rrule 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +25 -0
  4. data/.travis.yml +6 -1
  5. data/Gemfile +9 -0
  6. data/Rakefile +9 -3
  7. data/lib/rrule.rb +4 -0
  8. data/lib/rrule/context.rb +5 -3
  9. data/lib/rrule/filters/by_month.rb +2 -0
  10. data/lib/rrule/filters/by_month_day.rb +2 -0
  11. data/lib/rrule/filters/by_week_day.rb +2 -0
  12. data/lib/rrule/filters/by_week_number.rb +2 -0
  13. data/lib/rrule/filters/by_year_day.rb +3 -1
  14. data/lib/rrule/frequencies/daily.rb +2 -0
  15. data/lib/rrule/frequencies/frequency.rb +4 -12
  16. data/lib/rrule/frequencies/monthly.rb +2 -0
  17. data/lib/rrule/frequencies/simple_weekly.rb +6 -6
  18. data/lib/rrule/frequencies/weekly.rb +2 -0
  19. data/lib/rrule/frequencies/yearly.rb +2 -0
  20. data/lib/rrule/generators/all_occurrences.rb +2 -0
  21. data/lib/rrule/generators/by_set_position.rb +2 -0
  22. data/lib/rrule/generators/generator.rb +3 -1
  23. data/lib/rrule/rule.rb +18 -33
  24. data/lib/rrule/version.rb +5 -0
  25. data/lib/rrule/weekday.rb +3 -1
  26. data/rrule.gemspec +16 -10
  27. data/scripts/benchmark.rb +3 -1
  28. metadata +13 -56
  29. data/spec/context_spec.rb +0 -261
  30. data/spec/filters/by_month_day_spec.rb +0 -35
  31. data/spec/filters/by_month_spec.rb +0 -35
  32. data/spec/filters/by_week_day_spec.rb +0 -35
  33. data/spec/filters/by_week_number_spec.rb +0 -41
  34. data/spec/filters/by_year_day_spec.rb +0 -35
  35. data/spec/frequencies/daily_spec.rb +0 -62
  36. data/spec/frequencies/monthly_spec.rb +0 -63
  37. data/spec/frequencies/simple_weekly_spec.rb +0 -32
  38. data/spec/frequencies/weekly_spec.rb +0 -92
  39. data/spec/frequencies/yearly_spec.rb +0 -54
  40. data/spec/generators/all_occurrences_spec.rb +0 -44
  41. data/spec/generators/by_set_position_spec.rb +0 -39
  42. data/spec/generators/generator_spec.rb +0 -110
  43. data/spec/rule_spec.rb +0 -2338
  44. data/spec/spec_helper.rb +0 -23
  45. data/spec/weekday_spec.rb +0 -34
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::ByWeekDay do
4
- let(:context) do
5
- RRule::Context.new(
6
- { freq: 'WEEKLY', count: 4 },
7
- Time.parse('Wed Jan 1 00:00:00 PST 1997'),
8
- 'America/Los_Angeles'
9
- )
10
- end
11
-
12
- subject { described_class.new([RRule::Weekday.parse('TU'), RRule::Weekday.parse('FR')], context).reject?(date.yday - 1) }
13
-
14
- before(:each) { context.rebuild(1997, 1) }
15
-
16
- describe '#reject?' do
17
- context 'for the Friday of the week' do
18
- let(:date) { Date.new(1997, 1, 3) }
19
-
20
- it { is_expected.to be false }
21
- end
22
-
23
- context 'for the Saturday of the week' do
24
- let(:date) { Date.new(1997, 1, 4) }
25
-
26
- it { is_expected.to be true }
27
- end
28
-
29
- context 'for the Tuesday of the next week' do
30
- let(:date) { Date.new(1997, 1, 7) }
31
-
32
- it { is_expected.to be false }
33
- end
34
- end
35
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::ByWeekNumber do
4
- let(:context) do
5
- RRule::Context.new(
6
- { freq: 'YEARLY', wkst: 1 },
7
- Time.parse('Wed Jan 1 00:00:00 PST 1997'),
8
- 'America/Los_Angeles'
9
- )
10
- end
11
-
12
- subject { described_class.new([2, -3], context).reject?(date.yday - 1) }
13
-
14
- before(:each) { context.rebuild(1997, 1) }
15
-
16
- describe '#reject?' do
17
- context 'for the first week of the year' do
18
- let(:date) { Date.new(1997, 1, 2) }
19
-
20
- it { is_expected.to be true }
21
- end
22
-
23
- context 'for the second week of the year' do
24
- let(:date) { Date.new(1997, 1, 8) }
25
-
26
- it { is_expected.to be false }
27
- end
28
-
29
- context 'for the fourth week of the year' do
30
- let(:date) { Date.new(1997, 1, 22) }
31
-
32
- it { is_expected.to be true }
33
- end
34
-
35
- context 'for the third-to-last week of the year' do
36
- let(:date) { Date.new(1997, 12, 9) }
37
-
38
- it { is_expected.to be false }
39
- end
40
- end
41
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::ByYearDay do
4
- let(:context) do
5
- RRule::Context.new(
6
- { freq: 'YEARLY', count: 4 },
7
- Time.parse('Wed Jan 1 00:00:00 PST 1997'),
8
- 'America/Los_Angeles'
9
- )
10
- end
11
-
12
- subject { described_class.new([45, -45], context).reject?(date.yday - 1) }
13
-
14
- before(:each) { context.rebuild(1997, 1) }
15
-
16
- describe '#reject?' do
17
- context 'for the 45th day of the year' do
18
- let(:date) { Date.new(1997, 2, 14) }
19
-
20
- it { is_expected.to be false }
21
- end
22
-
23
- context 'for the 60th day of the year' do
24
- let(:date) { Date.new(1997, 3, 1) }
25
-
26
- it { is_expected.to be true }
27
- end
28
-
29
- context 'for the 45th-from-last day of the month' do
30
- let(:date) { Date.new(1997, 11, 17) }
31
-
32
- it { is_expected.to be false }
33
- end
34
- end
35
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::Daily do
4
- let(:interval) { 1 }
5
- let(:context) do
6
- RRule::Context.new(
7
- { interval: interval },
8
- date,
9
- 'America/Los_Angeles'
10
- )
11
- end
12
- let(:filters) { [] }
13
- let(:generator) { RRule::AllOccurrences.new(context) }
14
- let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] }
15
-
16
- before { context.rebuild(date.year, date.month) }
17
-
18
- describe '#next_occurrences' do
19
- subject(:frequency) { described_class.new(context, filters, generator, timeset) }
20
-
21
- context 'with an interval of one' do
22
- let(:date) { Time.zone.local(1997, 1, 1) }
23
-
24
- it 'returns sequential days' do
25
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
26
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 2)]
27
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 3)]
28
- end
29
- end
30
-
31
- context 'with an interval of two' do
32
- let(:interval) { 2 }
33
- let(:date) { Time.zone.local(1997, 1, 1) }
34
-
35
- it 'returns every other day' do
36
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
37
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 3)]
38
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 5)]
39
- end
40
- end
41
-
42
- context 'on the last day of February' do
43
- let(:date) { Time.zone.local(1997, 2, 28) }
44
-
45
- it 'goes into the next month' do
46
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 28)]
47
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 1)]
48
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 2)]
49
- end
50
- end
51
-
52
- context 'on the last day of the year' do
53
- let(:date) { Time.zone.local(1997, 12, 31) }
54
-
55
- it 'goes into the next year' do
56
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 12, 31)]
57
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 1)]
58
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 2)]
59
- end
60
- end
61
- end
62
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::Monthly do
4
- let(:interval) { 1 }
5
- let(:context) do
6
- RRule::Context.new(
7
- { interval: interval },
8
- date,
9
- 'America/Los_Angeles'
10
- )
11
- end
12
- let(:filters) { [RRule::ByMonthDay.new([date.day], context)] }
13
- let(:generator) { RRule::AllOccurrences.new(context) }
14
- let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] }
15
-
16
- before { context.rebuild(date.year, date.month) }
17
-
18
- describe '#next_occurrences' do
19
- subject(:frequency) { described_class.new(context, filters, generator, timeset) }
20
-
21
- context 'with an interval of one' do
22
- let(:date) { Time.zone.local(1997, 1, 1) }
23
-
24
- it 'returns sequential months' do
25
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
26
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 1)]
27
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 1)]
28
- end
29
- end
30
-
31
- context 'with an interval of two' do
32
- let(:interval) { 2 }
33
- let(:date) { Time.zone.local(1997, 1, 1) }
34
-
35
- it 'returns every other month' do
36
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
37
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 1)]
38
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 5, 1)]
39
- end
40
- end
41
-
42
- context 'on the last day of February' do
43
- let(:date) { Time.zone.local(1997, 2, 28) }
44
-
45
- it 'returns the next three months' do
46
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 28)]
47
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 28)]
48
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 4, 28)]
49
- end
50
- end
51
-
52
- context 'on the last day of the year' do
53
- let(:date) { Time.zone.local(1997, 12, 31) }
54
-
55
- it 'returns empty arrays for periods with no matching occurrences' do
56
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 12, 31)]
57
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 31)]
58
- expect(frequency.next_occurrences).to eql []
59
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 3, 31)]
60
- end
61
- end
62
- end
63
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::SimpleWeekly do
4
- let(:context) { RRule::Context.new({ interval: interval }, date, 'America/Los_Angeles') }
5
- let(:frequency) { described_class.new(context, nil, generator, timeset) }
6
- let(:generator) { RRule::AllOccurrences.new(context) }
7
- let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] }
8
-
9
- describe '#next_occurrences' do
10
- let(:date) { Time.zone.local(1997, 1, 1) }
11
-
12
- context 'with an interval of 1' do
13
- let(:interval) { 1 }
14
-
15
- it 'returns occurrences every week' do
16
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
17
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 8)]
18
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 15)]
19
- end
20
- end
21
-
22
- context 'with an interval of 2' do
23
- let(:interval) { 2 }
24
-
25
- it 'returns occurrences every other week' do
26
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
27
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 15)]
28
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 29)]
29
- end
30
- end
31
- end
32
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::Weekly do
4
- let(:interval) { 1 }
5
- let(:context) do
6
- RRule::Context.new(
7
- { interval: interval, wkst: 1 },
8
- date,
9
- 'America/Los_Angeles'
10
- )
11
- end
12
- let(:filters) { [RRule::ByWeekDay.new([RRule::Weekday.new(date.wday)], context)] }
13
- let(:generator) { RRule::AllOccurrences.new(context) }
14
- let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] }
15
-
16
- before { context.rebuild(date.year, date.month) }
17
-
18
- describe '#next_occurrences' do
19
- subject(:frequency) { described_class.new(context, filters, generator, timeset) }
20
-
21
- context 'with an interval of one' do
22
- let(:date) { Time.zone.local(1997, 1, 1) }
23
-
24
- it 'returns sequential weeks' do
25
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
26
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 8)]
27
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 15)]
28
- end
29
- end
30
-
31
- context 'with an interval of two' do
32
- let(:interval) { 2 }
33
- let(:date) { Time.zone.local(1997, 1, 1) }
34
-
35
- it 'returns every other week' do
36
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
37
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 15)]
38
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 29)]
39
- end
40
- end
41
-
42
- context 'on the first day of the year with five days left in the week' do
43
- let(:date) { Time.zone.local(1997, 1, 1) }
44
-
45
- it 'returns the next three weeks' do
46
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
47
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 8)]
48
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 15)]
49
- end
50
- end
51
-
52
- context 'on a day in the first month with two days left in the week' do
53
- let(:date) { Time.zone.local(1997, 1, 25) }
54
-
55
- it 'returns the next three weeks' do
56
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 25)]
57
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 1)]
58
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 8)]
59
- end
60
- end
61
-
62
- context 'on a day in the next month with six days left in the week' do
63
- let(:date) { Time.zone.local(1997, 2, 25) }
64
-
65
- it 'returns the next three weeks' do
66
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 25)]
67
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 4)]
68
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 11)]
69
- end
70
- end
71
-
72
- context 'on the last day of February' do
73
- let(:date) { Time.zone.local(1997, 2, 28) }
74
-
75
- it 'returns the next three weeks' do
76
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 2, 28)]
77
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 7)]
78
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 3, 14)]
79
- end
80
- end
81
-
82
- context 'on the last day of the year' do
83
- let(:date) { Time.zone.local(1997, 12, 31) }
84
-
85
- it 'returns the next three weeks' do
86
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 12, 31)]
87
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 7)]
88
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 14)]
89
- end
90
- end
91
- end
92
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::Yearly do
4
- let(:interval) { 1 }
5
- let(:context) do
6
- RRule::Context.new(
7
- { interval: interval, wkst: 1 },
8
- date,
9
- 'America/Los_Angeles'
10
- )
11
- end
12
- let(:filters) { [RRule::ByMonth.new([date.month], context), RRule::ByMonthDay.new([date.day], context)] }
13
- let(:generator) { RRule::AllOccurrences.new(context) }
14
- let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] }
15
-
16
- before(:each) { context.rebuild(date.year, date.month) }
17
-
18
- describe '#next_occurrences' do
19
- subject(:frequency) { described_class.new(context, filters, generator, timeset) }
20
-
21
- context 'on the first day of the year' do
22
- let(:date) { Time.zone.local(1997, 1, 1) }
23
-
24
- it 'returns the next three years' do
25
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
26
- expect(frequency.next_occurrences).to eql [Time.zone.local(1998, 1, 1)]
27
- expect(frequency.next_occurrences).to eql [Time.zone.local(1999, 1, 1)]
28
- end
29
- end
30
-
31
- context 'on the last day of February in a leap year' do
32
- let(:date) { Time.zone.local(2000, 2, 29) }
33
-
34
- it 'skips non-leap years' do
35
- expect(frequency.next_occurrences).to eql [Time.zone.local(2000, 2, 29)]
36
- expect(frequency.next_occurrences).to eql []
37
- expect(frequency.next_occurrences).to eql []
38
- expect(frequency.next_occurrences).to eql []
39
- expect(frequency.next_occurrences).to eql [Time.zone.local(2004, 2, 29)]
40
- end
41
- end
42
-
43
- context 'with an interval of two' do
44
- let(:interval) { 2 }
45
- let(:date) { Time.zone.local(1997, 1, 1) }
46
-
47
- it 'returns every other year' do
48
- expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1)]
49
- expect(frequency.next_occurrences).to eql [Time.zone.local(1999, 1, 1)]
50
- expect(frequency.next_occurrences).to eql [Time.zone.local(2001, 1, 1)]
51
- end
52
- end
53
- end
54
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RRule::AllOccurrences do
4
- let(:context) do
5
- RRule::Context.new(
6
- { interval: 1, wkst: 1 },
7
- Time.parse('Wed Jan 1 00:00:00 PST 1997'),
8
- 'America/Los_Angeles'
9
- )
10
- end
11
-
12
- around(:each) do |example|
13
- Time.use_zone('America/Los_Angeles') do
14
- example.run
15
- end
16
- end
17
-
18
- before(:each) { context.rebuild(1997, 1) }
19
-
20
- describe '#combine_dates_and_times' do
21
- subject { described_class.new(context).combine_dates_and_times(dates, times)}
22
-
23
- context 'with a single date and time' do
24
- let(:dates) { [0] }
25
- let(:times) { [{ hour: 12, minute: 30, second: 15 }] }
26
-
27
- it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997')] }
28
- end
29
-
30
- context 'with multiple dates and a single time' do
31
- let(:dates) { [0, 15] }
32
- let(:times) { [{ hour: 12, minute: 30, second: 15 }] }
33
-
34
- it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Thu Jan 16 12:30:15 PST 1997')] }
35
- end
36
-
37
- context 'with a single date and multiple times' do
38
- let(:dates) { [0] }
39
- let(:times) { [{ hour: 12, minute: 30, second: 15 }, { hour: 18, minute: 45, second: 20 }] }
40
-
41
- it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Wed Jan 1 18:45:20 PST 1997')] }
42
- end
43
- end
44
- end