Skip to content

Commit

Permalink
Merge pull request #16 from mxie/mx-january-start
Browse files Browse the repository at this point in the history
Return the same financial year when the start month is January
  • Loading branch information
Aditya Sanghi committed Dec 5, 2015
2 parents 387bd16 + f949e51 commit 2012420
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rising_sun/fiscali.rb
Expand Up @@ -51,7 +51,9 @@ def uses_forward_year?
end

def financial_year
if self.class.uses_forward_year?
if start_month == 1
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
Expand Down
22 changes: 22 additions & 0 deletions spec/fiscali_spec.rb
Expand Up @@ -160,4 +160,26 @@
thread.join
expect(thread['my_fiscal_zone']).to eql(:india)
end

context "when the start month is January" do
around :each do |example|
old_fy_start_month = Date.fy_start_month
Date.fy_start_month = 1
@date = Date.new(2014, 1, 1)
example.run
Date.fy_start_month = old_fy_start_month
end

it "returns the date's year as the financial year" do
expect(@date.financial_year).to eql(2014)
end

context "when using forward year" do
it "returns the date's year as the financial year" do
Date.use_forward_year!
expect(@date.financial_year).to eql(2014)
Date.reset_forward_year!
end
end
end
end

0 comments on commit 2012420

Please sign in to comment.