# rubocop:disable Metrics/BlockLength require 'dates_toolbox' RSpec.describe DatesToolbox do it 'has a version number' do expect(DatesToolbox::VERSION).not_to be nil end before(:each) do @d = Date.new end context 'Testing extending date class' do context 'Test format setting' do it 'says true for testing format after setting to %Y' do @d.format = '%Y' expect(@d.test_format).to eql(true) end it 'says false for testing format after setting to %Q' do @d.format = '%Q' expect(@d.test_format).to eql(false) end end context 'Test basic functionality' do context 'Full/Default method names' do it 'says 23 June 1912 is a day 1' do expect(@d.the_day('23/6/1912')).to eql(23) end it 'says 23 June 1912 is a month 6' do expect(@d.the_month('23/6/1912')).to eql(6) end it 'says 23 June 1912 is a year 1912' do expect(@d.the_year('23/6/1912')).to eql(1912) end it 'says 23 June 1912 is day 0' do expect(@d.day_of_the_week('23/6/1912')).to eql(0) end it 'says 23 June 1912 is a Sunday' do expect(@d.day_of_the_week_name('23/6/1912')).to eql('Sunday') end it 'says 23 June 1912 is day of year 175' do expect(@d.day_of_the_year('23/6/1912')).to eql(175) end it 'says 15324 for days between 23 June 1912 and 7 June 1954' do expect(@d.days_between('23/6/1912', '7/6/1954')).to eql(15_324) end end context 'Aliased method names' do it 'says 23 June 1912 is day 0' do expect(@d.dotw('23/6/1912')).to eql(0) end it 'says 23 June 1912 is a Sunday' do expect(@d.dotwn('23/6/1912')).to eql('Sunday') end it 'says 23 June 1912 is day of year 175' do expect(@d.doty('23/6/1912')).to eql(175) end end end context 'Test complex functionality' do it 'returns an array for weekends in the year 2000' do expect(@d.weekends('1/1/2000', '31/12/2000')).to be_an_instance_of(Array) end it 'says ["01/01/2000", "02/01/2000", "08/01/2000", "09/01/2000", "15/01/2000", "16/01/2000", "22/01/2000", "23/01/2000", "29/01/2000", "30/01/2000"] for weekends in the year Jan 2000' do expect(@d.weekends_string('1/1/2000', '31/1/2000')).to match_array(['01/01/2000', '02/01/2000', '08/01/2000', '09/01/2000', '15/01/2000', '16/01/2000', '22/01/2000', '23/01/2000', '29/01/2000', '30/01/2000']) end it 'returns an array for weekdays in the year 2000' do expect(@d.weekdays('1/1/2000', '31/12/2000')).to be_an_instance_of(Array) end it 'says ["03/01/2000", "04/01/2000", "05/01/2000", "06/01/2000", "07/01/2000", "10/01/2000", "11/01/2000", "12/01/2000", "13/01/2000", "14/01/2000"] for weekdays in the first 2 weeks Jan 2000' do expect(@d.weekdays_string('1/1/2000', '14/1/2000')).to match_array(['03/01/2000', '04/01/2000', '05/01/2000', '06/01/2000', '07/01/2000', '10/01/2000', '11/01/2000', '12/01/2000', '13/01/2000', '14/01/2000']) end end context 'Test error handling' do it 'says Invalid date 25/12/2000 with format %m/%d/%Y' do begin expect(@d.day_of_the_year('25/12/2000', '%m/%d/%Y')).to eql('Invalid date 25/12/2000 with format %m/%d/%Y') rescue ArgumentError => e _actual = e end end end end context 'Test overloaded string class' do context 'Test basic functionality' do context 'Full/Default method names' do it 'says 23 June 1912 is day 23' do expect('23/6/1912'.the_day).to eql(23) end it 'says 23 June 1912 is month 6' do expect('23/6/1912'.the_month).to eql(6) end it 'says 23 June 1912 is a year 1912' do expect('23/6/1912'.the_year).to eql(1912) end it 'says 23 June 1912 is day 0' do expect('23/6/1912'.day_of_the_week).to eql(0) end it 'says 23 June 1912 is a Sunday' do expect('23/6/1912'.day_of_the_week_name).to eql('Sunday') end it 'says 23 June 1912 is day of year 175' do expect('23/6/1912'.day_of_the_year).to eql(175) end it 'says 15324 for days between 23 June 1912 and 7 June 1954' do expect('23/6/1912'.days_between('7/6/1954')).to eql(15_324) end end context 'Alias method names' do it 'says 23 June 1912 is day 0' do expect('23/6/1912'.dotw).to eql(0) end it 'says 23 June 1912 is a Sunday' do expect('23/6/1912'.dotwn).to eql('Sunday') end it 'says 23 June 1912 is day of year 175' do expect('23/6/1912'.doty).to eql(175) end end end context 'Test complex functionality' do it 'returns an array for weekends in the year 2000' do expect('1/1/2000'.weekends('31/12/2000')).to be_an_instance_of(Array) end it 'says ["01/01/2000", "02/01/2000", "08/01/2000", "09/01/2000", "15/01/2000", "16/01/2000", "22/01/2000", "23/01/2000", "29/01/2000", "30/01/2000"] for weekends in the year Jan 2000' do expect('1/1/2000'.weekends_string('31/1/2000')).to match_array(['01/01/2000', '02/01/2000', '08/01/2000', '09/01/2000', '15/01/2000', '16/01/2000', '22/01/2000', '23/01/2000', '29/01/2000', '30/01/2000']) end it 'returns an array for weekdays in the year 2000' do expect('1/1/2000'.weekdays('31/12/2000')).to be_an_instance_of(Array) end it 'says ["03/01/2000", "04/01/2000", "05/01/2000", "06/01/2000", "07/01/2000", "10/01/2000", "11/01/2000", "12/01/2000", "13/01/2000", "14/01/2000"] for weekdays in the first 2 weeks Jan 2000' do expect('1/1/2000'.weekdays_string('14/1/2000')).to match_array(['03/01/2000', '04/01/2000', '05/01/2000', '06/01/2000', '07/01/2000', '10/01/2000', '11/01/2000', '12/01/2000', '13/01/2000', '14/01/2000']) end end end end # rubocop:enable Metrics/BlockLength