Module: BusinessDays::Time::Calculations

Included in:
Time
Defined in:
lib/business_days/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



4
5
6
7
8
9
10
11
12
13
# File 'lib/business_days/time.rb', line 4

def self.included(base) #:nodoc:

  base.class_eval do
    alias_method :plus_without_business_days, :+
    alias_method :+, :plus_with_business_days

    alias_method :minus_without_business_days, :-
    alias_method :-, :minus_with_business_days
  end
end

Instance Method Details

#is_business_day?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/business_days/time.rb', line 15

def is_business_day?
  # TODO: Holidays.
  ! [0,6].include?(self.wday)
end

#minus_with_business_days(other) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/business_days/time.rb', line 28

def minus_with_business_days(other)
  if BusinessDays::BusinessDayDuration === other
    other.calculate_duration(self, :-)
  else
    minus_without_business_days(other)
  end
end

#plus_with_business_days(other) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/business_days/time.rb', line 20

def plus_with_business_days(other)
  if BusinessDays::BusinessDayDuration === other
    other.calculate_duration(self, :+)
  else
    plus_without_business_days(other)
  end
end