rrule 0.4.1 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +28 -0
- data/.travis.yml +27 -1
- data/Appraisals +27 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +9 -0
- data/Rakefile +9 -3
- data/gemfiles/activesupport_2.3_LTS.gemfile +16 -0
- data/gemfiles/activesupport_3.gemfile +16 -0
- data/gemfiles/activesupport_4.gemfile +15 -0
- data/gemfiles/activesupport_5.gemfile +15 -0
- data/gemfiles/activesupport_6.gemfile +15 -0
- data/gemfiles/activesupport_7.gemfile +15 -0
- data/lib/rrule/context.rb +5 -3
- data/lib/rrule/filters/by_month.rb +2 -0
- data/lib/rrule/filters/by_month_day.rb +2 -0
- data/lib/rrule/filters/by_week_day.rb +5 -3
- data/lib/rrule/filters/by_week_number.rb +2 -0
- data/lib/rrule/filters/by_year_day.rb +3 -1
- data/lib/rrule/frequencies/daily.rb +2 -0
- data/lib/rrule/frequencies/frequency.rb +4 -12
- data/lib/rrule/frequencies/monthly.rb +2 -0
- data/lib/rrule/frequencies/simple_weekly.rb +6 -6
- data/lib/rrule/frequencies/weekly.rb +2 -0
- data/lib/rrule/frequencies/yearly.rb +2 -0
- data/lib/rrule/generators/all_occurrences.rb +2 -0
- data/lib/rrule/generators/by_set_position.rb +2 -0
- data/lib/rrule/generators/generator.rb +5 -1
- data/lib/rrule/rule.rb +29 -37
- data/lib/rrule/version.rb +5 -0
- data/lib/rrule/weekday.rb +4 -2
- data/lib/rrule.rb +4 -0
- data/rrule.gemspec +18 -11
- data/scripts/benchmark.rb +3 -1
- metadata +30 -52
- data/spec/context_spec.rb +0 -261
- data/spec/filters/by_month_day_spec.rb +0 -35
- data/spec/filters/by_month_spec.rb +0 -35
- data/spec/filters/by_week_day_spec.rb +0 -35
- data/spec/filters/by_week_number_spec.rb +0 -41
- data/spec/filters/by_year_day_spec.rb +0 -35
- data/spec/frequencies/daily_spec.rb +0 -62
- data/spec/frequencies/monthly_spec.rb +0 -63
- data/spec/frequencies/simple_weekly_spec.rb +0 -32
- data/spec/frequencies/weekly_spec.rb +0 -92
- data/spec/frequencies/yearly_spec.rb +0 -54
- data/spec/generators/all_occurrences_spec.rb +0 -44
- data/spec/generators/by_set_position_spec.rb +0 -39
- data/spec/generators/generator_spec.rb +0 -110
- data/spec/rule_spec.rb +0 -2338
- data/spec/spec_helper.rb +0 -23
- data/spec/weekday_spec.rb +0 -34
@@ -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
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RRule::BySetPosition 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(positions, context).combine_dates_and_times(dates, times)}
|
22
|
-
|
23
|
-
context 'with a single set position' do
|
24
|
-
let(:positions) { [0] }
|
25
|
-
let(:dates) { [0, 1, 2, 3, 4] }
|
26
|
-
let(:times) { [{ hour: 12, minute: 30, second: 15 }] }
|
27
|
-
|
28
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997')] }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with multiple set positions' do
|
32
|
-
let(:positions) { [1, 3] }
|
33
|
-
let(:dates) { [0, 1, 2, 3, 4] }
|
34
|
-
let(:times) { [{ hour: 12, minute: 30, second: 15 }] }
|
35
|
-
|
36
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Fri Jan 3 12:30:15 PST 1997')] }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RRule::Generator 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 '#process_timeset' do
|
21
|
-
describe "single timeset" do
|
22
|
-
subject { described_class.new(context).process_timeset(date, timeset)}
|
23
|
-
|
24
|
-
context 'with a timeset with only 1 set' do
|
25
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
26
|
-
let(:timeset) { [{ hour: 12, minute: 30, second: 15 }] }
|
27
|
-
|
28
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997')] }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with multiple hours in the timeset' do
|
32
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
33
|
-
let(:timeset) { [{ hour: [12, 15], minute: 30, second: 15 }] }
|
34
|
-
|
35
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Wed Jan 1 15:30:15 PST 1997')] }
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'with multiple minutes in the timeset' do
|
39
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
40
|
-
let(:timeset) { [{ hour: [12], minute: [15, 30], second: 15 }] }
|
41
|
-
|
42
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:15:15 PST 1997'), Time.parse('Wed Jan 1 12:30:15 PST 1997')] }
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'with multiple seconds in the timeset' do
|
46
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
47
|
-
let(:timeset) { [{ hour: [12], minute: [30], second: [15, 59] }] }
|
48
|
-
|
49
|
-
it { is_expected.to match_array [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Wed Jan 1 12:30:59 PST 1997')] }
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with multiple hours, minutes, and seconds in the timeset' do
|
53
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
54
|
-
let(:timeset) { [{ hour: [12, 20], minute: [30, 55], second: [15, 59] }] }
|
55
|
-
|
56
|
-
it { is_expected.to eq [
|
57
|
-
Time.parse('Wed Jan 1 12:30:15 PST 1997'),
|
58
|
-
Time.parse('Wed Jan 1 12:30:59 PST 1997'),
|
59
|
-
Time.parse('Wed Jan 1 12:55:15 PST 1997'),
|
60
|
-
Time.parse('Wed Jan 1 12:55:59 PST 1997'),
|
61
|
-
Time.parse('Wed Jan 1 20:30:15 PST 1997'),
|
62
|
-
Time.parse('Wed Jan 1 20:30:59 PST 1997'),
|
63
|
-
Time.parse('Wed Jan 1 20:55:15 PST 1997'),
|
64
|
-
Time.parse('Wed Jan 1 20:55:59 PST 1997'),
|
65
|
-
] }
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'with multiple hours, minutes, and seconds in the timeset, unsorted' do
|
69
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
70
|
-
let(:timeset) { [{ hour: [20, 12], minute: [55, 30], second: [59, 15] }] }
|
71
|
-
|
72
|
-
it { is_expected.to eq [
|
73
|
-
Time.parse('Wed Jan 1 12:30:15 PST 1997'),
|
74
|
-
Time.parse('Wed Jan 1 12:30:59 PST 1997'),
|
75
|
-
Time.parse('Wed Jan 1 12:55:15 PST 1997'),
|
76
|
-
Time.parse('Wed Jan 1 12:55:59 PST 1997'),
|
77
|
-
Time.parse('Wed Jan 1 20:30:15 PST 1997'),
|
78
|
-
Time.parse('Wed Jan 1 20:30:59 PST 1997'),
|
79
|
-
Time.parse('Wed Jan 1 20:55:15 PST 1997'),
|
80
|
-
Time.parse('Wed Jan 1 20:55:59 PST 1997'),
|
81
|
-
] }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "multiple timesets" do
|
87
|
-
subject { described_class.new(context).process_timeset(date, timeset)}
|
88
|
-
|
89
|
-
context 'with multiple timsets' do
|
90
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
91
|
-
let(:timeset) { [{ hour: 12, minute: 30, second: 15 }, { hour: 18, minute: 45, second: 20 }] }
|
92
|
-
|
93
|
-
it { is_expected.to eq [Time.parse('Wed Jan 1 12:30:15 PST 1997'), Time.parse('Wed Jan 1 18:45:20 PST 1997')] }
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'with multiple timsets with multiple hour sets' do
|
97
|
-
let(:date) { Time.parse('Wed Jan 1 00:11:22 PST 1997') }
|
98
|
-
let(:timeset) { [{ hour: [12, 20], minute: 30, second: [15, 45] }, { hour: 18, minute: [22, 45], second: 20 }] }
|
99
|
-
|
100
|
-
it { is_expected.to eq [
|
101
|
-
Time.parse('Wed Jan 1 12:30:15 PST 1997'),
|
102
|
-
Time.parse('Wed Jan 1 12:30:45 PST 1997'),
|
103
|
-
Time.parse('Wed Jan 1 20:30:15 PST 1997'),
|
104
|
-
Time.parse('Wed Jan 1 20:30:45 PST 1997'),
|
105
|
-
Time.parse('Wed Jan 1 18:22:20 PST 1997'),
|
106
|
-
Time.parse('Wed Jan 1 18:45:20 PST 1997')
|
107
|
-
] }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|