diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..a7642566 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ + +name: Test & lint + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + - develop + +jobs: + spec: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} w/ ${{ matrix.gemfile }} + strategy: + fail-fast: false + matrix: + ruby: + - "2.6" + - "2.7" + - "3.0" + - "3.1" + - "3.2" + gemfile: + - tzinfo_2_0 + - active_support_6_1 + - active_support_7_0 + - active_support_7_1 + exclude: + - ruby: "2.6" + gemfile: active_support_7_0 + - ruby: "2.6" + gemfile: active_support_7_1 + env: + BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile + BUNDLE_PATH: "gemfiles/vendor/bundle" + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - uses: actions/cache@v3 + with: + # NOTE: Bundler expands the path relative to the gemfile, not the + # current directory. + path: ./gemfiles/vendor/bundle + key: bundled-gems-${{ runner.os }}-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles( 'gemfiles/*.lock' ) }} + restore-keys: | + bundled-gems-${{ runner.os }}-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}- + bundled-gems-${{ runner.os }}-ruby-${{ matrix.ruby }}- + - name: Run tests + run: bundle exec rspec diff --git a/.gitignore b/.gitignore index d87d4be6..eba00d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +gemfiles/*.lock diff --git a/.rspec b/.rspec deleted file mode 100644 index e69de29b..00000000 diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 77d8d524..00000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -kdgm-ri_cal diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 23a63f52..00000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.2.8 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8c0d4d10..00000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: ruby -rvm: - - 1.9.3-p551 - - 2.2.8 -# uncomment this line if your project needs to run something other than `rake`: -# script: bundle exec rspec spec diff --git a/Appraisals b/Appraisals new file mode 100644 index 00000000..3a58eefe --- /dev/null +++ b/Appraisals @@ -0,0 +1,15 @@ +appraise "tzinfo_2_0" do + gem "tzinfo", "~> 2" +end + +appraise "active_support_6_1" do + gem "activesupport", "~> 6.1.0", require: "active_support" +end + +appraise "active_support_7_0" do + gem "activesupport", "~> 7.0.0", require: "active_support" +end + +appraise "active_support_7_1" do + gem "activesupport", "~> 7.1.0", require: "active_support" +end diff --git a/gemfiles/active_support_6_1.gemfile b/gemfiles/active_support_6_1.gemfile new file mode 100644 index 00000000..5b9831a2 --- /dev/null +++ b/gemfiles/active_support_6_1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 6.1.0", require: "active_support" + +gemspec path: "../" diff --git a/gemfiles/active_support_7_0.gemfile b/gemfiles/active_support_7_0.gemfile new file mode 100644 index 00000000..79954297 --- /dev/null +++ b/gemfiles/active_support_7_0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.0.0", require: "active_support" + +gemspec path: "../" diff --git a/gemfiles/active_support_7_1.gemfile b/gemfiles/active_support_7_1.gemfile new file mode 100644 index 00000000..2e683e1b --- /dev/null +++ b/gemfiles/active_support_7_1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.1.0", require: "active_support" + +gemspec path: "../" diff --git a/gemfiles/tzinfo_2_0.gemfile b/gemfiles/tzinfo_2_0.gemfile new file mode 100644 index 00000000..81ebb3c7 --- /dev/null +++ b/gemfiles/tzinfo_2_0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "tzinfo", "~> 2" + +gemspec path: "../" diff --git a/lib/ri_cal/component/t_z_info_timezone.rb b/lib/ri_cal/component/t_z_info_timezone.rb index e0a6ae78..c010236a 100644 --- a/lib/ri_cal/component/t_z_info_timezone.rb +++ b/lib/ri_cal/component/t_z_info_timezone.rb @@ -22,20 +22,20 @@ def initialize(which, this_period, prev_period) @abbreviation = this_period.abbreviation @rdates = [] end - + def daylight? @which == "DAYLIGHT" end - + def period_local_end(period) - (period.local_end || DateTime.parse("99990101T000000")).strftime("%Y%m%dT%H%M%S") + (period.local_ends_at&.to_datetime || DateTime.parse("99990101T000000")).strftime("%Y%m%dT%H%M%S") end - + # This assumes a 1 hour shift which is why we use the previous period local end when # possible def period_local_start(period) shift = daylight? ? Rational(-1, 24) : Rational(1, 24) - ((period.local_start || DateTime.parse("16010101T000000")) + shift).strftime("%Y%m%dT%H%M%S") + ((period.local_starts_at&.to_datetime || DateTime.parse("16010101T000000")) + shift).strftime("%Y%m%dT%H%M%S") end def add_period(this_period) @@ -69,7 +69,7 @@ class Periods #:nodoc: all def initialize @dst_period = @std_period = @previous_period = nil end - + def empty? @periods.nil? || @periods.empty? end @@ -86,7 +86,7 @@ def log_period(period) @periods ||= [] @periods << period unless @periods.include?(period) end - + def add_period(this_period, force=false) if @previous_period || force if this_period.dst? @@ -110,7 +110,7 @@ def export_to(export_stream) def initialize(tzinfo_timezone) #:nodoc: @tzinfo_timezone = tzinfo_timezone end - + # convert time from this time zone to utc time def local_to_utc(time, dst_ambiguity=nil) @tzinfo_timezone.local_to_utc(time.to_ri_cal_ruby_value, dst_ambiguity) @@ -143,11 +143,11 @@ def export_utc_to(export_stream, utc_start, utc_end) #:nodoc: periods = Periods.new period = initial_period = tzinfo_timezone.period_for_utc(utc_start) #start with the period before the one containing utc_start - prev_period = period.utc_start && tzinfo_timezone.period_for_utc(period.utc_start - 1) + prev_period = period.starts_at && tzinfo_timezone.period_for_utc(period.starts_at.to_datetime - 1) period = prev_period if prev_period - while period && period.utc_start && period.utc_start < utc_end + while period && period.starts_at && period.starts_at.to_datetime < utc_end periods.add_period(period) - period = period.utc_end && tzinfo_timezone.period_for_utc(period.utc_end + 1) + period = period.ends_at && tzinfo_timezone.period_for_utc(period.ends_at.to_datetime + 1) end periods.add_period(initial_period, :force) if periods.empty? periods.export_to(export_stream) diff --git a/ri_cal.gemspec b/ri_cal.gemspec index f2bc4639..74d52e1c 100644 --- a/ri_cal.gemspec +++ b/ri_cal.gemspec @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -#- 2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license +# - 2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license require File.join File.dirname(__FILE__), 'lib', 'ri_cal', 'version' Gem::Specification.new do |gem| gem.authors = ["Jon Phenow, Rick DeNatale"] @@ -21,11 +21,10 @@ A Google group for discussion of this library has been set up http://groups.goog gem.name = "ri_cal" gem.require_paths = ["lib"] gem.version = RiCal::VERSION - gem.required_ruby_version = '>= 1.9.3' + gem.required_ruby_version = '>= 2.6.7' - gem.add_dependency 'tzinfo' + gem.add_runtime_dependency 'tzinfo', "~> 2.0", "< 3.0" - gem.add_development_dependency 'activesupport', "~> 3.0.15" gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' gem.add_development_dependency 'rspec-its' @@ -34,14 +33,5 @@ A Google group for discussion of this library has been set up http://groups.goog gem.add_development_dependency 'autotest-standalone' gem.add_development_dependency 'autotest-fsevent' gem.add_development_dependency 'awesome_print' - - if gem.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - gem.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') - else - end - else - end + gem.add_development_dependency 'appraisal' end diff --git a/spec/ri_cal/calendar_occurrences_edge_cases_spec.rb b/spec/ri_cal/calendar_occurrences_edge_cases_spec.rb index 4303a3a5..70325c69 100644 --- a/spec/ri_cal/calendar_occurrences_edge_cases_spec.rb +++ b/spec/ri_cal/calendar_occurrences_edge_cases_spec.rb @@ -9,14 +9,14 @@ def generate_calendar(fixtures) dtstart, rrule = recurring.split('#') event do |e| e.uid = uid - e.dtstart = Time.parse(dtstart) + e.dtstart = DateTime.parse(dtstart) e.rrule = rrule if rrule end overrides.each do |dtfrom, dtto| event do |e| e.uid = uid - e.dtstart = Time.parse(dtto) - e.recurrence_id = Time.parse(dtfrom) + e.dtstart = DateTime.parse(dtto) + e.recurrence_id = DateTime.parse(dtfrom) end end end @@ -26,7 +26,7 @@ def generate_calendar(fixtures) describe RiCal::Component::Calendar do context "move first override before range" do - let(:range) { { starting: Time.parse("2016-06-26"), count: 4 } } + let(:range) { { starting: DateTime.parse("2016-06-26"), count: 4 } } subject { generate_calendar( "Jun 26, 2016 16:30:00#FREQ=DAILY" => { @@ -48,7 +48,7 @@ def generate_calendar(fixtures) end context "move last event in range to a later date outside range/count" do - let(:range) { { starting: Time.parse("2016-06-27"), count: 4 } } + let(:range) { { starting: DateTime.parse("2016-06-27"), count: 4 } } subject { generate_calendar( "Jun 26, 2016 16:30:00#FREQ=DAILY" => { @@ -71,7 +71,7 @@ def generate_calendar(fixtures) end context "move all but last event out of range" do - let(:range) { { starting: Time.parse("2016-06-26"), before: Time.parse("2016-07-03") } } + let(:range) { { starting: DateTime.parse("2016-06-26"), before: DateTime.parse("2016-07-03") } } subject { generate_calendar( "Jun 26, 2016 16:30:00#FREQ=DAILY" => { @@ -95,7 +95,7 @@ def generate_calendar(fixtures) end context "move overrides into empty range" do - let(:range) { { starting: Time.parse("2016-06-26"), before: Time.parse("2016-07-03") } } + let(:range) { { starting: DateTime.parse("2016-06-26"), before: DateTime.parse("2016-07-03") } } subject { generate_calendar( "Jul 03, 2016 16:30:00#FREQ=DAILY" => { @@ -126,7 +126,7 @@ def generate_calendar(fixtures) end context "should distinguish coincident events" do - let(:range) { { starting: Time.parse("2016-06-26"), count: 8 } } + let(:range) { { starting: DateTime.parse("2016-06-26"), count: 8 } } subject { generate_calendar( "Jun 26, 2016 10:00:00#FREQ=DAILY#1" => { @@ -158,7 +158,7 @@ def generate_calendar(fixtures) end context "should return correct next occurrence" do - let(:range) { { starting: Time.parse("2016-06-26"), count: 1 } } + let(:range) { { starting: DateTime.parse("2016-06-26"), count: 1 } } subject { generate_calendar( "Jun 26, 2016 10:00:00#FREQ=DAILY" => { diff --git a/spec/ri_cal/calendar_occurrences_spec.rb b/spec/ri_cal/calendar_occurrences_spec.rb index b90578dc..0661e7f8 100644 --- a/spec/ri_cal/calendar_occurrences_spec.rb +++ b/spec/ri_cal/calendar_occurrences_spec.rb @@ -260,7 +260,7 @@ } it("should return correct date/times with `starting` set") { - subject.occurrences(starting: Time.parse("2016-06-29T11:30:00+02:00"), count: 3).map(&:dtstart).map(&:to_s).should eql(%w( + subject.occurrences(starting: DateTime.parse("2016-06-29T11:30:00+02:00"), count: 3).map(&:dtstart).map(&:to_s).should eql(%w( 2016-07-06T12:00:00+02:00 2016-07-13T12:00:00+02:00 2016-07-20T12:00:00+02:00 @@ -428,7 +428,7 @@ ]) } it { - subject.occurrences(starting: Time.parse("2016-06-16T20:00:01+02:00"), count: 6).map(&:summary).should eql([ + subject.occurrences(starting: DateTime.parse("2016-06-16T20:00:01+02:00"), count: 6).map(&:summary).should eql([ "Test 2", # instance summary "Test 3", # instance summary "Test Woensdag 18:00", # instance different day, time, summary @@ -438,7 +438,7 @@ ]) } it { - subject.occurrences(starting: Time.parse("2016-06-16T20:00:01+02:00"), before: Time.parse("2016-07-21T20:00:00+02:00")).map(&:summary).should eql([ + subject.occurrences(starting: DateTime.parse("2016-06-16T20:00:01+02:00"), before: DateTime.parse("2016-07-21T20:00:00+02:00")).map(&:summary).should eql([ "Test 2", # instance summary "Test 3", # instance summary "Test Woensdag 18:00", # instance different day, time, summary @@ -516,7 +516,7 @@ } it { - subject.occurrences(starting: Time.parse('2016-07-24 10:00:00'), count: 4).map{ |o| [o.dtstart.to_s, o.summary].join(' ') }.should eql([ + subject.occurrences(starting: DateTime.parse('2016-07-24 10:00:00+02:00'), count: 4).map{ |o| [o.dtstart.to_s, o.summary].join(' ') }.should eql([ "2016-07-24T10:00:00+02:00 dhr. N. Weeda", "2016-07-24T16:30:00+02:00 ds. W. M. van Wijk", "2016-07-31T10:00:00+02:00 ds. M. Oppenhuizen", @@ -1199,7 +1199,7 @@ subject { RiCal.Calendar do |cal| cal.event do |event| - event.dtstart = Time.parse("2016-06-27T15:00:00+02:00") + event.dtstart = DateTime.parse("2016-06-27T15:00:00+02:00") event.rrule = "FREQ=WEEKLY" end end @@ -1272,7 +1272,7 @@ its(:events) { should have(2).items } it { subject.occurrences( - starting: Time.parse("2016-09-15 10:59:45 +0200"), count: 3).map(&:dtstart).map(&:to_s).should eql(%w( + starting: DateTime.parse("2016-09-15 10:59:45 +0200"), count: 3).map(&:dtstart).map(&:to_s).should eql(%w( 2016-09-15T11:10:00+02:00 2016-09-22T10:00:00+02:00 2016-09-29T10:00:00+02:00