timely 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
 - data/.rubocop.yml +22 -2
 - data/.travis.yml +0 -6
 - data/CHANGELOG.md +6 -0
 - data/Gemfile +2 -0
 - data/Rakefile +6 -4
 - data/gemfiles/rails5.gemfile +4 -2
 - data/gemfiles/rails6.gemfile +3 -1
 - data/lib/timely/date.rb +6 -2
 - data/lib/timely/date_chooser.rb +29 -30
 - data/lib/timely/date_range.rb +17 -19
 - data/lib/timely/date_time.rb +3 -1
 - data/lib/timely/rails/calendar_tag.rb +3 -3
 - data/lib/timely/rails/date.rb +3 -1
 - data/lib/timely/rails/date_group.rb +24 -24
 - data/lib/timely/rails/date_range_validity_module.rb +8 -6
 - data/lib/timely/rails/date_time.rb +5 -3
 - data/lib/timely/rails/extensions.rb +12 -37
 - data/lib/timely/rails/period.rb +14 -12
 - data/lib/timely/rails/season.rb +14 -33
 - data/lib/timely/rails/time.rb +7 -3
 - data/lib/timely/rails.rb +2 -0
 - data/lib/timely/railtie.rb +2 -0
 - data/lib/timely/range.rb +4 -2
 - data/lib/timely/string.rb +4 -2
 - data/lib/timely/time.rb +7 -3
 - data/lib/timely/time_since.rb +5 -3
 - data/lib/timely/trackable_date_set.rb +21 -21
 - data/lib/timely/version.rb +3 -1
 - data/lib/timely/week_days.rb +14 -16
 - data/lib/timely.rb +2 -0
 - data/rails/init.rb +2 -0
 - data/spec/calendar_tag_spec.rb +11 -10
 - data/spec/date_chooser_spec.rb +67 -62
 - data/spec/date_group_spec.rb +18 -15
 - data/spec/date_range_spec.rb +29 -19
 - data/spec/date_spec.rb +3 -1
 - data/spec/extensions_spec.rb +5 -9
 - data/spec/rails/date_spec.rb +5 -3
 - data/spec/rails/date_time_spec.rb +9 -7
 - data/spec/rails/period_spec.rb +2 -0
 - data/spec/rails/time_spec.rb +6 -4
 - data/spec/schema.rb +4 -3
 - data/spec/season_spec.rb +23 -26
 - data/spec/spec_helper.rb +3 -1
 - data/spec/support/coverage_loader.rb +3 -1
 - data/spec/temporal_patterns_spec.rb +5 -5
 - data/spec/time_since_spec.rb +6 -4
 - data/spec/time_spec.rb +6 -4
 - data/spec/trackable_date_set_spec.rb +20 -18
 - data/spec/week_days_spec.rb +24 -22
 - data/timely.gemspec +20 -18
 - metadata +32 -20
 - data/spec/string_spec.rb +0 -14
 
    
        data/spec/date_group_spec.rb
    CHANGED
    
    | 
         @@ -1,23 +1,29 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            RSpec.describe Timely::DateGroup do
         
     | 
| 
       5 
6 
     | 
    
         
             
              before do
         
     | 
| 
       6 
7 
     | 
    
         
             
                @date_group = Timely::DateGroup.new(
         
     | 
| 
       7 
     | 
    
         
            -
                  : 
     | 
| 
      
 8 
     | 
    
         
            +
                  start_date: '2000-01-01', end_date: '2000-01-03', weekdays: %w[1 1 1 1 1 1 1]
         
     | 
| 
       8 
9 
     | 
    
         
             
                )
         
     | 
| 
       9 
10 
     | 
    
         
             
              end
         
     | 
| 
       10 
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 
     | 
    
         
            +
             
     | 
| 
       11 
17 
     | 
    
         
             
              it 'should detect overlaps' do
         
     | 
| 
       12 
18 
     | 
    
         
             
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-01'.to_date))).to be true
         
     | 
| 
       13 
19 
     | 
    
         
             
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-06'.to_date))).to be true
         
     | 
| 
       14 
20 
     | 
    
         
             
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2001-01-01'.to_date, '2001-01-01'.to_date))).to be false
         
     | 
| 
       15 
     | 
    
         
            -
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('1999-12-29'.to_date, '2000-01-05'.to_date))).to be true 
     | 
| 
      
 21 
     | 
    
         
            +
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('1999-12-29'.to_date, '2000-01-05'.to_date))).to be true
         
     | 
| 
       16 
22 
     | 
    
         
             
              end
         
     | 
| 
       17 
23 
     | 
    
         | 
| 
       18 
24 
     | 
    
         
             
              it "should detect overlaps when certain weekdays aren't selected" do
         
     | 
| 
       19 
