Module: HasHelpers::CoreExt::Date

Defined in:
lib/has_helpers/core_ext/date/infinity.rb,
lib/has_helpers/core_ext/date.rb

Defined Under Namespace

Modules: Infinity

Instance Method Summary collapse

Instance Method Details

#business_day?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/has_helpers/core_ext/date.rb', line 14

def business_day?
  # The holidays included in the holidays gem are:
  # [
  #   "New Year's Day", "Martin Luther King, Jr. Day", "Presidents' Day",
  #   "Memorial Day", "Independence Day", "Labor Day", "Columbus Day",
  #   "Veterans Day", "Thanksgiving", "Christmas Day"
  # ]
  !weekend? && !holiday?(:us)
end

#next_business_day(skip = 1) ⇒ Object

Finds the next business day, defined as a weekday that does not fall on a holiday



26
27
28
29
30
31
32
33
34
35
# File 'lib/has_helpers/core_ext/date.rb', line 26

def next_business_day(skip = 1)
  date = self
  skip.times do
    date = date + 1
    while !date.business_day?
      date = date + 1
    end
  end
  date
end

#weekend?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/has_helpers/core_ext/date.rb', line 10

def weekend?
  saturday? || sunday?
end