Skip to content

Commit

Permalink
fix tzinfo timezone export
Browse files Browse the repository at this point in the history
  • Loading branch information
rubyredrick committed Apr 16, 2010
1 parent c948343 commit ef42601
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
20 changes: 17 additions & 3 deletions lib/ri_cal/component/t_z_info_timezone.rb
Expand Up @@ -10,19 +10,31 @@ class Period #:nodoc: all

def initialize(which, this_period, prev_period)
@which = which
@onset = period_local_start(this_period)
if prev_period
@onset = period_local_end(prev_period)
@offset_from = format_rfc2445_offset(prev_period.utc_total_offset)
else
@onset = period_local_start(this_period)
@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 daylight?
@which == "DAYLIGHT"
end

def period_local_end(period)
(period.local_end || 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)
(period.local_start || DateTime.parse("16010101T000000")).strftime("%Y%m%dT%H%M%S")
shift = daylight? ? Rational(-1, 24) : Rational(1, 24)
((period.local_start || DateTime.parse("16010101T000000")) + shift).strftime("%Y%m%dT%H%M%S")
end

def add_period(this_period)
Expand All @@ -41,7 +53,9 @@ def format_rfc2445_offset(seconds) #:nodoc:
def export_to(export_stream)
export_stream.puts "BEGIN:#{@which}"
export_stream.puts "DTSTART:#{@onset}"
export_stream.puts "RDATE:#{@rdates.join(",")}"
@rdates.each do |rdate|
export_stream.puts "RDATE:#{rdate}"
end
export_stream.puts "TZOFFSETFROM:#{@offset_from}"
export_stream.puts "TZOFFSETTO:#{@offset_to}"
export_stream.puts "TZNAME:#{@abbreviation}"
Expand Down
9 changes: 5 additions & 4 deletions spec/ri_cal/component/t_z_info_timezone_spec.rb
Expand Up @@ -18,15 +18,16 @@
BEGIN:VTIMEZONE
TZID;X-RICAL-TZSOURCE=TZINFO:America/New_York
BEGIN:DAYLIGHT
DTSTART:20070311T030000
RDATE:20070311T030000,20080309T030000
DTSTART:20070311T020000
RDATE:20070311T020000
RDATE:20080309T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:20071104T010000
RDATE:20071104T010000
DTSTART:20071104T020000
RDATE:20071104T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
Expand Down
6 changes: 3 additions & 3 deletions spec/ri_cal/parser_spec.rb
Expand Up @@ -233,13 +233,13 @@ def self.describe_named_property(entity_name, prop_text, prop_name, params, valu
describe_multi_property("VEVENT", "RRULE", {"X-FOO" => "BAR"}, "FREQ=DAILY;COUNT=10", RiCal::PropertyValue::RecurrenceRule)

#RFC 2445 section 4.8.7.1 CREATED p129
describe_property("VEVENT", "CREATED", {"X-FOO" => "BAR"}, "19960329T133000Z", RiCal::PropertyValue::DateTime)
describe_property("VEVENT", "CREATED", {"X-FOO" => "BAR"}, "19960329T133000Z", RiCal::PropertyValue::ZuluDateTime)

#RFC 2445 section 4.8.7.2 DTSTAMP p129
describe_property("VEVENT", "DTSTAMP", {"X-FOO" => "BAR"}, "19971210T080000Z", RiCal::PropertyValue::DateTime)
describe_property("VEVENT", "DTSTAMP", {"X-FOO" => "BAR"}, "19971210T080000Z", RiCal::PropertyValue::ZuluDateTime)

#RFC 2445 section 4.8.7.3 LAST-MODIFIED p131
describe_property("VEVENT", "LAST-MODIFIED", {"X-FOO" => "BAR"}, "19960817T133000Z", RiCal::PropertyValue::DateTime)
describe_property("VEVENT", "LAST-MODIFIED", {"X-FOO" => "BAR"}, "19960817T133000Z", RiCal::PropertyValue::ZuluDateTime)

#RFC 2445 section 4.8.7.3 SEQUENCE p131
describe_property("VEVENT", "SEQUENCE", {"X-FOO" => "BAR"}, 2, RiCal::PropertyValue::Integer)
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -40,7 +40,6 @@ def rectify_ical(string)
def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
DateTime.civil(year, month, day, hour, min, sec,
offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate_offset)).in_time_zone(tzid)
puts "#{result} #{result.inspect}"
end
else
def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
Expand Down

0 comments on commit ef42601

Please sign in to comment.