From 9b5d3d348e118921448b7b1b8d732cb2c87e65a3 Mon Sep 17 00:00:00 2001 From: Rick DeNatale Date: Sun, 14 Jun 2009 20:13:54 -0400 Subject: [PATCH] 0.6.3 - 14 June 2009 * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/13 tzinfotimezones-with-no-transitions-fail-on-export --- History.txt | 3 ++ lib/ri_cal.rb | 2 +- lib/ri_cal/component/t_z_info_timezone.rb | 36 +++++++++++++------ ri_cal.gemspec | 4 +-- .../component/t_z_info_timezone_spec.rb | 27 ++++++++++++-- website/index.html | 2 +- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/History.txt b/History.txt index 4b3de644..5fbffe5b 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,6 @@ +=== 0.6.3 - 14 June 2009 + * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/13 + tzinfotimezones-with-no-transitions-fail-on-export === 0.6.2 - 11 June 2009 * Fixed http://rick_denatale.lighthouseapp.com/projects/30941-ri_cal/tickets/12 export-failure-for-unbounded-tzinfo-timezone diff --git a/lib/ri_cal.rb b/lib/ri_cal.rb index 2b827bd6..2832db5a 100644 --- a/lib/ri_cal.rb +++ b/lib/ri_cal.rb @@ -14,7 +14,7 @@ module RiCal autoload :OccurrenceEnumerator, "#{my_dir}/ri_cal/occurrence_enumerator.rb" # :stopdoc: - VERSION = '0.6.2' + VERSION = '0.6.3' LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR diff --git a/lib/ri_cal/component/t_z_info_timezone.rb b/lib/ri_cal/component/t_z_info_timezone.rb index 0df24101..c406c935 100644 --- a/lib/ri_cal/component/t_z_info_timezone.rb +++ b/lib/ri_cal/component/t_z_info_timezone.rb @@ -2,21 +2,31 @@ # # A wrapper class for a Timezone implemented by the TZInfo Gem # (or by Rails) +# + class RiCal::Component::TZInfoTimezone < RiCal::Component::Timezone class Period #:nodoc: all def initialize(which, this_period, prev_period) @which = which - @onset = this_period.local_start.strftime("%Y%m%dT%H%M%S") - @offset_from = format_rfc2445_offset(prev_period.utc_total_offset) + @onset = period_local_start(this_period) + if prev_period + @offset_from = format_rfc2445_offset(prev_period.utc_total_offset) + else + @offset_from = format_rfc2445_offset(this_period.utc_total_offset) + end @offset_to = format_rfc2445_offset(this_period.utc_total_offset) @abbreviation = this_period.abbreviation @rdates = [] end + + def period_local_start(period) + (period.local_start || DateTime.parse("16010101T000000")).strftime("%Y%m%dT%H%M%S") + end def add_period(this_period) - @rdates << this_period.local_start.strftime("%Y%m%dT%H%M%S") + @rdates << period_local_start(this_period) end @@ -44,6 +54,10 @@ class Periods #:nodoc: all def initialize @dst_period = @std_period = @previous_period = nil end + + def empty? + @periods.nil? || @periods.empty? + end def daylight_period(this_period, previous_period) @daylight_period ||= Period.new("DAYLIGHT", this_period, previous_period) @@ -57,9 +71,9 @@ def log_period(period) @periods ||= [] @periods << period unless @periods.include?(period) end - - def add_period(this_period) - if @previous_period + + def add_period(this_period, force=false) + if @previous_period || force if this_period.dst? period = daylight_period(this_period, @previous_period) else @@ -81,7 +95,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) @tzinfo_timezone.local_to_utc(time.to_ri_cal_ruby_value) @@ -110,13 +124,15 @@ def to_rfc2445_string(utc_start, utc_end) #:nodoc: def export_utc_to(export_stream, utc_start, utc_end) #:nodoc: export_stream.puts "BEGIN:VTIMEZONE","TZID;X-RICAL-TZSOURCE=TZINFO:#{identifier}" periods = Periods.new - period = tzinfo_timezone.period_for_utc(utc_start) + period = initial_period = tzinfo_timezone.period_for_utc(utc_start) #start with the period before the one containing utc_start - period = tzinfo_timezone.period_for_utc(period.utc_start - 1) - while period && period.utc_start < utc_end + prev_period = period.utc_start && tzinfo_timezone.period_for_utc(period.utc_start - 1) + period = prev_period if prev_period + while period && period.utc_start && period.utc_start < utc_end periods.add_period(period) period = period.utc_end && tzinfo_timezone.period_for_utc(period.utc_end + 1) end + periods.add_period(initial_period, :force) if periods.empty? periods.export_to(export_stream) export_stream.puts "END:VTIMEZONE\n" end diff --git a/ri_cal.gemspec b/ri_cal.gemspec index 0e7078d5..2e38b197 100644 --- a/ri_cal.gemspec +++ b/ri_cal.gemspec @@ -2,11 +2,11 @@ Gem::Specification.new do |s| s.name = %q{ri_cal} - s.version = "0.6.2" + s.version = "0.6.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["author=Rick DeNatale"] - s.date = %q{2009-06-11} + s.date = %q{2009-06-14} s.default_executable = %q{ri_cal} s.description = %q{A new Ruby implementation of RFC2445 iCalendar. diff --git a/spec/ri_cal/component/t_z_info_timezone_spec.rb b/spec/ri_cal/component/t_z_info_timezone_spec.rb index 2e411b7a..0b966522 100644 --- a/spec/ri_cal/component/t_z_info_timezone_spec.rb +++ b/spec/ri_cal/component/t_z_info_timezone_spec.rb @@ -1,8 +1,9 @@ #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license require File.join(File.dirname(__FILE__), %w[.. .. spec_helper]) -require 'rubygems' -require 'tzinfo' +# Uncomment the next two lines to run this spec in textmate +# require 'rubygems' +# require 'tzinfo' describe RiCal::Component::TZInfoTimezone do @@ -33,4 +34,26 @@ END:VTIMEZONE ENDDATA end + + TZInfo::Timezone.all_identifiers.each do |tz| + context "TZInfo timezone #{tz}" do + before(:each) do + @calendar = RiCal.Calendar do |cal| + cal.event do |event| + event.description = "test" + event.dtstart = "TZID=#{tz}:20090530T123000" + event.dtend = "TZID=#{tz}:20090530T123001" + end + end + end + it "should be allowed as a tzid" do + lambda {@calendar.export}.should_not raise_error + end + unless tz == "UTC" + it "should produce at least one period in the VTIMEZONE" do + @calendar.export.should match(/BEGIN:(STANDARD|DAYLIGHT)/) + end + end + end + end end \ No newline at end of file diff --git a/website/index.html b/website/index.html index 3f7a96fe..2ca3a710 100644 --- a/website/index.html +++ b/website/index.html @@ -34,7 +34,7 @@

RiCal