Class: Icalendar::Values::DateTime
- Inherits:
-
Icalendar::Value
- Object
- SimpleDelegator
- Icalendar::Value
- Icalendar::Values::DateTime
- Includes:
- Helpers::TimeWithZone
- Defined in:
- lib/icalendar/values/date_time.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- FORMAT =
'%Y%m%dT%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
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 Helpers::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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/icalendar/values/date_time.rb', line 14 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
40 41 42 43 44 45 46 |
# File 'lib/icalendar/values/date_time.rb', line 40 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
48 49 50 |
# File 'lib/icalendar/values/date_time.rb', line 48 def utc? value.respond_to?(:utc?) ? value.utc? : value.to_time.utc? end |