25 
     | 
    
         
             
                @date_group = Timely::DateGroup.create!(
         
     | 
| 
       20 
     | 
    
         
            -
                  : 
     | 
| 
      
 26 
     | 
    
         
            +
                  start_date: '2012-01-01', end_date: '2012-01-07', weekdays: %w[1 0 1 0 1 0 1]
         
     | 
| 
       21 
27 
     | 
    
         
             
                )
         
     | 
| 
       22 
28 
     | 
    
         
             
                # Note: 2012-01-1 is a Sunday
         
     | 
| 
       23 
29 
     | 
    
         
             
                expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-01'.to_date))).to be true
         
     | 
| 
         @@ -27,21 +33,18 @@ RSpec.describe Timely::DateGroup do 
     | 
|
| 
       27 
33 
     | 
    
         
             
              end
         
     | 
| 
       28 
34 
     | 
    
         
             
            end
         
     | 
| 
       29 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
            RSpec.describe Timely::DateGroup, 'without weekdays' do
         
     | 
| 
      
 37 
     | 
    
         
            +
              subject { Timely::DateGroup.new(start_date: Date.current, end_date: Date.current) }
         
     | 
| 
      
 38 
     | 
    
         
            +
              it { is_expected.to be_valid }
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
| 
       30 
40 
     | 
    
         | 
| 
       31 
41 
     | 
    
         
             
            RSpec.describe 'Timely::DateGroup.for_any_weekdays' do
         
     | 
| 
       32 
42 
     | 
    
         
             
              let(:date_range) { ('2019-10-17'.to_date)..('2019-10-18'.to_date) }
         
     | 
| 
       33 
43 
     | 
    
         
             
              let(:weekdays_int) { Timely::WeekDays.from_range(date_range).weekdays_int }
         
     | 
| 
       34 
44 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
              let(:special_group) {
         
     | 
| 
       36 
     | 
    
         
            -
                Timely::DateGroup.create(start_date: date_range.first, end_date: date_range.last).tap { |date_group|
         
     | 
| 
       37 
     | 
    
         
            -
                  date_group.update_column(:weekdays_bit_array, nil)
         
     | 
| 
       38 
     | 
    
         
            -
                }.reload
         
     | 
| 
       39 
     | 
    
         
            -
              }
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
45 
     | 
    
         
             
              let!(:date_groups) { [
         
     | 
| 
       42 
46 
     | 
    
         
             
                Timely::DateGroup.create(start_date: date_range.first, end_date: date_range.last, weekdays: { thu: true }),
         
     | 
| 
       43 
47 
     | 
    
         
             
                Timely::DateGroup.create(start_date: date_range.first, end_date: date_range.last, weekdays: { mon: true }),
         
     | 
| 
       44 
     | 
    
         
            -
                special_group,
         
     | 
| 
       45 
48 
     | 
    
         
             
              ] }
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
       47 
50 
     | 
    
         
             
              RSpec.shared_examples 'finds expected date groups' do
         
     | 
| 
         @@ -61,15 +64,15 @@ RSpec.describe 'Timely::DateGroup.for_any_weekdays' do 
     | 
|
| 
       61 
64 
     | 
    
         | 
| 
       62 
65 
     | 
    
         
             
              context '#within_range' do
         
     | 
| 
       63 
66 
     | 
    
         
             
                let(:scoped_result) { Timely::DateGroup.within_range(date_range).to_a }
         
     | 
