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.



6
7
8
# File 'lib/business_time/business_days.rb', line 6

def initialize(days)
  @days = days
end

Instance Method Details

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



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

def after(time = Time.now)
  time = Time.zone ? Time.zone.parse(time.strftime('%Y-%m-%d %H:%M:%S %z')) : Time.parse(time.strftime('%Y-%m-%d %H:%M:%S %z'))
  days = @days
  while days > 0 || !Time.workday?(time)
    days -= 1 if Time.workday?(time)
    time = time + 1.day
  end
  time
end

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



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

def before(time = Time.now)
  time = Time.zone ? Time.zone.parse(time.rfc822) : Time.parse(time.rfc822)
  days = @days
  while days > 0 || !Time.workday?(time)
    days -= 1 if Time.workday?(time)
    time = time - 1.day
  end
  time
end