module Workdays

This module contains methods to help with dates

Constants

DEFAULT_LOCALE
VERSION

Public Class Methods

days_in(start_time, end_time) click to toggle source

Inclusive of start and end dates

# File lib/workdays/time_extensions.rb, line 51
def days_in(start_time, end_time)
  (end_time.to_date - start_time.to_date).to_i + 1
end
workdays_in(start_time, end_time, locale = DEFAULT_LOCALE) click to toggle source
# File lib/workdays/time_extensions.rb, line 42
def workdays_in(start_time, end_time, locale = DEFAULT_LOCALE)
  total_days = days_in(start_time, end_time)
  weekends   = weekends_in(start_time, end_time)
  holidays   = non_weekend_holidays_in(start_time, end_time, locale)

  total_days - weekends - holidays
end

Private Class Methods

non_weekend_holidays_in(start_time, end_time, locale = DEFAULT_LOCALE) click to toggle source
# File lib/workdays/time_extensions.rb, line 59
        def non_weekend_holidays_in(start_time, end_time, locale = DEFAULT_LOCALE)
  start_date  = start_time.to_date
  end_date    = end_time.to_date

  Holidays.between(start_date, end_date, locale, :observed).map do |holiday|
    holiday[:date].on_weekday?
  end.count(true)
end
weekends_in(start_time, end_time) click to toggle source
# File lib/workdays/time_extensions.rb, line 55
        def weekends_in(start_time, end_time)
  (start_time..end_time).map(&:on_weekend?).count(true)
end