Module: RiCal::CoreExtensions::Date::Conversions
- Included in:
- Date
- Defined in:
- lib/ri_cal/core_extensions/date/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
A method to keep Time, Date and DateTime instances interchangeable on conversions.
-
#to_datetime ⇒ Object
Converts a Date instance to a DateTime, where the time is set to the beginning of the day and UTC offset is set to 0.
-
#to_ri_cal_date_time_value(timezone_finder = nil) ⇒ Object
Return an RiCal::PropertyValue::DateTime representing the receiver.
-
#to_ri_cal_date_value(timezone_finder = nil) ⇒ Object
(also: #to_ri_cal_date_or_date_time_value, #to_ri_cal_occurrence_list_value)
Return an RiCal::PropertyValue::Date representing the receiver.
-
#to_ri_cal_property_value(timezone_finder = nil) ⇒ Object
Return the natural ri_cal_property for this object.
-
#to_time(form = :local) ⇒ Object
Converts a Date instance to a Time, where the time is set to the beginning of the day.
Instance Method Details
#to_date ⇒ Object
A method to keep Time, Date and DateTime instances interchangeable on conversions. In this case, it simply returns self.
29 30 31 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 29 def to_date self end |
#to_datetime ⇒ Object
Converts a Date instance to a DateTime, where the time is set to the beginning of the day and UTC offset is set to 0.
Examples
date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
54 55 56 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 54 def to_datetime ::DateTime.civil(year, month, day, 0, 0, 0, 0) end |
#to_ri_cal_date_time_value(timezone_finder = nil) ⇒ Object
Return an RiCal::PropertyValue::DateTime representing the receiver
9 10 11 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 9 def to_ri_cal_date_time_value(timezone_finder = nil) RiCal::PropertyValue::DateTime.new(timezone_finder, :value => self) end |
#to_ri_cal_date_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::Date representing the receiver
14 15 16 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 14 def to_ri_cal_date_value(timezone_finder = nil) RiCal::PropertyValue::Date.new(timezone_finder, :value => self) end |
#to_ri_cal_property_value(timezone_finder = nil) ⇒ Object
Return the natural ri_cal_property for this object
22 23 24 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 22 def to_ri_cal_property_value(timezone_finder = nil) to_ri_cal_date_value(timezone_finder) end |
#to_time(form = :local) ⇒ Object
Converts a Date instance to a Time, where the time is set to the beginning of the day. The timezone can be either :local or :utc (default :local).
Examples
date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
date.to_time # => Sat Nov 10 00:00:00 0800 2007
date.to_time(:local) # => Sat Nov 10 00:00:00 0800 2007
date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007
43 44 45 |
# File 'lib/ri_cal/core_extensions/date/conversions.rb', line 43 def to_time(form = :local) ::Time.send("#{form}_time", year, month, day) end |