Class: Icalendar::Values::Time

Inherits:
Icalendar::Value show all
Includes:
TimeWithZone
Defined in:
lib/icalendar/values/time.rb

Constant Summary collapse

FORMAT =
'%H%M%S'

Instance Attribute Summary

Attributes included from TimeWithZone

#tz_utc

Attributes inherited from Icalendar::Value

#ical_params

Instance Method Summary collapse

Methods included from TimeWithZone

#params_ical

Methods inherited from Icalendar::Value

#ical_param, #params_ical, #to_ical, #value, value_type, #value_type

Constructor Details

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

Returns a new instance of Time.



12
13
14
15
16
17
18
19
20
21
# File 'lib/icalendar/values/time.rb', line 12

def initialize(value, params = {})
  if value.is_a? String
    params['tzid'] = 'UTC' if value.end_with? 'Z'
    super ::DateTime.strptime(value, FORMAT).to_time, params
  elsif value.respond_to? :to_time
    super value.to_time, params
  else
    super
  end
end

Instance Method Details

#value_icalObject



23
24
25
26
27
28
29
# File 'lib/icalendar/values/time.rb', line 23

def value_ical
  if tz_utc
    "#{strftime FORMAT}Z"
  else
    strftime FORMAT
  end
end