Module: Icalendar::Values::TimeWithZone

Included in:
DateTime, Time
Defined in:
lib/icalendar/values/time_with_zone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tz_utcObject (readonly)

Returns the value of attribute tz_utc.



16
17
18
# File 'lib/icalendar/values/time_with_zone.rb', line 16

def tz_utc
  @tz_utc
end

Instance Method Details

#initialize(value, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/icalendar/values/time_with_zone.rb', line 18

def initialize(value, params = {})
  params = Icalendar::DowncasedHash(params)
  @tz_utc = params['tzid'] == 'UTC'
  x_tz_info = params.delete 'x-tz-info'

  offset_value = unless params['tzid'].nil?
    tzid = params['tzid'].is_a?(::Array) ? params['tzid'].first : params['tzid']
    if defined?(ActiveSupport::TimeZone) &&
        defined?(ActiveSupportTimeWithZoneAdapter) &&
        (tz = ActiveSupport::TimeZone[tzid])
      ActiveSupportTimeWithZoneAdapter.new(nil, tz, value)
    elsif !x_tz_info.nil?
      offset = x_tz_info.offset_for_local(value).to_s
      if value.respond_to?(:change)
        value.change offset: offset
      else
        ::Time.new value.year, value.month, value.day, value.hour, value.min, value.sec, offset
      end
    end
  end
  super((offset_value || value), params)
end

#params_icalObject



41
42
43
44
# File 'lib/icalendar/values/time_with_zone.rb', line 41

def params_ical
  ical_params.delete 'tzid' if tz_utc
  super
end