Module: RiCal::CoreExtensions::DateTime::Conversions
- Included in:
- DateTime
- Defined in:
- lib/ri_cal/core_extensions/date_time/conversions.rb
Overview
-
©2009 Rick DeNatale
-
All rights reserved. Refer to the file README.txt for the license
Instance Method Summary collapse
-
#to_date ⇒ Object
Converts self to a Ruby Date object; time portion is discarded.
-
#to_datetime ⇒ Object
To be able to keep Times, Dates and DateTimes interchangeable on conversions.
-
#to_ri_cal_date_time_value(timezone_finder = nil) ⇒ Object
(also: #to_ri_cal_date_or_date_time_value, #to_ri_cal_occurrence_list_value)
Return an RiCal::PropertyValue::DateTime representing the receiver.
-
#to_ri_cal_property_value(timezone_finder = nil) ⇒ Object
Return the natural ri_cal_property for this object.
-
#to_time ⇒ Object
Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class If self has an offset other than 0, self will just be returned unaltered, since there’s no clean way to map it to a Time.
-
#with_floating_timezone ⇒ Object
Return a copy of this object which will be interpreted as a floating time.
Instance Method Details
#to_date ⇒ Object
Converts self to a Ruby Date object; time portion is discarded
32 33 34 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 32 def to_date ::Date.new(year, month, day) end |
#to_datetime ⇒ Object
To be able to keep Times, Dates and DateTimes interchangeable on conversions
43 44 45 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 43 def to_datetime self end |
#to_ri_cal_date_time_value(timezone_finder = nil) ⇒ Object Also known as: to_ri_cal_date_or_date_time_value, to_ri_cal_occurrence_list_value
Return an RiCal::PropertyValue::DateTime representing the receiver
10 11 12 13 14 15 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 10 def to_ri_cal_date_time_value(timezone_finder = nil) #:nodoc: RiCal::PropertyValue::DateTime.new( timezone_finder, :value => strftime("%Y%m%dT%H%M%S"), :params => {"TZID" => self.tzid || :default}) end |
#to_ri_cal_property_value(timezone_finder = nil) ⇒ Object
Return the natural ri_cal_property for this object
21 22 23 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 21 def to_ri_cal_property_value(timezone_finder = nil) #:nodoc: to_ri_cal_date_time_value(timezone_finder) end |
#to_time ⇒ Object
Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class If self has an offset other than 0, self will just be returned unaltered, since there’s no clean way to map it to a Time
38 39 40 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 38 def to_time self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self end |
#with_floating_timezone ⇒ Object
Return a copy of this object which will be interpreted as a floating time.
26 27 28 |
# File 'lib/ri_cal/core_extensions/date_time/conversions.rb', line 26 def with_floating_timezone dup.set_tzid(:floating) end |