Class: BusinessTime::BusinessDays

Inherits:
Object
  • Object
show all
Defined in:
lib/business_time/business_days.rb

Instance Method Summary collapse

Constructor Details

#initialize(days) ⇒ BusinessDays

Returns a new instance of BusinessDays.



4
5
6
# File 'lib/business_time/business_days.rb', line 4

def initialize(days)
  @days = days
end

Instance Method Details

#after(time = Time.now) ⇒ Object Also known as: from_now, since



8
9
10
11
12
13
14
15
16
# File 'lib/business_time/business_days.rb', line 8

def after(time = Time.now)
  time = Time.zone ? Time.zone.parse(time.to_s) : Time.parse(time.to_s)
  @days.times do
    begin
      time = time + 1.day
    end until Time.workday?(time)
  end
  time
end

#before(time = Time.now) ⇒ Object Also known as: ago, until



21
22
23
24
25
26
27
28
29
# File 'lib/business_time/business_days.rb', line 21

def before(time = Time.now)
  time = Time.zone ? Time.zone.parse(time.to_s) : Time.parse(time.to_s)
  @days.times do
    begin
      time = time - 1.day
    end until Time.workday?(time)
  end
  time
end