timely 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/timely/version.rb +1 -1
- data/timely.gemspec +6 -10
- metadata +22 -103
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/release.yml +0 -59
- data/.github/workflows/ruby.yml +0 -19
- data/.gitignore +0 -6
- data/.rspec +0 -2
- data/.rubocop.yml +0 -28
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/LICENSE +0 -21
- data/Rakefile +0 -14
- data/gemfiles/rails60.gemfile +0 -8
- data/gemfiles/rails61.gemfile +0 -8
- data/rails/init.rb +0 -3
- data/spec/calendar_tag_spec.rb +0 -30
- data/spec/date_chooser_spec.rb +0 -115
- data/spec/date_group_spec.rb +0 -124
- data/spec/date_range_spec.rb +0 -89
- data/spec/date_spec.rb +0 -78
- data/spec/extensions_spec.rb +0 -28
- data/spec/rails/date_spec.rb +0 -18
- data/spec/rails/date_time_spec.rb +0 -28
- data/spec/rails/period_spec.rb +0 -19
- data/spec/rails/time_spec.rb +0 -73
- data/spec/schema.rb +0 -17
- data/spec/season_spec.rb +0 -62
- data/spec/spec_helper.rb +0 -46
- data/spec/support/coverage_loader.rb +0 -6
- data/spec/temporal_patterns_spec.rb +0 -28
- data/spec/time_since_spec.rb +0 -26
- data/spec/time_spec.rb +0 -70
- data/spec/trackable_date_set_spec.rb +0 -82
- data/spec/week_days_spec.rb +0 -76
data/spec/date_group_spec.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Timely::DateGroup do
|
6
|
-
before do
|
7
|
-
@date_group = Timely::DateGroup.new(
|
8
|
-
start_date: '2000-01-01', end_date: '2000-01-03', weekdays: %w[1 1 1 1 1 1 1]
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'is not valid to set nil weekdays' do
|
13
|
-
@date_group.weekdays_bit_array = nil
|
14
|
-
expect(@date_group).not_to be_valid
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should detect overlaps' do
|
18
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-01'.to_date))).to be true
|
19
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-06'.to_date))).to be true
|
20
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2001-01-01'.to_date, '2001-01-01'.to_date))).to be false
|
21
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('1999-12-29'.to_date, '2000-01-05'.to_date))).to be true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should detect overlaps when certain weekdays aren't selected" do
|
25
|
-
@date_group = Timely::DateGroup.create!(
|
26
|
-
start_date: '2012-01-01', end_date: '2012-01-07', weekdays: %w[1 0 1 0 1 0 1]
|
27
|
-
)
|
28
|
-
# Note: 2012-01-1 is a Sunday
|
29
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-01'.to_date))).to be true
|
30
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-02'.to_date, '2012-01-02'.to_date))).to be false
|
31
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-03'.to_date, '2012-01-03'.to_date))).to be true
|
32
|
-
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-03'.to_date))).to be true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
RSpec.describe Timely::DateGroup, 'Timely::DateGroup.applying_for_duration' do
|
37
|
-
let!(:date_group_a) { Timely::DateGroup.create!(
|
38
|
-
start_date: '2020-01-01', end_date: '2020-04-04', weekdays: %w[1 1 1 1 1 1 1]
|
39
|
-
) }
|
40
|
-
|
41
|
-
let!(:date_group_b) { Timely::DateGroup.create!(
|
42
|
-
start_date: '2020-04-02', end_date: '2020-04-09', weekdays: %w[1 1 1 1 1 1 1]
|
43
|
-
) }
|
44
|
-
|
45
|
-
subject {
|
46
|
-
Timely::DateGroup.applying_for_duration(Timely::DateRange.new(start_date, end_date)).to_a
|
47
|
-
}
|
48
|
-
|
49
|
-
context 'intersecting dates (inside first)' do
|
50
|
-
let(:start_date) { '2020-03-29'.to_date }
|
51
|
-
let(:end_date) { '2020-04-13'.to_date }
|
52
|
-
it { is_expected.to eq([date_group_a, date_group_b]) }
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'intersecting dates full range' do
|
56
|
-
let(:start_date) { '2020-01-01'.to_date }
|
57
|
-
let(:end_date) { '2020-04-09'.to_date }
|
58
|
-
it { is_expected.to eq([date_group_a, date_group_b]) }
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'touching end of range' do
|
62
|
-
let(:start_date) { '2020-04-09'.to_date }
|
63
|
-
let(:end_date) { '2020-04-09'.to_date }
|
64
|
-
it { is_expected.to eq([date_group_b]) }
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'touching start of range' do
|
68
|
-
let(:start_date) { '2020-04-01'.to_date }
|
69
|
-
let(:end_date) { '2020-04-01'.to_date }
|
70
|
-
it { is_expected.to eq([date_group_a]) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
RSpec.describe Timely::DateGroup, 'without weekdays' do
|
75
|
-
subject { Timely::DateGroup.new(start_date: Date.current, end_date: Date.current) }
|
76
|
-
it { is_expected.to be_valid }
|
77
|
-
end
|
78
|
-
|
79
|
-
RSpec.describe 'Timely::DateGroup.for_any_weekdays' do
|
80
|
-
let(:date_range) { ('2019-10-17'.to_date)..('2019-10-18'.to_date) }
|
81
|
-
let(:weekdays_int) { Timely::WeekDays.from_range(date_range).weekdays_int }
|
82
|
-
|
83
|
-
let!(:date_groups) { [
|
84
|
-
Timely::DateGroup.create(start_date: date_range.first, end_date: date_range.last, weekdays: { thu: true }),
|
85
|
-
Timely::DateGroup.create(start_date: date_range.first, end_date: date_range.last, weekdays: { mon: true }),
|
86
|
-
] }
|
87
|
-
|
88
|
-
RSpec.shared_examples 'finds expected date groups' do
|
89
|
-
it 'finds expected date groups' do
|
90
|
-
includes_date_groups.each do |date_group|
|
91
|
-
expect(date_group.includes_date?(date_range.first)).to eq(true)
|
92
|
-
end
|
93
|
-
expected_groups.each do |date_group|
|
94
|
-
expect(scoped_result).to include(date_group)
|
95
|
-
end
|
96
|
-
absent_groups.each do |date_group|
|
97
|
-
expect(date_group.includes_date?(date_range.first)).to eq(false)
|
98
|
-
expect(scoped_result).not_to include(date_group)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context '#within_range' do
|
104
|
-
let(:scoped_result) { Timely::DateGroup.within_range(date_range).to_a }
|
105
|
-
let(:expected_groups) { [date_groups[0], date_groups[1]] }
|
106
|
-
let(:absent_groups) { [] }
|
107
|
-
let(:includes_date_groups) { [] }
|
108
|
-
it_behaves_like 'finds expected date groups'
|
109
|
-
end
|
110
|
-
|
111
|
-
let(:includes_date_groups) { expected_groups }
|
112
|
-
let(:expected_groups) { [date_groups[0]] }
|
113
|
-
let(:absent_groups) { [date_groups[1]] }
|
114
|
-
|
115
|
-
context '#for_any_weekdays' do
|
116
|
-
let(:scoped_result) { Timely::DateGroup.for_any_weekdays(weekdays_int).to_a }
|
117
|
-
it_behaves_like 'finds expected date groups'
|
118
|
-
end
|
119
|
-
|
120
|
-
context '#applying_for_duration' do
|
121
|
-
let(:scoped_result) { Timely::DateGroup.applying_for_duration(date_range).to_a }
|
122
|
-
it_behaves_like 'finds expected date groups'
|
123
|
-
end
|
124
|
-
end
|
data/spec/date_range_spec.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Timely::DateRange do
|
6
|
-
it 'should allow initialization with two dates' do
|
7
|
-
expect { @date_range = Timely::DateRange.new(Date.today, Date.today + 3) }.to_not raise_error
|
8
|
-
expect(@date_range.start_date).to eq Date.today
|
9
|
-
expect(@date_range.end_date).to eq Date.today + 3
|
10
|
-
expect(@date_range.number_of_nights).to eq 4
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should allow initialization with one date' do
|
14
|
-
expect { @date_range = Timely::DateRange.new(Date.today) }.to_not raise_error
|
15
|
-
expect(@date_range.start_date).to eq Date.today
|
16
|
-
expect(@date_range.end_date).to eq Date.today
|
17
|
-
expect(@date_range.number_of_nights).to eq 1
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should allow initialization with a range' do
|
21
|
-
expect { @date_range = Timely::DateRange.new(Date.today..Date.today + 3) }.to_not raise_error
|
22
|
-
expect(@date_range.start_date).to eq Date.today
|
23
|
-
expect(@date_range.end_date).to eq Date.today + 3
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should print a readable version of time between two dates' do
|
27
|
-
expect(Timely::DateRange.new('2000-01-04'.to_date, '2000-01-04'.to_date).to_s).to eq '2000-01-04'
|
28
|
-
expect(Timely::DateRange.new('2000-01-04'.to_date, '2000-01-06'.to_date).to_s).to eq '2000-01-04 to 2000-01-06 (inclusive)'
|
29
|
-
expect(Timely::DateRange.new('2000-01-01'.to_date, '2000-05-31'.to_date).to_s).to eq 'Jan 2000 to May 2000'
|
30
|
-
expect(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-31'.to_date).to_s).to eq 'Jan 2000'
|
31
|
-
expect(Timely::DateRange.new('2000-01-01'.to_date, '2001-01-31'.to_date).to_s).to eq 'Jan 2000 to Jan 2001'
|
32
|
-
Date::DATE_FORMATS[:short] = '%Y-%m-%d'
|
33
|
-
expect(Timely::DateRange.to_s('2000-01-01'.to_date, nil)).to eq 'on or after 2000-01-01'
|
34
|
-
expect(Timely::DateRange.to_s(nil, '2000-01-31'.to_date)).to eq 'on or before 2000-01-31'
|
35
|
-
expect(Timely::DateRange.to_s(nil, nil)).to eq 'no date range'
|
36
|
-
end
|
37
|
-
|
38
|
-
let(:fourth) { '2000-01-04'.to_date }
|
39
|
-
let(:fifth) { '2000-01-05'.to_date }
|
40
|
-
let(:sixth) { '2000-01-06'.to_date }
|
41
|
-
|
42
|
-
it 'should print a readable version of time between two times' do
|
43
|
-
expect(Timely::DateRange.to_s(fourth.at(9, 30), sixth.at(4, 20)))
|
44
|
-
.to eq '2000-01-04 09:30 to 2000-01-06 04:20'
|
45
|
-
expect(Timely::DateRange.to_s(fourth.at(9, 30)))
|
46
|
-
.to eq 'on or after 2000-01-04 09:30'
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should handle params' do
|
50
|
-
today = Timely::DateRange.from_params('2000-01-04')
|
51
|
-
expect(today.first).to eq '2000-01-04'.to_date
|
52
|
-
expect(today.last).to eq '2000-01-04'.to_date
|
53
|
-
|
54
|
-
today = Timely::DateRange.from_params('2000-01-04', '2')
|
55
|
-
expect(today.first).to eq '2000-01-04'.to_date
|
56
|
-
expect(today.last).to eq '2000-01-05'.to_date
|
57
|
-
|
58
|
-
today = Timely::DateRange.from_params('2000-01-04', 2)
|
59
|
-
expect(today.first).to eq '2000-01-04'.to_date
|
60
|
-
expect(today.last).to eq '2000-01-05'.to_date
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should correctly find the interesection between two date ranges' do
|
64
|
-
@date_range = Timely::DateRange.new('2000-01-03'.to_date, '2000-01-06'.to_date)
|
65
|
-
{
|
66
|
-
['2000-01-04'.to_date, '2000-01-07'.to_date] => '2000-01-04'.to_date..'2000-01-06'.to_date,
|
67
|
-
['2000-01-01'.to_date, '2000-01-02'.to_date] => [],
|
68
|
-
['2000-01-01'.to_date, '2000-01-03'.to_date] => '2000-01-03'.to_date..'2000-01-03'.to_date,
|
69
|
-
['2000-01-06'.to_date, '2000-01-07'.to_date] => '2000-01-06'.to_date..'2000-01-06'.to_date,
|
70
|
-
['2000-01-06'.to_date, '2000-01-07'.to_date] => '2000-01-06'.to_date..'2000-01-06'.to_date,
|
71
|
-
['2000-01-04'.to_date, '2000-01-05'.to_date] => '2000-01-04'.to_date..'2000-01-05'.to_date,
|
72
|
-
['2000-01-05'.to_date, '2000-01-05'.to_date] => '2000-01-05'.to_date..'2000-01-05'.to_date
|
73
|
-
}.each do |args, result|
|
74
|
-
tdr = Timely::DateRange.new(*args)
|
75
|
-
expect(@date_range.intersecting_dates(tdr)).to eq(result)
|
76
|
-
end
|
77
|
-
|
78
|
-
@date_range = Timely::DateRange.new('2000-01-03'.to_date, '2000-01-03'.to_date)
|
79
|
-
{
|
80
|
-
['2000-01-04'.to_date, '2000-01-07'.to_date] => [],
|
81
|
-
['2000-01-01'.to_date, '2000-01-03'.to_date] => '2000-01-03'.to_date..'2000-01-03'.to_date,
|
82
|
-
['2000-01-03'.to_date, '2000-01-05'.to_date] => '2000-01-03'.to_date..'2000-01-03'.to_date,
|
83
|
-
['2000-01-02'.to_date, '2000-01-04'.to_date] => '2000-01-03'.to_date..'2000-01-03'.to_date
|
84
|
-
}.each do |args, result|
|
85
|
-
tdr = Timely::DateRange.new(*args)
|
86
|
-
expect(@date_range.intersecting_dates(tdr)).to eq(result)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/spec/date_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Date do
|
6
|
-
it 'should determine if date between' do
|
7
|
-
expect(Date.today.between?(nil, nil)).to be true
|
8
|
-
expect(Date.today.between?(Date.today - 1, Date.today - 1)).to be false
|
9
|
-
expect(Date.today.between?(Date.today - 1, nil)).to be true
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Date do
|
14
|
-
before :each do
|
15
|
-
@date = Date.today - 5
|
16
|
-
|
17
|
-
@hour = 1
|
18
|
-
@minute = 2
|
19
|
-
@second = 3
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should give a time on that date' do
|
23
|
-
expect(@date).to respond_to(:at_time)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'giving a time on that date' do
|
27
|
-
it 'should accept hour, minute, and second' do
|
28
|
-
expect { @date.at_time(@hour, @minute, @second) }.to_not raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should accept hour and minute' do
|
32
|
-
expect { @date.at_time(@hour, @minute) }.to_not raise_error
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should accept hour' do
|
36
|
-
expect { @date.at_time(@hour) }.to_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should accept no arguments' do
|
40
|
-
expect { @date.at_time }.to_not raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should return a time for the given hour, minute, and second if all three are specified' do
|
44
|
-
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, @second)
|
45
|
-
expect(@date.at_time(@hour, @minute, @second)).to eq expected
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should default second to 0 if unspecified' do
|
49
|
-
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, 0)
|
50
|
-
expect(@date.at_time(@hour, @minute)).to eq expected
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should default minute to 0 if unspecified' do
|
54
|
-
expected = Time.local(@date.year, @date.month, @date.day, @hour, 0, 0)
|
55
|
-
expect(@date.at_time(@hour)).to eq expected
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should default hour to 0 if unspecified' do
|
59
|
-
expected = Time.local(@date.year, @date.month, @date.day, 0, 0, 0)
|
60
|
-
expect(@date.at_time).to eq expected
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should accept a time' do
|
64
|
-
expect { @date.at_time(Time.now) }.to_not raise_error
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should return the passed-in time on the date' do
|
68
|
-
@time = Time.now - 12_345
|
69
|
-
expected = Time.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
|
70
|
-
expect(@date.at_time(@time)).to eq expected
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should provide 'at' as an alias" do
|
75
|
-
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, @second)
|
76
|
-
expect(@date.at(@hour, @minute, @second)).to eq expected
|
77
|
-
end
|
78
|
-
end
|
data/spec/extensions_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'timely/rails/extensions'
|
5
|
-
|
6
|
-
describe Timely::Extensions do
|
7
|
-
before do
|
8
|
-
class TimelyExtensionsTestSeasonal < ActiveRecord::Base
|
9
|
-
self.table_name = 'seasonals'
|
10
|
-
acts_as_seasonal
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
after { Object.send(:remove_const, 'TimelyExtensionsTestSeasonal') }
|
15
|
-
|
16
|
-
it 'should cache boundary start' do
|
17
|
-
season = Timely::Season.new
|
18
|
-
season.date_groups.build(start_date: Date.current, end_date: Date.current + 2)
|
19
|
-
season.date_groups.build(start_date: Date.current - 1, end_date: Date.current + 1)
|
20
|
-
season.save!
|
21
|
-
|
22
|
-
o = TimelyExtensionsTestSeasonal.new
|
23
|
-
o.season = season
|
24
|
-
o.save!
|
25
|
-
expect(o.boundary_start).to eq Date.current - 1
|
26
|
-
expect(o.boundary_end).to eq Date.current + 2
|
27
|
-
end
|
28
|
-
end
|
data/spec/rails/date_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Date do
|
6
|
-
let(:date) { Date.parse('2010-01-01') }
|
7
|
-
|
8
|
-
before { Time.zone = ActiveSupport::TimeZone['Adelaide'] }
|
9
|
-
|
10
|
-
subject(:converted) { date.to_time_in_time_zone }
|
11
|
-
|
12
|
-
it 'should convert to time in time zone' do
|
13
|
-
expect(converted.year).to eq date.year
|
14
|
-
expect(converted.month).to eq date.month
|
15
|
-
expect(converted.day).to eq date.day
|
16
|
-
expect(converted.time_zone).to eq Time.zone
|
17
|
-
end
|
18
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe DateTime do
|
6
|
-
let(:date_time) { parse_time('2010-01-01 00:00:00') }
|
7
|
-
|
8
|
-
it 'should allow advancing by calendar days' do
|
9
|
-
expect(date_time.advance_considering_calendar(:calendar_days, 10))
|
10
|
-
.to eq parse_time('2010-01-10 23:59:59')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should allow advancing by calendar months' do
|
14
|
-
expect(date_time.advance_considering_calendar(:calendar_months, 10))
|
15
|
-
.to eq parse_time('2010-10-31 23:59:59')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should allow advancing by calendar years' do
|
19
|
-
expect(date_time.advance_considering_calendar(:calendar_years, 10))
|
20
|
-
.to eq parse_time('2019-12-31 23:59:59')
|
21
|
-
end
|
22
|
-
|
23
|
-
def parse_time(time)
|
24
|
-
# ActiveSupport 5.1+ returns end of day differently
|
25
|
-
# Returns with usec at 999999 vs 0
|
26
|
-
DateTime.parse(time).end_of_day
|
27
|
-
end
|
28
|
-
end
|
data/spec/rails/period_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'timely/rails/period'
|
6
|
-
|
7
|
-
describe Timely::Period do
|
8
|
-
let(:time) { DateTime.new(2000, 1, 1, 12, 0, 0) }
|
9
|
-
let(:period_after_time) { DateTime.new(2000, 1, 1, 12, 2, 0) }
|
10
|
-
subject(:period) { Timely::Period.new(2, :minutes) }
|
11
|
-
|
12
|
-
it 'should work' do
|
13
|
-
expect(period.after(time)).to eq period_after_time
|
14
|
-
end
|
15
|
-
|
16
|
-
specify do
|
17
|
-
expect(period.to_s).to eq '2 minutes'
|
18
|
-
end
|
19
|
-
end
|
data/spec/rails/time_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
TestRailsTime = Class.new(Time) do
|
6
|
-
include ::Timely::Rails::Time
|
7
|
-
end
|
8
|
-
|
9
|
-
describe TestRailsTime do
|
10
|
-
before { TestRailsTime.zone = 'Australia/Sydney' }
|
11
|
-
|
12
|
-
it 'should be able to set date on a time' do
|
13
|
-
xmas = Date.new(2012, 12, 25)
|
14
|
-
lunch_time = TestRailsTime.parse('12:00')
|
15
|
-
xmas_lunch = lunch_time.on_date(xmas)
|
16
|
-
expect(xmas_lunch.year).to eq 2012
|
17
|
-
expect(xmas_lunch.month).to eq 12
|
18
|
-
expect(xmas_lunch.day).to eq 25
|
19
|
-
expect(xmas_lunch.hour).to eq 12
|
20
|
-
expect(xmas_lunch.min).to eq 0
|
21
|
-
expect(xmas_lunch.sec).to eq 0
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should allow setting the date part given a date' do
|
25
|
-
time = TestRailsTime.parse('2010-01-01 09:30:00')
|
26
|
-
expect(time.on_date(Date.parse('2012-12-31'))).to eq TestRailsTime.zone.parse('2012-12-31 09:30:00')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe Time do
|
31
|
-
before :each do
|
32
|
-
TestRailsTime.zone = 'Australia/Sydney'
|
33
|
-
@time = TestRailsTime.now
|
34
|
-
|
35
|
-
@year = 2005
|
36
|
-
@month = 3
|
37
|
-
@day = 15
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should give that time on a date' do
|
41
|
-
expect(@time).to respond_to(:on_date)
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'giving that time on a date' do
|
45
|
-
it 'should accept year, month and day' do
|
46
|
-
expect { @time.on_date(@year, @month, @day) }.to_not raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should require year, month, and day' do
|
50
|
-
expect { @time.on_date(@year, @month) }.to raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should return the same time on the specified year, month, and day' do
|
54
|
-
expected = TestRailsTime.zone.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
55
|
-
expect(@time.on_date(@year, @month, @day)).to eq expected
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should accept a date' do
|
59
|
-
expect { @time.on_date(Date.today) }.to_not raise_error
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should return the same time on the specified date' do
|
63
|
-
@date = Date.today - 2345
|
64
|
-
expected = Time.zone.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
|
65
|
-
expect(@time.on_date(@date)).to eq expected
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should provide 'on' as an alias" do
|
70
|
-
expected = TestRailsTime.zone.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
71
|
-
expect(@time.on(@year, @month, @day)).to eq expected
|
72
|
-
end
|
73
|
-
end
|
data/spec/schema.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ActiveRecord::Schema.define(version: 1) do
|
4
|
-
create_table :seasonals do |t|
|
5
|
-
t.date :boundary_start, :boundary_end
|
6
|
-
t.integer :season_id
|
7
|
-
end
|
8
|
-
|
9
|
-
create_table :seasons do |t|
|
10
|
-
t.string :name
|
11
|
-
end
|
12
|
-
|
13
|
-
create_table :date_groups do |t|
|
14
|
-
t.integer :season_id, :weekdays_bit_array, null: false, default: Timely::WeekDays::ALL_WEEKDAYS.weekdays_int
|
15
|
-
t.date :start_date, :end_date
|
16
|
-
end
|
17
|
-
end
|
data/spec/season_spec.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Timely::Season, 'in general' do
|
6
|
-
before do
|
7
|
-
# 1st and 3rd Quarter
|
8
|
-
@simple_low_season = Timely::Season.new
|
9
|
-
@simple_low_season.date_groups.build(start_date: '2009-01-01'.to_date, end_date: '2009-03-31'.to_date)
|
10
|
-
@simple_low_season.date_groups.build(start_date: '2009-07-01'.to_date, end_date: '2009-09-30'.to_date)
|
11
|
-
|
12
|
-
# 2nd and 4th Quarter
|
13
|
-
@simple_high_season = Timely::Season.new
|
14
|
-
@simple_high_season.date_groups.build(start_date: '2009-04-01'.to_date, end_date: '2009-06-30'.to_date)
|
15
|
-
@simple_high_season.date_groups.build(start_date: '2009-10-01'.to_date, end_date: '2009-12-31'.to_date)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'be able to tell if a date is in or out of its season' do
|
19
|
-
low_season_date = '2009-02-22'.to_date
|
20
|
-
high_season_date = '2009-04-22'.to_date
|
21
|
-
|
22
|
-
expect(@simple_low_season.includes_date?(low_season_date)).to be true
|
23
|
-
expect(@simple_high_season.includes_date?(low_season_date)).to_not be true
|
24
|
-
|
25
|
-
expect(@simple_low_season.includes_date?(high_season_date)).to_not be true
|
26
|
-
expect(@simple_high_season.includes_date?(high_season_date)).to be true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should be able to tell the boundary range (the range including the absolute first and last date) of itself' do
|
30
|
-
expect(@simple_low_season.boundary_range).to eq('2009-01-01'.to_date..'2009-09-30'.to_date)
|
31
|
-
expect(@simple_high_season.boundary_range).to eq('2009-04-01'.to_date..'2009-12-31'.to_date)
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'creating with nested attributes' do
|
35
|
-
subject { Timely::Season.new(date_groups_attributes: attrs) }
|
36
|
-
|
37
|
-
context 'with valid attributes' do
|
38
|
-
let(:attrs) { [ { 'start_date' => '2019-11-26' } ] }
|
39
|
-
it 'accepts nested date groups' do
|
40
|
-
expect(subject.date_groups).not_to be_empty
|
41
|
-
expect(subject.date_groups.first.start_date).to eq('2019-11-26'.to_date)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'invalid nested date groups' do
|
46
|
-
let(:attrs) { [ { 'start_date' => '' } ] }
|
47
|
-
it 'rejects nested date groups with nil start date' do
|
48
|
-
expect(subject.date_groups).to be_empty
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# == Schema Information
|
55
|
-
#
|
56
|
-
# Table name: seasons
|
57
|
-
#
|
58
|
-
# id :integer(4) not null, primary key
|
59
|
-
# name :string(255)
|
60
|
-
# created_at :datetime
|
61
|
-
# updated_at :datetime
|
62
|
-
#
|
data/spec/spec_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
-
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
6
|
-
# loaded once.
|
7
|
-
#
|
8
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
-
|
10
|
-
require 'rubygems'
|
11
|
-
require 'bundler/setup'
|
12
|
-
require 'rspec/its'
|
13
|
-
require 'active_record'
|
14
|
-
require 'pry'
|
15
|
-
require 'database_cleaner'
|
16
|
-
|
17
|
-
require 'support/coverage_loader'
|
18
|
-
|
19
|
-
I18n.enforce_available_locales = true if I18n.respond_to? :enforce_available_locales=
|
20
|
-
|
21
|
-
require 'timely'
|
22
|
-
require 'timely/rails'
|
23
|
-
|
24
|
-
DB_FILE = 'tmp/test_db'
|
25
|
-
FileUtils.mkdir_p File.dirname(DB_FILE)
|
26
|
-
FileUtils.rm_f DB_FILE
|
27
|
-
|
28
|
-
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: DB_FILE
|
29
|
-
|
30
|
-
load('spec/schema.rb')
|
31
|
-
|
32
|
-
RSpec.configure do |config|
|
33
|
-
config.run_all_when_everything_filtered = true
|
34
|
-
config.filter_run :focus
|
35
|
-
|
36
|
-
config.before(:suite) do
|
37
|
-
DatabaseCleaner.strategy = :transaction
|
38
|
-
DatabaseCleaner.clean_with(:truncation, except: %w(ar_internal_metadata))
|
39
|
-
end
|
40
|
-
|
41
|
-
config.around(:each) do |example|
|
42
|
-
DatabaseCleaner.cleaning do
|
43
|
-
example.run
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Timely::TemporalPatterns do
|
6
|
-
before(:all) do
|
7
|
-
@from = Date.new(2012, 1, 1)
|
8
|
-
@to = Date.new(2013, 4, 1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should be able to create a basic 1st-of-the-month recurrence pattern' do
|
12
|
-
pattern = Timely::TemporalPatterns::Pattern.new([@from..@to], 1.month)
|
13
|
-
expect(pattern.to_s).to eq 'every 1st of the month from 2012-01-01T00:00:00+00:00 to 2013-04-01T00:00:00+00:00'
|
14
|
-
|
15
|
-
expect(pattern.match?('01-05-2012'.to_date)).to be true
|
16
|
-
expect(pattern.match?('01-08-2012'.to_date)).to be true
|
17
|
-
expect(pattern.match?('01-04-2013'.to_date)).to be true
|
18
|
-
|
19
|
-
expect(pattern.match?('03-05-2012'.to_date)).to be false
|
20
|
-
expect(pattern.match?('01-06-2013'.to_date)).to be false
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should only allow a positive duration to be set as the frequency of the pattern' do
|
24
|
-
expect { Timely::TemporalPatterns::Frequency.new(2) }.to raise_error(ArgumentError)
|
25
|
-
expect { Timely::TemporalPatterns::Frequency.new(-5.months) }.to raise_error(ArgumentError)
|
26
|
-
expect(Timely::TemporalPatterns::Frequency.new(3.months).to_s).to eq 'every 3 months'
|
27
|
-
end
|
28
|
-
end
|
data/spec/time_since_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'timely/time_since'
|
4
|
-
|
5
|
-
require 'timecop'
|
6
|
-
|
7
|
-
describe Timely::TimeSince do
|
8
|
-
before do
|
9
|
-
Timecop.freeze(DateTime.new(2000, 1, 10, 12, 0, 42))
|
10
|
-
end
|
11
|
-
after { Timecop.return }
|
12
|
-
|
13
|
-
context '42 seconds ago' do
|
14
|
-
subject(:time) { DateTime.new(2000, 1, 10, 12, 0, 0) }
|
15
|
-
its(:seconds_since) { should eq 42 }
|
16
|
-
its(:minutes_since) { should eq 0 }
|
17
|
-
its(:hours_since) { should eq 0 }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'a day ago' do
|
21
|
-
subject(:time) { DateTime.new(2000, 1, 9, 12, 0, 42) }
|
22
|
-
its(:seconds_since) { should eq 24 * 60 * 60 }
|
23
|
-
its(:minutes_since) { should eq 24 * 60 }
|
24
|
-
its(:hours_since) { should eq 24 }
|
25
|
-
end
|
26
|
-
end
|