Class: RiCal::Component::TZInfoTimezone

Inherits:
Timezone show all
Defined in:
lib/ri_cal/component/t_z_info_timezone.rb

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

A wrapper class for a Timezone implemented by the TZInfo Gem (or by Rails)

Defined Under Namespace

Classes: Period, Periods

Instance Attribute Summary collapse

Attributes inherited from RiCal::Component

#imported

Instance Method Summary collapse

Methods inherited from Timezone

#name, #period_for_local, #period_for_utc, #periods_for_local, #rational_utc_offset

Methods included from Properties::Timezone

#==, #add_date_times_to, #export_properties_to, included, #initialize_copy, #last_modified, #last_modified=, #last_modified_property, #last_modified_property=, #last_modified_property_from_string, #mutual_exclusion_violation, #tzid, #tzid=, #tzid_property, #tzid_property=, #tzid_property_from_string, #tzurl, #tzurl=, #tzurl_property, #tzurl_property=, #tzurl_property_from_string

Methods inherited from RiCal::Component

#add_property_date_times_to, #add_subcomponent, #add_x_property, #alarms, #daylight, #default_tzid, entity_name, #entity_name, #export, #export_prop_to, #export_subcomponent_to, #export_to, #export_x_properties_to, #find_timezone, from_parser, #imported?, #initialize_copy, #last_before_local, #last_before_utc, #last_period, #method_missing, parse, parse_string, #parse_subcomponent, #process_line, #prop_string, #standard, #subcomponent_class, #subcomponents, #time_zone_for, #to_s, #tz_info_source?, #valid?, #x_properties

Constructor Details

#initialize(tzinfo_timezone) ⇒ TZInfoTimezone

:nodoc:



109
110
111
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 109

def initialize(tzinfo_timezone) #:nodoc:
  @tzinfo_timezone = tzinfo_timezone
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RiCal::Component

Instance Attribute Details

#tzinfo_timezoneObject (readonly)

:nodoc:



107
108
109
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 107

def tzinfo_timezone
  @tzinfo_timezone
end

Instance Method Details

#export_local_to(export_stream, local_start, local_end) ⇒ Object

:nodoc:



128
129
130
131
132
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 128

def export_local_to(export_stream, local_start, local_end) #:nodoc:
  export_utc_to(export_stream, 
                local_to_utc(local_start.to_ri_cal_ruby_value, true), 
                local_to_utc(local_end.to_ri_cal_ruby_value, false))
end

#export_utc_to(export_stream, utc_start, utc_end) ⇒ Object

:nodoc:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 140

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 = 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)
  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

#identifierObject

return the time zone identifier



124
125
126
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 124

def identifier
  @tzinfo_timezone.identifier
end

#local_to_utc(time, dst_ambiguity = nil) ⇒ Object

convert time from this time zone to utc time



114
115
116
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 114

def local_to_utc(time, dst_ambiguity=nil)
  @tzinfo_timezone.local_to_utc(time.to_ri_cal_ruby_value, dst_ambiguity)
end

#to_rfc2445_string(utc_start, utc_end) ⇒ Object

:nodoc:



134
135
136
137
138
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 134

def to_rfc2445_string(utc_start, utc_end) #:nodoc:
  export_stream = StringIO.new
  export_utc_to(export_stream, utc_start, utc_end)
  export_stream.string
end

#utc_to_local(time) ⇒ Object

convert time from utc time to this time zone



119
120
121
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 119

def utc_to_local(time)
  @tzinfo_timezone.utc_to_local(time.to_ri_cal_ruby_value)
end