Class: Icalendar::Values::Date

Inherits:
Icalendar::Value show all
Defined in:
lib/icalendar/values/date.rb

Defined Under Namespace

Classes: FormatError

Constant Summary collapse

FORMAT =
'%Y%m%d'

Constants inherited from Icalendar::Value

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

Instance Attribute Summary

Attributes inherited from Icalendar::Value

#context, #ical_params

Instance Method Summary collapse

Methods inherited from Icalendar::Value

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

Constructor Details

#initialize(value, params = {}, *args) ⇒ Date

Returns a new instance of Date.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/icalendar/values/date.rb', line 11

def initialize(value, params = {}, *args)
  params.delete 'tzid'
  if value.is_a? String
    begin
      parsed_date = ::Date.strptime(value, FORMAT)
    rescue ArgumentError => e
      raise FormatError.new("Failed to parse \"#{value}\" - #{e.message}")
    end

    super parsed_date, params, *args
  elsif value.respond_to? :to_date
    super value.to_date, params, *args
  else
    super
  end
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



28
29
30
# File 'lib/icalendar/values/date.rb', line 28

def value_ical
  value.strftime FORMAT
end