Module: RisingSun::Fiscali

Defined in:
lib/rising_sun/fiscali.rb,
lib/rising_sun/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

FISCAL_ZONE =
{:india => 4, :uk => 4, :us => 10, :pakistan => 7,
:australia => 7, :ireland => 1, :nz => 7, :japan => 4}
FY_START_MONTH =
1
VERSION =
"2.4.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/rising_sun/fiscali.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#all_financial_quarterObject



120
121
122
# File 'lib/rising_sun/fiscali.rb', line 120

def all_financial_quarter
  beginning_of_financial_quarter..end_of_financial_quarter
end

#all_financial_yearObject



124
125
126
# File 'lib/rising_sun/fiscali.rb', line 124

def all_financial_year
  beginning_of_financial_year..end_of_financial_year
end

#beginning_of_financial_halfObject



108
109
110
# 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) ⇒ Object



98
99
100
101
# 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_yearObject Also known as: beginning_of_financial_h1



63
64
65
# 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

#end_of_financial_quarter(quarter = nil) ⇒ Object



103
104
105
106
# 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_yearObject Also known as: end_of_financial_h2



67
68
69
# 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

#financial_halfObject



86
87
88
# File 'lib/rising_sun/fiscali.rb', line 86

def financial_half
  "H#{( months_between / 6 ).floor + 1} #{financial_year}"
end

#financial_month_of(month) ⇒ Object



128
129
130
131
132
133
134
# 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_quarterObject



82
83
84
# File 'lib/rising_sun/fiscali.rb', line 82

def financial_quarter
  "Q#{( months_between / 3 ).floor + 1} #{financial_year}"
end

#financial_yearObject



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



94
95
96
# 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_quarterObject



90
91
92
# 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_halfObject



116
117
118
# File 'lib/rising_sun/fiscali.rb', line 116

def previous_financial_half
  beginning_of_financial_half.months_ago(6)
end

#previous_financial_quarterObject



112
113
114
# File 'lib/rising_sun/fiscali.rb', line 112

def previous_financial_quarter
  beginning_of_financial_quarter.months_ago(3)
end