module RisingSun::Fiscali
Constants
- FISCAL_ZONE
- FY_START_MONTH
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/rising_sun/fiscali.rb, line 3 def self.included(base) base.extend ClassMethods end
Public Instance Methods
all_financial_quarter()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 120 def all_financial_quarter beginning_of_financial_quarter..end_of_financial_quarter end
all_financial_year()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 124 def all_financial_year beginning_of_financial_year..end_of_financial_year end
beginning_of_financial_half()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 108 def beginning_of_financial_half beginning_of_financial_year.months_since(((months_between / 6).floor) * 6) end
beginning_of_financial_quarter(quarter = nil)
click to toggle source
# File lib/rising_sun/fiscali.rb, line 98 def beginning_of_financial_quarter(quarter = nil) quarter = (months_between / 3).floor + 1 unless quarter.in? 1..4 beginning_of_financial_year.advance(months: (quarter - 1) * 3).beginning_of_month end
beginning_of_financial_year()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 63 def beginning_of_financial_year change(:year => year_of_financial_year_beginning, :month => start_month, :day => 1).beginning_of_month end
Also aliased as: beginning_of_financial_h1
end_of_financial_quarter(quarter = nil)
click to toggle source
# File lib/rising_sun/fiscali.rb, line 103 def end_of_financial_quarter(quarter = nil) quarter = (months_between / 3).floor + 1 unless quarter.in? 1..4 beginning_of_financial_year.advance(months: quarter * 3 - 1).end_of_month end
end_of_financial_year()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 67 def end_of_financial_year (beginning_of_financial_year + 1.year - 1.month).end_of_month end
Also aliased as: end_of_financial_h2
financial_half()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 86 def financial_half "H#{( months_between / 6 ).floor + 1} #{financial_year}" end
financial_month_of(month)
click to toggle source
# File lib/rising_sun/fiscali.rb, line 128 def financial_month_of(month) if month < start_month Date.new(year+1,month,1) else Date.new(year,month,1) end end
financial_quarter()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 82 def financial_quarter "Q#{( months_between / 3 ).floor + 1} #{financial_year}" end
financial_year()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 53 def financial_year if january_start_month? self.year elsif self.class.uses_forward_year? self.month < start_month ? self.year : self.year + 1 else self.month < start_month ? self.year - 1 : self.year end end
next_financial_half()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 94 def next_financial_half beginning_of_financial_year.months_since(((months_between / 6).floor + 1) * 6) end
next_financial_quarter()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 90 def next_financial_quarter beginning_of_financial_year.months_since(((months_between / 3).floor + 1 ) * 3) end
previous_financial_half()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 116 def previous_financial_half beginning_of_financial_half.months_ago(6) end
previous_financial_quarter()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 112 def previous_financial_quarter beginning_of_financial_quarter.months_ago(3) end
Private Instance Methods
january_start_month?()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 146 def january_start_month? start_month == 1 end
months_between()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 150 def months_between soy = self.beginning_of_financial_year (self.month - soy.month) + 12 * (self.year - soy.year) end
start_month()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 155 def start_month self.class.fy_start_month || FY_START_MONTH end
year_of_financial_year_beginning()
click to toggle source
# File lib/rising_sun/fiscali.rb, line 138 def year_of_financial_year_beginning if self.class.uses_forward_year? && !january_start_month? financial_year - 1 else financial_year end end