Class: Icalendar::Values::Time

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

Constant Summary collapse

FORMAT =
'%H%M%S'

Constants inherited from Icalendar::Value

Icalendar::Value::VALUE_TYPE_GSUB_REGEX_1, Icalendar::Value::VALUE_TYPE_GSUB_REGEX_2

Instance Attribute Summary

Attributes included from Helpers::TimeWithZone

#timezone_store, #tz_utc

Attributes inherited from Icalendar::Value

#ical_params

Instance Method Summary collapse

Methods included from Helpers::TimeWithZone

#__getobj__, #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.



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

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



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

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