Sha256: c0d2786fc83292f2f17efe94ea93441b8dd702be93e52f577e9ef607a704e2c2

Contents?: true

Size: 1.7 KB

Versions: 60

Compression:

Stored size: 1.7 KB

Contents

module RiCal
  class PropertyValue
    class DateTime
      #- ©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
      module AdditiveMethods
        #  if end_time is nil => nil
        #  otherwise convert end_time to a DateTime and compute the difference
        def duration_until(end_time) # :nodoc:
          end_time  && RiCal::PropertyValue::Duration.from_datetimes(timezone_finder, to_datetime, end_time.to_datetime)
        end

        # Double-dispatch method for subtraction.
        def subtract_from_date_time_value(dtvalue) #:nodoc:
          RiCal::PropertyValue::Duration.from_datetimes(timezone_finder, to_datetime,dtvalue.to_datetime)
        end

        # Double-dispatch method for addition.
        def add_to_date_time_value(date_time_value) #:nodoc:
          raise ArgumentError.new("Cannot add #{date_time_value} to #{self}")
        end

        # 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
        def -(other)
          other.subtract_from_date_time_value(self)
        end

        # 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
        def +(duration)
          duration.add_to_date_time_value(self)
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 8 rubygems

Version Path
demingfactor-ri_cal-0.10.0 lib/ri_cal/property_value/date_time/additive_methods.rb
demingfactor-ri_cal-0.9.0 lib/ri_cal/property_value/date_time/additive_methods.rb
ebeigarts-ri_cal-0.8.1 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.10 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.11 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.3 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.4 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.5 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.6 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.7 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.8 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.0.9 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.5.0 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.5.1 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.5.2 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.5.3 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.6.0 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.6.1 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.6.2 lib/ri_cal/property_value/date_time/additive_methods.rb
rubyredrick-ri_cal-0.6.3 lib/ri_cal/property_value/date_time/additive_methods.rb