Module: RiCal::PropertyValue::DateTime::AdditiveMethods
- Included in:
- RiCal::PropertyValue::DateTime
- Defined in:
- lib/ri_cal/property_value/date_time/additive_methods.rb
Overview
Methods for DateTime which support adding or subtracting another DateTime or Duration
Instance Method Summary collapse
-
#+(duration) ⇒ Object
Return the sum of the receiver and duration.
-
#-(other) ⇒ Object
Return the difference between the receiver and other.
-
#add_to_date_time_value(date_time_value) ⇒ Object
Double-dispatch method for addition.
-
#duration_until(end_time) ⇒ Object
if end_time is nil => nil otherwise convert end_time to a DateTime and compute the difference.
-
#subtract_from_date_time_value(dtvalue) ⇒ Object
Double-dispatch method for subtraction.
Instance Method Details
#+(duration) ⇒ Object
Return the sum of the receiver and duration
The parameter other duration should be a RiCal::PropertyValue::Duration
The result will be an RiCal::PropertyValue::DateTime
36 37 38 |
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 36 def +(duration) duration.add_to_date_time_value(self) end |
#-(other) ⇒ Object
Return the difference between the receiver and other
The parameter other should be either a RiCal::PropertyValue::Duration or a RiCal::PropertyValue::DateTime
If other is a Duration, the result will be a DateTime, if it is a DateTime the result will be a Duration
27 28 29 |
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 27 def -(other) other.subtract_from_date_time_value(self) end |
#add_to_date_time_value(date_time_value) ⇒ Object
Double-dispatch method for addition.
18 19 20 |
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 18 def add_to_date_time_value(date_time_value) #:nodoc: raise ArgumentError.new("Cannot add #{date_time_value} to #{self}") end |
#duration_until(end_time) ⇒ Object
if end_time is nil => nil
otherwise convert end_time to a DateTime and compute the difference
8 9 10 |
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 8 def duration_until(end_time) # :nodoc: end_time && RiCal::PropertyValue::Duration.from_datetimes(timezone_finder, to_datetime, end_time.to_datetime) end |
#subtract_from_date_time_value(dtvalue) ⇒ Object
Double-dispatch method for subtraction.
13 14 15 |
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 13 def subtract_from_date_time_value(dtvalue) #:nodoc: RiCal::PropertyValue::Duration.from_datetimes(timezone_finder, to_datetime,dtvalue.to_datetime) end |