Class: Icalendar::Values::DateTime

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

Constant Summary collapse

FORMAT =
'%Y%m%dT%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

Constructor Details

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

Returns a new instance of DateTime.



12
13
14
15
16
17
18
19
20
21
# File 'lib/icalendar/values/date_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), params
  elsif value.respond_to? :to_datetime
    super value.to_datetime, params
  else
    super
  end
end

Instance Method Details

#<=>(other) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/icalendar/values/date_time.rb', line 31

def <=>(other)
  if other.is_a?(Icalendar::Values::Date) || other.is_a?(Icalendar::Values::DateTime)
    value_ical <=> other.value_ical
  else
    nil
  end
end

#value_icalObject



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

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