Permalink
Browse files

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
  • Loading branch information...
1 parent 3930187 commit 9b5d3d348e118921448b7b1b8d732cb2c87e65a3 @rubyredrick committed Jun 15, 2009
View
@@ -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
View
@@ -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
@@ -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
View
@@ -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.
@@ -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
View
@@ -34,7 +34,7 @@
<div class="sidebar">
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ri-cal"; return false'>
<p>Get Version</p>
- <a href="http://rubyforge.org/projects/ri-cal" class="numbers">0.6.2</a>
+ <a href="http://rubyforge.org/projects/ri-cal" class="numbers">0.6.3</a>
<p>
<a href='http://www.pledgie.com/campaigns/4360'><img alt='Click here to lend your support to: ri_cal and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/4360.png?skin_name=chrome' border='0' /></a>
</p>

0 comments on commit 9b5d3d3

Please sign in to comment.