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:



95
96
97
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 95

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:



93
94
95
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 93

def tzinfo_timezone
  @tzinfo_timezone
end

Instance Method Details

#export_local_to(export_stream, local_start, local_end) ⇒ Object

:nodoc:



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

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), local_to_utc(local_end.to_ri_cal_ruby_value))
end

#export_utc_to(export_stream, utc_start, utc_end) ⇒ Object

:nodoc:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 124

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



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

def identifier
  @tzinfo_timezone.identifier
end

#local_to_utc(time) ⇒ Object

convert time from this time zone to utc time



100
101
102
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 100

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

#to_rfc2445_string(utc_start, utc_end) ⇒ Object

:nodoc:



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

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



105
106
107
# File 'lib/ri_cal/component/t_z_info_timezone.rb', line 105

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