Skip to content

Commit

Permalink
Merge pull request #4 from kdgm/feature/tzinfo_2_0
Browse files Browse the repository at this point in the history
fix `tzinfo 2.0` regressions
  • Loading branch information
LeipeLeon authored Jun 12, 2024
2 parents 54347c3 + ae8a852 commit c28d6ce
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 48 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
gemfiles/*.lock
Empty file removed .rspec
Empty file.
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions gemfiles/active_support_6_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activesupport", "~> 6.1.0", require: "active_support"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/active_support_7_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activesupport", "~> 7.0.0", require: "active_support"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/active_support_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activesupport", "~> 7.1.0", require: "active_support"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/tzinfo_2_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "tzinfo", "~> 2"

gemspec path: "../"
22 changes: 11 additions & 11 deletions lib/ri_cal/component/t_z_info_timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 4 additions & 14 deletions ri_cal.gemspec
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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'
Expand All @@ -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
18 changes: 9 additions & 9 deletions spec/ri_cal/calendar_occurrences_edge_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" => {
Expand All @@ -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" => {
Expand All @@ -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" => {
Expand All @@ -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" => {
Expand Down Expand Up @@ -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" => {
Expand Down Expand Up @@ -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" => {
Expand Down
12 changes: 6 additions & 6 deletions spec/ri_cal/calendar_occurrences_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c28d6ce

Please sign in to comment.