Class: Icalendar::Values::DateTime
- Inherits:
-
Icalendar::Value
- Object
- SimpleDelegator
- Icalendar::Value
- Icalendar::Values::DateTime
- Includes:
- TimeWithZone
- Defined in:
- lib/icalendar/values/date_time.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- FORMAT =
'%Y%m%dT%H%M%S'
Instance Attribute Summary
Attributes included from TimeWithZone
Attributes inherited from Icalendar::Value
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(value, params = {}) ⇒ DateTime
constructor
A new instance of DateTime.
- #utc? ⇒ Boolean
- #value_ical ⇒ Object
Methods included from TimeWithZone
Methods inherited from Icalendar::Value
#ical_param, #params_ical, #to_ical, #value, value_type, #value_type
Constructor Details
#initialize(value, params = {}) ⇒ DateTime
Returns a new instance of DateTime.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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' begin parsed_date = ::DateTime.strptime(value, FORMAT) rescue ArgumentError => e raise FormatError.new("Failed to parse \"#{value}\" - #{e.}") end super parsed_date, params elsif value.respond_to? :to_datetime super value.to_datetime, params else super end end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/icalendar/values/date_time.rb', line 38 def <=>(other) if other.is_a?(Icalendar::Values::Date) || other.is_a?(Icalendar::Values::DateTime) value_ical <=> other.value_ical else nil end end |
#utc? ⇒ Boolean
46 47 48 |
# File 'lib/icalendar/values/date_time.rb', line 46 def utc? value.respond_to?(:utc?) ? value.utc? : value.to_time.utc? end |