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/time_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
TestTime = Class.new(Time) do
|
6
|
-
include ::Timely::Time
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Time do
|
10
|
-
it 'should be able to set date on a time' do
|
11
|
-
xmas = Date.new(2012, 12, 25)
|
12
|
-
lunch_time = TestTime.parse('12:00')
|
13
|
-
xmas_lunch = lunch_time.on_date(xmas)
|
14
|
-
expect(xmas_lunch.year).to eq 2012
|
15
|
-
expect(xmas_lunch.month).to eq 12
|
16
|
-
expect(xmas_lunch.day).to eq 25
|
17
|
-
expect(xmas_lunch.hour).to eq 12
|
18
|
-
expect(xmas_lunch.min).to eq 0
|
19
|
-
expect(xmas_lunch.sec).to eq 0
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should allow setting the date part given a date' do
|
23
|
-
time = TestTime.parse('2010-01-01 09:30:00')
|
24
|
-
expect(time.on_date(Date.parse('2012-12-31'))).to eq Time.parse('2012-12-31 09:30:00')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Time do
|
29
|
-
before :each do
|
30
|
-
@time = TestTime.now
|
31
|
-
|
32
|
-
@year = 2005
|
33
|
-
@month = 3
|
34
|
-
@day = 15
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should give that time on a date' do
|
38
|
-
expect(@time).to respond_to(:on_date)
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'giving that time on a date' do
|
42
|
-
it 'should accept year, month and day' do
|
43
|
-
expect { @time.on_date(@year, @month, @day) }.to_not raise_error
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should require year, month, and day' do
|
47
|
-
expect { @time.on_date(@year, @month) }.to raise_error(ArgumentError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should return the same time on the specified year, month, and day' do
|
51
|
-
expected = Time.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
52
|
-
expect(@time.on_date(@year, @month, @day)).to eq expected
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should accept a date' do
|
56
|
-
expect { @time.on_date(Date.today) }.to_not raise_error
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should return the same time on the specified date' do
|
60
|
-
@date = Date.today - 2345
|
61
|
-
expected = Time.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
|
62
|
-
expect(@time.on_date(@date)).to eq expected
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should provide 'on' as an alias" do
|
67
|
-
expected = Time.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
68
|
-
expect(@time.on(@year, @month, @day)).to eq expected
|
69
|
-
end
|
70
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Timely::TrackableDateSet, ' tracking 7 days' do
|
6
|
-
before do
|
7
|
-
@range = Date.today..(Date.today + 6)
|
8
|
-
@trackable_date_set = Timely::TrackableDateSet.new(@range)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should start on the first date' do
|
12
|
-
expect(@trackable_date_set.start_date).to eq Date.today
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should end on the last date' do
|
16
|
-
expect(@trackable_date_set.end_date).to eq Date.today + 6
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should have the 7 days set' do
|
20
|
-
expect(dates).to eq @range.to_a
|
21
|
-
expect(@trackable_date_set.duration).to eq 7
|
22
|
-
expect(@trackable_date_set.number_of_nights).to eq 7
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have all the 7 days to do' do
|
26
|
-
expect(dates_to_do).to eq @range.to_a
|
27
|
-
should_not_have_done(@range.to_a)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should have only the last 6 days to do when we set_done! the first one' do
|
31
|
-
@trackable_date_set.set_date_done!(Date.today)
|
32
|
-
expect(dates_to_do).to eq(((Date.today + 1)..(Date.today + 6)).to_a)
|
33
|
-
|
34
|
-
should_not_have_done(@range.to_a - [Date.today])
|
35
|
-
should_have_done([Date.today])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should have the first, and last three left to do if we set 2nd, 3rd & 4th to be done' do
|
39
|
-
dates_to_be_done = [Date.today + 1, Date.today + 2, Date.today + 3]
|
40
|
-
@trackable_date_set.set_dates_done!(dates_to_be_done)
|
41
|
-
|
42
|
-
expect(dates_to_do).to eq [Date.today, Date.today + 4, Date.today + 5, Date.today + 6]
|
43
|
-
should_not_have_done(@range.to_a - dates_to_be_done)
|
44
|
-
should_have_done(dates_to_be_done)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should have none left to do when set_all_done!' do
|
48
|
-
@trackable_date_set.set_all_done!
|
49
|
-
expect(dates_to_do).to eq []
|
50
|
-
should_have_done(@range.to_a)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should have no actions applied' do
|
54
|
-
expect(@trackable_date_set.action_applied?(:some_action)).to be false
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should remember if we apply an action' do
|
58
|
-
@trackable_date_set.apply_action(:some_action)
|
59
|
-
expect(@trackable_date_set.action_applied?(:some_action)).to be true
|
60
|
-
expect(@trackable_date_set.action_applied?(:some_other_action)).to be false
|
61
|
-
end
|
62
|
-
|
63
|
-
def should_have_done(dates)
|
64
|
-
dates.each { |date| expect(@trackable_date_set.done_dates?(date)).to be true }
|
65
|
-
end
|
66
|
-
|
67
|
-
def should_not_have_done(dates)
|
68
|
-
dates.each { |date| expect(@trackable_date_set.done_dates?(date)).to be false }
|
69
|
-
end
|
70
|
-
|
71
|
-
def dates
|
72
|
-
contained_dates = []
|
73
|
-
@trackable_date_set.each_date { |date| contained_dates << date }
|
74
|
-
contained_dates
|
75
|
-
end
|
76
|
-
|
77
|
-
def dates_to_do
|
78
|
-
contained_dates = []
|
79
|
-
@trackable_date_set.each_date_to_do { |date| contained_dates << date }
|
80
|
-
contained_dates
|
81
|
-
end
|
82
|
-
end
|
data/spec/week_days_spec.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Timely::WeekDays do
|
6
|
-
before do
|
7
|
-
@weekdays = Timely::WeekDays.new(tue: true, thu: true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should create via hash, integer and array' do
|
11
|
-
# 0 0 1 0 1 0 0
|
12
|
-
# Sat Fri Thu Wed Tue Mon Sun
|
13
|
-
expect(Timely::WeekDays.new(0b0010100).weekdays).to eq %i[tue thu]
|
14
|
-
expect(Timely::WeekDays.new(%w[0 0 1 0 1 0 0]).weekdays).to eq %i[tue thu]
|
15
|
-
expect(Timely::WeekDays.new(tue: true, thu: true).weekdays).to eq %i[tue thu]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should be able to set/unset days' do
|
19
|
-
@weekdays[:mon] = true
|
20
|
-
expect(@weekdays.weekdays).to eq %i[mon tue thu]
|
21
|
-
@weekdays[:tue] = false
|
22
|
-
expect(@weekdays.weekdays).to eq %i[mon thu]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should output days nicely' do
|
26
|
-
expect(Timely::WeekDays.new(%w[1 0 0 0 0 0 0]).to_s).to eq 'Sun'
|
27
|
-
expect(Timely::WeekDays.new(%w[1 0 1 0 0 0 0]).to_s).to eq 'Sun, and Tue'
|
28
|
-
expect(Timely::WeekDays.new(%w[1 0 1 1 0 0 0]).to_s).to eq 'Sun, Tue, and Wed'
|
29
|
-
expect(Timely::WeekDays.new(%w[1 0 1 1 0 1 0]).to_s).to eq 'Sun, Tue, Wed, and Fri'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should be able to determine if days of the week are selected' do
|
33
|
-
# Test mon and tue in both symbol/integer forms
|
34
|
-
expect(@weekdays.has_day?(1)).to be false
|
35
|
-
expect(@weekdays.has_day?(:mon)).to be false
|
36
|
-
expect(@weekdays.has_day?(2)).to be true
|
37
|
-
expect(@weekdays.has_day?(:tue)).to be true
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should be able to determine if it would be applicable on a date' do
|
41
|
-
expect(@weekdays.applies_for_date?(Date.new(2012, 0o4, 22))).to be false # Sunday
|
42
|
-
expect(@weekdays.applies_for_date?(Date.new(2012, 0o4, 24))).to be true # Tuesday
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be able to convert to integer for use in databases, etc.' do
|
46
|
-
expect(@weekdays.weekdays_int).to eq 4 + 16 # 4 = Tue, 16 = Thu
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should be able to determine if all days are selected' do
|
50
|
-
expect(Timely::WeekDays.new(%w[1 1 1 1 1 1 1]).all_days?).to be true
|
51
|
-
expect(Timely::WeekDays.new(%w[1 1 1 1 1 0 1]).all_days?).to be false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
RSpec.describe 'Timely::WeekDays.from_range' do
|
56
|
-
{
|
57
|
-
'single date as string': { date_range: '2019-10-17', expected_weekdays: [:thu] },
|
58
|
-
'single date as object': { date_range: '2019-10-17'.to_date, expected_weekdays: [:thu] },
|
59
|
-
'range with strings': {
|
60
|
-
date_range: '2019-10-17'..'2019-10-18',
|
61
|
-
expected_weekdays: %i[thu fri]
|
62
|
-
},
|
63
|
-
'range with objects': {
|
64
|
-
date_range: ('2019-10-17'.to_date)..('2019-10-18'.to_date),
|
65
|
-
expected_weekdays: %i[thu fri]
|
66
|
-
}
|
67
|
-
}.each do |type, data|
|
68
|
-
it "#{type} has correct weekdays and applies for dates" do
|
69
|
-
weekdays = Timely::WeekDays.from_range(data[:date_range])
|
70
|
-
expect(weekdays.weekdays).to eq(data[:expected_weekdays])
|
71
|
-
Array(data[:date_range]).each do |date|
|
72
|
-
expect(weekdays.applies_for_date?(date.to_date)).to eq(true)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|