class Date
Add workday and weekday concepts to the Date
class
Public Instance Methods
business_dates_until(to_date, inclusive = false, options={})
click to toggle source
# File lib/business_time/core_ext/date.rb, line 9 def business_dates_until(to_date, inclusive = false, options={}) if inclusive (self..to_date).select{|this_date| this_date.workday?(options)} else (self...to_date).select{|this_date| this_date.workday?(options)} end end
business_days_until(to_date, inclusive = false, options={})
click to toggle source
# File lib/business_time/core_ext/date.rb, line 5 def business_days_until(to_date, inclusive = false, options={}) business_dates_until(to_date, inclusive, options).size end
fiscal_month_offset()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 30 def fiscal_month_offset BusinessTime::Config.fiscal_month_offset end
fiscal_year()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 50 def fiscal_year month >= fiscal_month_offset ? year + 1 : year end
fiscal_year_month()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 40 def fiscal_year_month shifted_month = month - (fiscal_month_offset - 1) shifted_month += 12 if shifted_month <= 0 shifted_month end
fiscal_year_quarter()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 46 def fiscal_year_quarter ((fiscal_year_month - 1) / 3) + 1 end
fiscal_year_week()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 34 def fiscal_year_week fyw = ((fiscal_year_yday - 1) / 7) + 1 fyw = 52 if fyw == 53 fyw end
fiscal_year_yday()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 54 def fiscal_year_yday offset_days = 0 1.upto(fiscal_month_offset - 1) { |m| offset_days += ::Time.days_in_month(m, year) } shifted_year_day = yday - offset_days shifted_year_day += 365 if shifted_year_day <= 0 shifted_year_day end
quarter()
click to toggle source
# File lib/business_time/core_ext/date.rb, line 26 def quarter ((month - 1) / 3) + 1 end
week()
click to toggle source
Adapted from: github.com/activewarehouse/activewarehouse/blob/master/lib/active_warehouse/core_ext/time/calculations.rb
# File lib/business_time/core_ext/date.rb, line 20 def week cyw = ((yday - 1) / 7) + 1 cyw = 52 if cyw == 53 cyw end