Class: Date

Inherits:
Object
  • Object
show all
Includes:
BusinessTime::TimeExtensions
Defined in:
lib/business_time/core_ext/date.rb

Overview

Add workday and weekday concepts to the Date class

Instance Method Summary collapse

Methods included from BusinessTime::TimeExtensions

#business_time_until, #consecutive_non_working_days, #consecutive_workdays, #during_business_hours?, #weekday?, #workday?

Instance Method Details

#business_dates_until(to_date, inclusive = false) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/business_time/core_ext/date.rb', line 9

def business_dates_until(to_date, inclusive = false)
  if inclusive
    (self..to_date).select(&:workday?)
  else
    (self...to_date).select(&:workday?)
  end
end

#business_days_until(to_date, inclusive = false) ⇒ Object



5
6
7
# File 'lib/business_time/core_ext/date.rb', line 5

def business_days_until(to_date, inclusive = false)
  business_dates_until(to_date, inclusive).size
end

#fiscal_month_offsetObject



30
31
32
# File 'lib/business_time/core_ext/date.rb', line 30

def fiscal_month_offset
  BusinessTime::Config.fiscal_month_offset
end

#fiscal_yearObject



50
51
52
# File 'lib/business_time/core_ext/date.rb', line 50

def fiscal_year
  month >= fiscal_month_offset ? year + 1 : year
end

#fiscal_year_monthObject



40
41
42
43
44
# 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_quarterObject



46
47
48
# File 'lib/business_time/core_ext/date.rb', line 46

def fiscal_year_quarter
  ((fiscal_year_month - 1) / 3) + 1
end

#fiscal_year_weekObject



34
35
36
37
38
# 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_ydayObject



54
55
56
57
58
59
60
# 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

#quarterObject



26
27
28
# File 'lib/business_time/core_ext/date.rb', line 26

def quarter
  ((month - 1) / 3) + 1
end

#weekObject



20
21
22
23
24
# File 'lib/business_time/core_ext/date.rb', line 20

def week
  cyw = ((yday - 1) / 7) + 1
  cyw = 52 if cyw == 53
  cyw
end