| 
       64 
     | 
    
         
            -
                let(:expected_groups) { [ 
     | 
| 
       65 
     | 
    
         
            -
                let(:absent_groups) { [ 
     | 
| 
      
 67 
     | 
    
         
            +
                let(:expected_groups) { [date_groups[0], date_groups[1]] }
         
     | 
| 
      
 68 
     | 
    
         
            +
                let(:absent_groups) { [] }
         
     | 
| 
       66 
69 
     | 
    
         
             
                let(:includes_date_groups) { [] }
         
     | 
| 
       67 
70 
     | 
    
         
             
                it_behaves_like 'finds expected date groups'
         
     | 
| 
       68 
71 
     | 
    
         
             
              end
         
     | 
| 
       69 
72 
     | 
    
         | 
| 
       70 
73 
     | 
    
         
             
              let(:includes_date_groups) { expected_groups }
         
     | 
| 
       71 
     | 
    
         
            -
              let(:expected_groups) { [ 
     | 
| 
       72 
     | 
    
         
            -
              let(:absent_groups) { [ 
     | 
| 
      
 74 
     | 
    
         
            +
              let(:expected_groups) { [date_groups[0]] }
         
     | 
| 
      
 75 
     | 
    
         
            +
              let(:absent_groups) { [date_groups[1]] }
         
     | 
| 
       73 
76 
     | 
    
         | 
| 
       74 
77 
     | 
    
         
             
              context '#for_any_weekdays' do
         
     | 
| 
       75 
78 
     | 
    
         
             
                let(:scoped_result) { Timely::DateGroup.for_any_weekdays(weekdays_int).to_a }
         
     | 
    
        data/spec/date_range_spec.rb
    CHANGED
    
    | 
         @@ -1,22 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Timely::DateRange do
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              it "should allow initialization with two dates" do
         
     | 
| 
      
 6 
     | 
    
         
            +
              it 'should allow initialization with two dates' do
         
     | 
| 
       6 
7 
     | 
    
         
             
                expect { @date_range = Timely::DateRange.new(Date.today, Date.today + 3) }.to_not raise_error
         
     | 
| 
       7 
8 
     | 
    
         
             
                expect(@date_range.start_date).to eq Date.today
         
     | 
| 
       8 
9 
     | 
    
         
             
                expect(@date_range.end_date).to eq Date.today + 3
         
     | 
| 
       9 
10 
     | 
    
         
             
                expect(@date_range.number_of_nights).to eq 4
         
     | 
| 
       10 
11 
     | 
    
         
             
              end
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              it  
     | 
| 
      
 13 
     | 
    
         
            +
              it 'should allow initialization with one date' do
         
     | 
| 
       13 
14 
     | 
    
         
             
                expect { @date_range = Timely::DateRange.new(Date.today) }.to_not raise_error
         
     | 
| 
       14 
15 
     | 
    
         
             
                expect(@date_range.start_date).to eq Date.today
         
     | 
| 
       15 
16 
     | 
    
         
             
                expect(@date_range.end_date).to eq Date.today
         
     | 
| 
       16 
17 
     | 
    
         
             
                expect(@date_range.number_of_nights).to eq 1
         
     | 
| 
       17 
18 
     | 
    
         
             
              end
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              it  
     | 
| 
      
 20 
     | 
    
         
            +
              it 'should allow initialization with a range' do
         
     | 
| 
       20 
21 
     | 
    
         
             
                expect { @date_range = Timely::DateRange.new(Date.today..Date.today + 3) }.to_not raise_error
         
     | 
| 
       21 
22 
     | 
    
         
             
                expect(@date_range.start_date).to eq Date.today
         
     | 
| 
       22 
23 
     | 
    
         
             
                expect(@date_range.end_date).to eq Date.today + 3
         
     | 
| 
         @@ -59,21 +60,30 @@ describe Timely::DateRange do 
     | 
|
| 
       59 
60 
     | 
    
         
             
                expect(today.last).to eq '2000-01-05'.to_date
         
     | 
| 
       60 
61 
     | 
    
         
             
              end
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
              it  
     | 
| 
       63 
     | 
    
         
            -
                @date_range = Timely::DateRange.new( 
     | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       71 
77 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                @date_range = Timely::DateRange.new( 
     | 
| 
       73 
     | 
    
         
            -
                 
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       77 
88 
     | 
    
         
             
              end
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
89 
     | 
    
         
             
            end
         
     | 
    
        data/spec/date_spec.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Date do
         
     | 
| 
         @@ -63,7 +65,7 @@ describe Date do 
     | 
|
| 
       63 
65 
     | 
    
         
             
                end
         
     | 
| 
       64 
66 
     | 
    
         | 
| 
       65 
67 
     | 
    
         
             
                it 'should return the passed-in time on the date' do
         
     | 
| 
       66 
     | 
    
         
            -
                  @time = Time.now -  
     | 
| 
      
 68 
     | 
    
         
            +
                  @time = Time.now - 12_345
         
     | 
| 
       67 
69 
     | 
    
         
             
                  expected = Time.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
         
     | 
| 
       68 
70 
     | 
    
         
             
                  expect(@date.at_time(@time)).to eq expected
         
     | 
| 
       69 
71 
     | 
    
         
             
                end
         
     | 
    
        data/spec/extensions_spec.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'timely/rails/extensions'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -13,20 +15,14 @@ describe Timely::Extensions do 
     | 
|
| 
       13 
15 
     | 
    
         | 
| 
       14 
16 
     | 
    
         
             
              it 'should cache boundary start' do
         
     | 
| 
       15 
17 
     | 
    
         
             
                season = Timely::Season.new
         
     | 
| 
       16 
     | 
    
         
            -
                season.date_groups.build(: 
     | 
| 
       17 
     | 
    
         
            -
                season.date_groups.build(: 
     | 
| 
      
 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)
         
     | 
| 
       18 
20 
     | 
    
         
             
                season.save!
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
22 
     | 
    
         
             
                o = TimelyExtensionsTestSeasonal.new
         
     | 
| 
       21 
23 
     | 
    
         
             
                o.season = season
         
     | 
| 
       22 
24 
     | 
    
         
             
                o.save!
         
     | 
| 
       23 
25 
     | 
    
         
             
                expect(o.boundary_start).to eq Date.current - 1
         
     | 
| 
       24 
     | 
    
         
            -
                expect(o.boundary_end 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                expect(TimelyExtensionsTestSeasonal.season_on(Date.current + 3)).to be_empty
         
     | 
| 
       27 
     | 
    
         
            -
                expect(TimelyExtensionsTestSeasonal.season_on(Date.current + 2)).to eq [o]
         
     | 
| 
       28 
     | 
    
         
            -
                expect(TimelyExtensionsTestSeasonal.season_on(Date.current - 1)).to eq [o]
         
     | 
| 
       29 
     | 
    
         
            -
                expect(TimelyExtensionsTestSeasonal.season_on(Date.current - 2)).to be_empty
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                expect(o.boundary_end).to eq Date.current + 2
         
     | 
| 
       31 
27 
     | 
    
         
             
              end
         
     | 
| 
       32 
28 
     | 
    
         
             
            end
         
     | 
    
        data/spec/rails/date_spec.rb
    CHANGED
    
    | 
         @@ -1,13 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Date do
         
     | 
| 
       4 
     | 
    
         
            -
              let(:date) { Date.parse( 
     | 
| 
      
 6 
     | 
    
         
            +
              let(:date) { Date.parse('2010-01-01') }
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              before { Time.zone = ActiveSupport::TimeZone[ 
     | 
| 
      
 8 
     | 
    
         
            +
              before { Time.zone = ActiveSupport::TimeZone['Adelaide'] }
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
10 
     | 
    
         
             
              subject(:converted) { date.to_time_in_time_zone }
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              it  
     | 
| 
      
 12 
     | 
    
         
            +
              it 'should convert to time in time zone' do
         
     | 
| 
       11 
13 
     | 
    
         
             
                expect(converted.year).to eq date.year
         
     | 
| 
       12 
14 
     | 
    
         
             
                expect(converted.month).to eq date.month
         
     | 
| 
       13 
15 
     | 
    
         
             
                expect(converted.day).to eq date.day
         
     | 
| 
         @@ -1,21 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe DateTime do
         
     | 
| 
       4 
     | 
    
         
            -
              let(:date_time) { parse_time( 
     | 
| 
      
 6 
     | 
    
         
            +
              let(:date_time) { parse_time('2010-01-01 00:00:00') }
         
     | 
| 
       5 
7 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              it  
     | 
| 
      
 8 
     | 
    
         
            +
              it 'should allow advancing by calendar days' do
         
     | 
| 
       7 
9 
     | 
    
         
             
                expect(date_time.advance_considering_calendar(:calendar_days, 10))
         
     | 
| 
       8 
     | 
    
         
            -
                  .to eq parse_time( 
     | 
| 
      
 10 
     | 
    
         
            +
                  .to eq parse_time('2010-01-10 23:59:59')
         
     | 
| 
       9 
11 
     | 
    
         
             
              end
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
              it  
     | 
| 
      
 13 
     | 
    
         
            +
              it 'should allow advancing by calendar months' do
         
     | 
| 
       12 
14 
     | 
    
         
             
                expect(date_time.advance_considering_calendar(:calendar_months, 10))
         
     | 
| 
       13 
     | 
    
         
            -
                  .to eq parse_time( 
     | 
| 
      
 15 
     | 
    
         
            +
                  .to eq parse_time('2010-10-31 23:59:59')
         
     | 
| 
       14 
16 
     | 
    
         
             
              end
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              it  
     | 
| 
      
 18 
     | 
    
         
            +
              it 'should allow advancing by calendar years' do
         
     | 
| 
       17 
19 
     | 
    
         
             
                expect(date_time.advance_considering_calendar(:calendar_years, 10))
         
     | 
| 
       18 
     | 
    
         
            -
                  .to eq parse_time( 
     | 
| 
      
 20 
     | 
    
         
            +
                  .to eq parse_time('2019-12-31 23:59:59')
         
     | 
| 
       19 
21 
     | 
    
         
             
              end
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
       21 
23 
     | 
    
         
             
              def parse_time(time)
         
     | 
    
        data/spec/rails/period_spec.rb
    CHANGED
    
    
    
        data/spec/rails/time_spec.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            TestRailsTime = Class.new(Time) do
         
     | 
| 
         @@ -9,7 +11,7 @@ describe TestRailsTime do 
     | 
|
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
              it 'should be able to set date on a time' do
         
     | 
| 
       11 
13 
     | 
    
         
             
                xmas = Date.new(2012, 12, 25)
         
     | 
| 
       12 
     | 
    
         
            -
                lunch_time = TestRailsTime.parse( 
     | 
| 
      
 14 
     | 
    
         
            +
                lunch_time = TestRailsTime.parse('12:00')
         
     | 
| 
       13 
15 
     | 
    
         
             
                xmas_lunch = lunch_time.on_date(xmas)
         
     | 
| 
       14 
16 
     | 
    
         
             
                expect(xmas_lunch.year).to eq 2012
         
     | 
| 
       15 
17 
     | 
    
         
             
                expect(xmas_lunch.month).to eq 12
         
     | 
| 
         @@ -19,9 +21,9 @@ describe TestRailsTime do 
     | 
|
| 
       19 
21 
     | 
    
         
             
                expect(xmas_lunch.sec).to eq 0
         
     | 
| 
       20 
22 
     | 
    
         
             
              end
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
              it  
     | 
| 
       23 
     | 
    
         
            -
                time = TestRailsTime.parse( 
     | 
| 
       24 
     | 
    
         
            -
                expect(time.on_date(Date.parse( 
     | 
| 
      
 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')
         
     | 
| 
       25 
27 
     | 
    
         
             
              end
         
     | 
| 
       26 
28 
     | 
    
         
             
            end
         
     | 
| 
       27 
29 
     | 
    
         | 
    
        data/spec/schema.rb
    CHANGED
    
    | 
         @@ -1,4 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ActiveRecord::Schema.define(version: 1) do
         
     | 
| 
       2 
4 
     | 
    
         
             
              create_table :seasonals do |t|
         
     | 
| 
       3 
5 
     | 
    
         
             
                t.date :boundary_start, :boundary_end
         
     | 
| 
       4 
6 
     | 
    
         
             
                t.integer :season_id
         
     | 
| 
         @@ -9,8 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do 
     | 
|
| 
       9 
11 
     | 
    
         
             
              end
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
              create_table :date_groups do |t|
         
     | 
| 
       12 
     | 
    
         
            -
                t.integer :season_id, :weekdays_bit_array
         
     | 
| 
      
 14 
     | 
    
         
            +
                t.integer :season_id, :weekdays_bit_array, null: false, default: Timely::WeekDays::ALL_WEEKDAYS.weekdays_int
         
     | 
| 
       13 
15 
     | 
    
         
             
                t.date :start_date, :end_date
         
     | 
| 
       14 
16 
     | 
    
         
             
              end
         
     | 
| 
       15 
17 
     | 
    
         
             
            end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
    
        data/spec/season_spec.rb
    CHANGED
    
    | 
         @@ -1,19 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe Timely::Season,  
     | 
| 
      
 5 
     | 
    
         
            +
            describe Timely::Season, 'in general' do
         
     | 
| 
       4 
6 
     | 
    
         
             
              before do
         
     | 
| 
       5 
7 
     | 
    
         
             
                # 1st and 3rd Quarter
         
     | 
| 
       6 
8 
     | 
    
         
             
                @simple_low_season = Timely::Season.new
         
     | 
| 
       7 
     | 
    
         
            -
                @simple_low_season.date_groups.build(: 
     | 
| 
       8 
     | 
    
         
            -
                @simple_low_season.date_groups.build(: 
     | 
| 
      
 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)
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
                # 2nd and 4th Quarter
         
     | 
| 
       11 
13 
     | 
    
         
             
                @simple_high_season = Timely::Season.new
         
     | 
| 
       12 
     | 
    
         
            -
                @simple_high_season.date_groups.build(: 
     | 
| 
       13 
     | 
    
         
            -
                @simple_high_season.date_groups.build(: 
     | 
| 
      
 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)
         
     | 
| 
       14 
16 
     | 
    
         
             
              end
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              it  
     | 
| 
      
 18 
     | 
    
         
            +
              it 'be able to tell if a date is in or out of its season' do
         
     | 
| 
       17 
19 
     | 
    
         
             
                low_season_date = '2009-02-22'.to_date
         
     | 
| 
       18 
20 
     | 
    
         
             
                high_season_date = '2009-04-22'.to_date
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
         @@ -24,35 +26,31 @@ describe Timely::Season, "in general" do 
     | 
|
| 
       24 
26 
     | 
    
         
             
                expect(@simple_high_season.includes_date?(high_season_date)).to be true
         
     | 
| 
       25 
27 
     | 
    
         
             
              end
         
     | 
| 
       26 
28 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              it  
     | 
| 
      
 29 
     | 
    
         
            +
              it 'should be able to tell the boundary range (the range including the absolute first and last date) of itself' do
         
     | 
| 
       28 
30 
     | 
    
         
             
                expect(@simple_low_season.boundary_range).to eq('2009-01-01'.to_date..'2009-09-30'.to_date)
         
     | 
| 
       29 
31 
     | 
    
         
             
                expect(@simple_high_season.boundary_range).to eq('2009-04-01'.to_date..'2009-12-31'.to_date)
         
     | 
| 
       30 
32 
     | 
    
         
             
              end
         
     | 
| 
       31 
     | 
    
         
            -
            end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            describe Timely::Season, 'when asked to build season for given dates' do
         
     | 
| 
       35 
     | 
    
         
            -
              subject(:season) { Timely::Season.build_season_for(dates) }
         
     | 
| 
       36 
33 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
              context ' 
     | 
| 
       38 
     | 
    
         
            -
                 
     | 
| 
       39 
     | 
    
         
            -
                its(:class) { should eq Timely::Season }
         
     | 
| 
       40 
     | 
    
         
            -
                its('date_groups.size') { should eq 3 }
         
     | 
| 
      
 34 
     | 
    
         
            +
              context 'creating with nested attributes' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                subject { Timely::Season.new(date_groups_attributes: attrs) }
         
     | 
| 
       41 
36 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
                 
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       46 
43 
     | 
    
         
             
                end
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
44 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       52 
51 
     | 
    
         
             
              end
         
     | 
| 
       53 
52 
     | 
    
         
             
            end
         
     | 
| 
       54 
53 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
54 
     | 
    
         
             
            # == Schema Information
         
     | 
| 
       57 
55 
     | 
    
         
             
            #
         
     | 
| 
       58 
56 
     | 
    
         
             
            # Table name: seasons
         
     | 
| 
         @@ -62,4 +60,3 @@ end 
     | 
|
| 
       62 
60 
     | 
    
         
             
            #  created_at :datetime
         
     | 
| 
       63 
61 
     | 
    
         
             
            #  updated_at :datetime
         
     | 
| 
       64 
62 
     | 
    
         
             
            #
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            # This file was generated by the `rspec --init` command. Conventionally, all
         
     | 
| 
       2 
4 
     | 
    
         
             
            # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
         
     | 
| 
       3 
5 
     | 
    
         
             
            # Require this file using `require "spec_helper.rb"` to ensure that it is only
         
     | 
| 
         @@ -21,7 +23,7 @@ DB_FILE = 'tmp/test_db' 
     | 
|
| 
       21 
23 
     | 
    
         
             
            FileUtils.mkdir_p File.dirname(DB_FILE)
         
     | 
| 
       22 
24 
     | 
    
         
             
            FileUtils.rm_f DB_FILE
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
            ActiveRecord::Base.establish_connection : 
     | 
| 
      
 26 
     | 
    
         
            +
            ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: DB_FILE
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
28 
     | 
    
         
             
            load('spec/schema.rb')
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Timely::TemporalPatterns do
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
6 
     | 
    
         
             
              before(:all) do
         
     | 
| 
       6 
7 
     | 
    
         
             
                @from = Date.new(2012, 1, 1)
         
     | 
| 
       7 
8 
     | 
    
         
             
                @to   = Date.new(2013, 4, 1)
         
     | 
| 
       8 
9 
     | 
    
         
             
              end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              it  
     | 
| 
      
 11 
     | 
    
         
            +
              it 'should be able to create a basic 1st-of-the-month recurrence pattern' do
         
     | 
| 
       11 
12 
     | 
    
         
             
                pattern = Timely::TemporalPatterns::Pattern.new([@from..@to], 1.month)
         
     | 
| 
       12 
     | 
    
         
            -
                expect(pattern.to_s).to eq  
     | 
| 
      
 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'
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
15 
     | 
    
         
             
                expect(pattern.match?('01-05-2012'.to_date)).to be true
         
     | 
| 
       15 
16 
     | 
    
         
             
                expect(pattern.match?('01-08-2012'.to_date)).to be true
         
     | 
| 
         @@ -19,10 +20,9 @@ describe Timely::TemporalPatterns do 
     | 
|
| 
       19 
20 
     | 
    
         
             
                expect(pattern.match?('01-06-2013'.to_date)).to be false
         
     | 
| 
       20 
21 
     | 
    
         
             
              end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
              it  
     | 
| 
      
 23 
     | 
    
         
            +
              it 'should only allow a positive duration to be set as the frequency of the pattern' do
         
     | 
| 
       23 
24 
     | 
    
         
             
                expect { Timely::TemporalPatterns::Frequency.new(2) }.to raise_error(ArgumentError)
         
     | 
| 
       24 
25 
     | 
    
         
             
                expect { Timely::TemporalPatterns::Frequency.new(-5.months) }.to raise_error(ArgumentError)
         
     | 
| 
       25 
26 
     | 
    
         
             
                expect(Timely::TemporalPatterns::Frequency.new(3.months).to_s).to eq 'every 3 months'
         
     | 
| 
       26 
27 
     | 
    
         
             
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
28 
     | 
    
         
             
            end
         
     | 
    
        data/spec/time_since_spec.rb
    CHANGED
    
    | 
         @@ -1,11 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'timely/time_since'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            require 'timecop'
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            describe Timely::TimeSince do
         
     | 
| 
       6 
     | 
    
         
            -
              before  
     | 
| 
      
 8 
     | 
    
         
            +
              before do
         
     | 
| 
       7 
9 
     | 
    
         
             
                Timecop.freeze(DateTime.new(2000, 1, 10, 12, 0, 42))
         
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
       9 
11 
     | 
    
         
             
              after { Timecop.return }
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
              context '42 seconds ago' do
         
     | 
| 
         @@ -17,8 +19,8 @@ describe Timely::TimeSince do 
     | 
|
| 
       17 
19 
     | 
    
         | 
| 
       18 
20 
     | 
    
         
             
              context 'a day ago' do
         
     | 
| 
       19 
21 
     | 
    
         
             
                subject(:time) { DateTime.new(2000, 1, 9, 12, 0, 42) }
         
     | 
| 
       20 
     | 
    
         
            -
                its(:seconds_since) { should eq 24*60*60 }
         
     | 
| 
       21 
     | 
    
         
            -
                its(:minutes_since) { should eq 24*60 }
         
     | 
| 
      
 22 
     | 
    
         
            +
                its(:seconds_since) { should eq 24 * 60 * 60 }
         
     | 
| 
      
 23 
     | 
    
         
            +
                its(:minutes_since) { should eq 24 * 60 }
         
     | 
| 
       22 
24 
     | 
    
         
             
                its(:hours_since) { should eq 24 }
         
     | 
| 
       23 
25 
     | 
    
         
             
              end
         
     | 
| 
       24 
26 
     | 
    
         
             
            end
         
     | 
    
        data/spec/time_spec.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            TestTime = Class.new(Time) do
         
     | 
| 
         @@ -7,7 +9,7 @@ end 
     | 
|
| 
       7 
9 
     | 
    
         
             
            describe Time do
         
     | 
| 
       8 
10 
     | 
    
         
             
              it 'should be able to set date on a time' do
         
     | 
| 
       9 
11 
     | 
    
         
             
                xmas = Date.new(2012, 12, 25)
         
     | 
| 
       10 
     | 
    
         
            -
                lunch_time = TestTime.parse( 
     | 
| 
      
 12 
     | 
    
         
            +
                lunch_time = TestTime.parse('12:00')
         
     | 
| 
       11 
13 
     | 
    
         
             
                xmas_lunch = lunch_time.on_date(xmas)
         
     | 
| 
       12 
14 
     | 
    
         
             
                expect(xmas_lunch.year).to eq 2012
         
     | 
| 
       13 
15 
     | 
    
         
             
                expect(xmas_lunch.month).to eq 12
         
     | 
| 
         @@ -17,9 +19,9 @@ describe Time do 
     | 
|
| 
       17 
19 
     | 
    
         
             
                expect(xmas_lunch.sec).to eq 0
         
     | 
| 
       18 
20 
     | 
    
         
             
              end
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
              it  
     | 
| 
       21 
     | 
    
         
            -
                time = TestTime.parse( 
     | 
| 
       22 
     | 
    
         
            -
                expect(time.on_date(Date.parse( 
     | 
| 
      
 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')
         
     | 
| 
       23 
25 
     | 
    
         
             
              end
         
     | 
| 
       24 
26 
     | 
    
         
             
            end
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Timely::TrackableDateSet, ' tracking 7 days' do
         
     | 
| 
         @@ -6,45 +8,45 @@ describe Timely::TrackableDateSet, ' tracking 7 days' do 
     | 
|
| 
       6 
8 
     | 
    
         
             
                @trackable_date_set = Timely::TrackableDateSet.new(@range)
         
     | 
| 
       7 
9 
     | 
    
         
             
              end
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
              it  
     | 
| 
      
 11 
     | 
    
         
            +
              it 'should start on the first date' do
         
     | 
| 
       10 
12 
     | 
    
         
             
                expect(@trackable_date_set.start_date).to eq Date.today
         
     | 
| 
       11 
13 
     | 
    
         
             
              end
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              it  
     | 
| 
      
 15 
     | 
    
         
            +
              it 'should end on the last date' do
         
     | 
| 
       14 
16 
     | 
    
         
             
                expect(@trackable_date_set.end_date).to eq Date.today + 6
         
     | 
| 
       15 
17 
     | 
    
         
             
              end
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              it  
     | 
| 
       18 
     | 
    
         
            -
                expect( 
     | 
| 
      
 19 
     | 
    
         
            +
              it 'should have the 7 days set' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                expect(dates).to eq @range.to_a
         
     | 
| 
       19 
21 
     | 
    
         
             
                expect(@trackable_date_set.duration).to eq 7
         
     | 
| 
       20 
22 
     | 
    
         
             
                expect(@trackable_date_set.number_of_nights).to eq 7
         
     | 
| 
       21 
23 
     | 
    
         
             
              end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
              it  
     | 
| 
       24 
     | 
    
         
            -
                expect( 
     | 
| 
      
 25 
     | 
    
         
            +
              it 'should have all the 7 days to do' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect(dates_to_do).to eq @range.to_a
         
     | 
| 
       25 
27 
     | 
    
         
             
                should_not_have_done(@range.to_a)
         
     | 
| 
       26 
28 
     | 
    
         
             
              end
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
              it  
     | 
| 
      
 30 
     | 
    
         
            +
              it 'should have only the last 6 days to do when we set_done! the first one' do
         
     | 
| 
       29 
31 
     | 
    
         
             
                @trackable_date_set.set_date_done!(Date.today)
         
     | 
| 
       30 
     | 
    
         
            -
                expect( 
     | 
| 
      
 32 
     | 
    
         
            +
                expect(dates_to_do).to eq(((Date.today + 1)..(Date.today + 6)).to_a)
         
     | 
| 
       31 
33 
     | 
    
         | 
| 
       32 
34 
     | 
    
         
             
                should_not_have_done(@range.to_a - [Date.today])
         
     | 
| 
       33 
35 
     | 
    
         
             
                should_have_done([Date.today])
         
     | 
| 
       34 
36 
     | 
    
         
             
              end
         
     | 
| 
       35 
37 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
              it  
     | 
| 
      
 38 
     | 
    
         
            +
              it 'should have the first, and last three left to do if we set 2nd, 3rd & 4th to be done' do
         
     | 
| 
       37 
39 
     | 
    
         
             
                dates_to_be_done = [Date.today + 1, Date.today + 2, Date.today + 3]
         
     | 
| 
       38 
40 
     | 
    
         
             
                @trackable_date_set.set_dates_done!(dates_to_be_done)
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                expect( 
     | 
| 
      
 42 
     | 
    
         
            +
                expect(dates_to_do).to eq [Date.today, Date.today + 4, Date.today + 5, Date.today + 6]
         
     | 
| 
       41 
43 
     | 
    
         
             
                should_not_have_done(@range.to_a - dates_to_be_done)
         
     | 
| 
       42 
44 
     | 
    
         
             
                should_have_done(dates_to_be_done)
         
     | 
| 
       43 
45 
     | 
    
         
             
              end
         
     | 
| 
       44 
46 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
              it  
     | 
| 
      
 47 
     | 
    
         
            +
              it 'should have none left to do when set_all_done!' do
         
     | 
| 
       46 
48 
     | 
    
         
             
                @trackable_date_set.set_all_done!
         
     | 
| 
       47 
     | 
    
         
            -
                expect( 
     | 
| 
      
 49 
     | 
    
         
            +
                expect(dates_to_do).to eq []
         
     | 
| 
       48 
50 
     | 
    
         
             
                should_have_done(@range.to_a)
         
     | 
| 
       49 
51 
     | 
    
         
             
              end
         
     | 
| 
       50 
52 
     | 
    
         | 
| 
         @@ -59,22 +61,22 @@ describe Timely::TrackableDateSet, ' tracking 7 days' do 
     | 
|
| 
       59 
61 
     | 
    
         
             
              end
         
     | 
| 
       60 
62 
     | 
    
         | 
| 
       61 
63 
     | 
    
         
             
              def should_have_done(dates)
         
     | 
| 
       62 
     | 
    
         
            -
                dates.each{|date| expect(@trackable_date_set. 
     | 
| 
      
 64 
     | 
    
         
            +
                dates.each { |date| expect(@trackable_date_set.done_dates?(date)).to be true }
         
     | 
| 
       63 
65 
     | 
    
         
             
              end
         
     | 
| 
       64 
66 
     | 
    
         | 
| 
       65 
67 
     | 
    
         
             
              def should_not_have_done(dates)
         
     | 
| 
       66 
     | 
    
         
            -
                dates.each{|date| expect(@trackable_date_set. 
     | 
| 
      
 68 
     | 
    
         
            +
                dates.each { |date| expect(@trackable_date_set.done_dates?(date)).to be false }
         
     | 
| 
       67 
69 
     | 
    
         
             
              end
         
     | 
| 
       68 
70 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
              def  
     | 
| 
      
 71 
     | 
    
         
            +
              def dates
         
     | 
| 
       70 
72 
     | 
    
         
             
                contained_dates = []
         
     | 
| 
       71 
     | 
    
         
            -
                @trackable_date_set.each_date{|date| contained_dates << date}
         
     | 
| 
      
 73 
     | 
    
         
            +
                @trackable_date_set.each_date { |date| contained_dates << date }
         
     | 
| 
       72 
74 
     | 
    
         
             
                contained_dates
         
     | 
| 
       73 
75 
     | 
    
         
             
              end
         
     | 
| 
       74 
76 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
              def  
     | 
| 
      
 77 
     | 
    
         
            +
              def dates_to_do
         
     | 
| 
       76 
78 
     | 
    
         
             
                contained_dates = []
         
     | 
| 
       77 
     | 
    
         
            -
                @trackable_date_set.each_date_to_do{|date| contained_dates << date}
         
     | 
| 
      
 79 
     | 
    
         
            +
                @trackable_date_set.each_date_to_do { |date| contained_dates << date }
         
     | 
| 
       78 
80 
     | 
    
         
             
                contained_dates
         
     | 
| 
       79 
81 
     | 
    
         
             
              end
         
     | 
| 
       80 
82 
     | 
    
         
             
            end
         
     |