Module: RiCal::PropertyValue::DateTime::AdditiveMethods

Included in:
RiCal::PropertyValue::DateTime
Defined in:
lib/ri_cal/property_value/date_time/additive_methods.rb

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

Methods for DateTime which support adding or subtracting another DateTime or Duration

Instance Method Summary collapse

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



38
39
40
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 38

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



29
30
31
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 29

def -(other)
  other.subtract_from_date_time_value(self)
end

#add_to_date_time_value(date_time_value) ⇒ Object

Double-dispatch method for addition.

Raises:

  • (ArgumentError)


20
21
22
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 20

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


10
11
12
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 10

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.



15
16
17
# File 'lib/ri_cal/property_value/date_time/additive_methods.rb', line 15

def subtract_from_date_time_value(dtvalue) #:nodoc:
  RiCal::PropertyValue::Duration.from_datetimes(timezone_finder, to_datetime,dtvalue.to_datetime)
end