fiscali 2.3.0 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +22 -0
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/CHANGELOG +6 -0
- data/LICENSE +18 -17
- data/README.markdown +45 -27
- data/fiscali.gemspec +3 -3
- data/lib/rising_sun/fiscali.rb +25 -4
- data/lib/rising_sun/version.rb +1 -1
- data/spec/fiscali_spec.rb +132 -65
- data/spec/spec_helper.rb +3 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 81069ed1f2eb4751cf14a55df03ad0df6dabec33b87a22ab1b718c5eb09180a3
|
4
|
+
data.tar.gz: 50eb72e9af40e2d8974d6faca52291a448bcff138afa40331fd93e6425b1c64b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c099b90e42efbf2e0d3698c0370113a5cb17d22bb8bd8e35f710fb913f2396d431a90d6bcc275cd386395724d58fab093fe2d14ebc34273c5f2af47bc074c1d
|
7
|
+
data.tar.gz: 17c5627351ee9bca5d7998f6b820677972a5baa6b9f36530e3fd446c3e63138d9414d8fed01caab7e8a75ae3bc1b4d0086c2f8c438073f90b1854e9142002327
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: 'CI'
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request: ~
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
run-tests:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
rubyversion: ['2.5', '2.6', '2.7', '3.0']
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: set up ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.rubyversion }}
|
20
|
+
bundler-cache: true
|
21
|
+
- name: run tests
|
22
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/LICENSE
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
Copyright (c) 2009 Aditya Sanghi
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,55 +1,67 @@
|
|
1
1
|
# Fiscali: Fiscal Year based calculations
|
2
2
|
|
3
|
-
Fiscali provides
|
3
|
+
Fiscali provides methods on your Date and Time classes to jump around dates in your Financial Year.
|
4
4
|
|
5
|
-
|
6
|
-
* Not sure it's a point to be said, but YES, you can specify your financial year zone and if you dont know your zone, just provide the first month your financial year to the Date/Time class.
|
5
|
+
You can specify your financial year zone and if you don’t know your zone, just provide the month your financial year begins.
|
7
6
|
|
8
7
|
## Quick Links
|
9
8
|
|
10
|
-
* [Wiki](
|
11
|
-
* [Bugs](
|
12
|
-
* [Donate](
|
9
|
+
* [Wiki](https://github.com/asanghi/fiscali/wiki)
|
10
|
+
* [Bugs](https://github.com/asanghi/fiscali/issues)
|
11
|
+
* [Donate](https://pledgie.org/campaigns/5400)
|
13
12
|
|
14
13
|
## Installing
|
15
14
|
|
16
|
-
|
15
|
+
gem install fiscali
|
17
16
|
|
18
17
|
## Using in your Rails project
|
19
18
|
|
20
|
-
In Rails projects, include
|
19
|
+
In Rails projects, include Fiscali in the Gemfile, and run `bundle install` to install the gem:
|
21
20
|
|
22
|
-
gem
|
21
|
+
gem 'fiscali'
|
23
22
|
|
24
|
-
Next
|
23
|
+
Next, create an initializer for configuration Fiscali:
|
24
|
+
|
25
|
+
config/initializers/fiscali.rb
|
26
|
+
|
27
|
+
Either provide your Date/Time class your start zone:
|
25
28
|
|
26
29
|
Date.fiscal_zone = :india
|
27
|
-
Time.fiscal_zone = :india
|
28
|
-
or
|
29
|
-
Date.start_month = 4
|
30
30
|
|
31
|
-
|
31
|
+
Or if set the exact start month—for example, April:
|
32
|
+
|
33
|
+
Date.fy_start_month = 4
|
34
|
+
|
35
|
+
You can also determine the default for Year Forward by adding this to the same initializer file:
|
32
36
|
|
33
37
|
Date.use_forward_year!
|
34
38
|
Time.use_forward_year!
|
35
39
|
|
36
|
-
|
40
|
+
To revert back to the default:
|
37
41
|
|
38
42
|
Date.reset_forward_year!
|
39
43
|
Time.reset_forward_year!
|
40
44
|
|
41
|
-
Year Forward refers to the standard name for a fiscal year. For example:
|
42
|
-
|
43
|
-
* If FY 2008 spans
|
45
|
+
“Year Forward” refers to the standard name for a fiscal year. For example:
|
46
|
+
|
47
|
+
* If FY 2008 spans 2008–2009, set to false or don’t include in initializer file.
|
48
|
+
* If FY 2008 spans 2007–2008, set to true in initializer file.
|
49
|
+
|
50
|
+
Note that for every configuration you make, you will need to make it to every class (Date, Time, and DateTime) independently. For example:
|
51
|
+
|
52
|
+
Date.fiscal_zone = :india
|
53
|
+
Time.fiscal_zone = :india
|
54
|
+
DateTime.fiscal_zone = :india
|
44
55
|
|
45
56
|
### Default options
|
46
57
|
|
47
|
-
By default, the financial year start in January.
|
48
|
-
Known Zones are -
|
58
|
+
By default, the financial year start in January.
|
49
59
|
|
50
|
-
|
60
|
+
Supported zones are:
|
51
61
|
|
52
|
-
|
62
|
+
{ india: 4, uk: 4, us: 10, pakistan: 7, australia: 7, ireland: 1, nz: 7, japan: 4}
|
63
|
+
|
64
|
+
By default, the year forward is false, meaning the term FY 2008 spans 2008–2009 years.
|
53
65
|
|
54
66
|
## Date or Time Class Methods
|
55
67
|
|
@@ -84,8 +96,6 @@ By default, the Year Forward option is set to false, meaning the term FY 2008 sp
|
|
84
96
|
Date.uses_forward_year?
|
85
97
|
=> true
|
86
98
|
|
87
|
-
|
88
|
-
|
89
99
|
If you want to add your own fiscal zone
|
90
100
|
|
91
101
|
RisingSun::Fiscali::FISCAL_ZONE.merge!(:my_own_zone => 2)
|
@@ -102,15 +112,17 @@ should do the trick.
|
|
102
112
|
Indian Fiscal Year starts from 1st of April
|
103
113
|
Assume Date.today is 1st May 2009
|
104
114
|
|
105
|
-
|
106
115
|
##### financial_year -> Returns the financial year of the date/time
|
116
|
+
|
107
117
|
Date.today.financial_year
|
108
118
|
=> 2009
|
109
119
|
Date.today.beginning_of_year.financial_year
|
110
120
|
=> 2008
|
111
|
-
|
121
|
+
|
122
|
+
Since 1st Jan 2009 in India falls in the 2008-09 financial year
|
112
123
|
|
113
124
|
##### beginning_of_financial_year -> Returns the beginning of financial year
|
125
|
+
|
114
126
|
Date.today.beginning_of_financial_year
|
115
127
|
=> 1st April 2009
|
116
128
|
Date.today.beginning_of_year.beginning_of_financial_year
|
@@ -199,11 +211,17 @@ Assume Date.today is 1st May 2009
|
|
199
211
|
Date.today.beginning_of_year.previous_financial_quarter
|
200
212
|
=> 1st Apr 2008
|
201
213
|
|
202
|
-
|
203
214
|
## Contributors
|
204
215
|
|
216
|
+
* [@mxie](https://github.com/mxie)
|
217
|
+
* [@moubry](https://github.com/moubry)
|
205
218
|
* [@reed](https://github.com/reed)
|
206
219
|
* [@chiperific](https://github.com/chiperific)
|
207
220
|
* [@rshallit](https://github.com/rshallit)
|
208
221
|
* [@asanghi](https://github.com/asanghi)
|
222
|
+
* [@maxwell](https://github.com/maxwell)
|
223
|
+
* [@wubr](https://github.com/wubr)
|
224
|
+
|
225
|
+
## License
|
209
226
|
|
227
|
+
Fiscali is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/fiscali.gemspec
CHANGED
@@ -5,10 +5,11 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.name = "fiscali"
|
6
6
|
gem.version = RisingSun::Fiscali::VERSION
|
7
7
|
gem.authors = ["Aditya Sanghi"]
|
8
|
-
gem.email = ["asanghi@
|
8
|
+
gem.email = ["asanghi@hey.com"]
|
9
9
|
gem.description = %q{Fiscal Year Date Functions}
|
10
10
|
gem.summary = %q{Fiscal Year Date Functions}
|
11
11
|
gem.homepage = "https://github.com/asanghi/fiscali"
|
12
|
+
gem.license = 'MIT'
|
12
13
|
|
13
14
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
15
|
gem.files = `git ls-files`.split("\n")
|
@@ -18,6 +19,5 @@ Gem::Specification.new do |gem|
|
|
18
19
|
gem.add_dependency 'activesupport'
|
19
20
|
|
20
21
|
gem.add_development_dependency 'rake'
|
21
|
-
gem.add_development_dependency 'rspec', '~>
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3.10'
|
22
23
|
end
|
23
|
-
|
data/lib/rising_sun/fiscali.rb
CHANGED
@@ -29,7 +29,7 @@ module RisingSun
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def financial_year_start(year=Date.today.year)
|
32
|
-
new(year,fy_start_month,1)
|
32
|
+
uses_forward_year? ? new(year - 1,fy_start_month,1) : new(year,fy_start_month,1)
|
33
33
|
end
|
34
34
|
|
35
35
|
def financial_months
|
@@ -51,7 +51,9 @@ module RisingSun
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def financial_year
|
54
|
-
if
|
54
|
+
if january_start_month?
|
55
|
+
self.year
|
56
|
+
elsif self.class.uses_forward_year?
|
55
57
|
self.month < start_month ? self.year : self.year + 1
|
56
58
|
else
|
57
59
|
self.month < start_month ? self.year - 1 : self.year
|
@@ -59,8 +61,7 @@ module RisingSun
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def beginning_of_financial_year
|
62
|
-
year
|
63
|
-
change(:year => year, :month => start_month, :day => 1).beginning_of_month
|
64
|
+
change(:year => year_of_financial_year_beginning, :month => start_month, :day => 1).beginning_of_month
|
64
65
|
end
|
65
66
|
|
66
67
|
def end_of_financial_year
|
@@ -116,6 +117,14 @@ module RisingSun
|
|
116
117
|
beginning_of_financial_half.months_ago(6)
|
117
118
|
end
|
118
119
|
|
120
|
+
def all_financial_quarter
|
121
|
+
beginning_of_financial_quarter..end_of_financial_quarter
|
122
|
+
end
|
123
|
+
|
124
|
+
def all_financial_year
|
125
|
+
beginning_of_financial_year..end_of_financial_year
|
126
|
+
end
|
127
|
+
|
119
128
|
def financial_month_of(month)
|
120
129
|
if month < start_month
|
121
130
|
Date.new(year+1,month,1)
|
@@ -126,6 +135,18 @@ module RisingSun
|
|
126
135
|
|
127
136
|
private
|
128
137
|
|
138
|
+
def year_of_financial_year_beginning
|
139
|
+
if self.class.uses_forward_year? && !january_start_month?
|
140
|
+
financial_year - 1
|
141
|
+
else
|
142
|
+
financial_year
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def january_start_month?
|
147
|
+
start_month == 1
|
148
|
+
end
|
149
|
+
|
129
150
|
def months_between
|
130
151
|
soy = self.beginning_of_financial_year
|
131
152
|
(self.month - soy.month) + 12 * (self.year - soy.year)
|
data/lib/rising_sun/version.rb
CHANGED
data/spec/fiscali_spec.rb
CHANGED
@@ -2,129 +2,149 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "fiscali" do
|
4
4
|
it "should be possible to read fiscal zone" do
|
5
|
-
Date.fiscal_zone.
|
5
|
+
expect(Date.fiscal_zone).to be_nil
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should be possible to write fiscal zone" do
|
9
9
|
Date.fiscal_zone = :india
|
10
|
-
Date.fiscal_zone.
|
10
|
+
expect(Date.fiscal_zone).to eql(:india)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should be possible to read fiscal start month" do
|
14
14
|
Date.fy_start_month = 2
|
15
|
-
Date.fy_start_month.
|
15
|
+
expect(Date.fy_start_month).to eql(2)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should report financial year start" do
|
19
19
|
Date.fiscal_zone = :india
|
20
20
|
this_year = Date.today.year
|
21
|
-
Date.financial_year_start.
|
21
|
+
expect(Date.financial_year_start).to eql(Date.new(this_year,4,1))
|
22
22
|
|
23
|
-
Date.financial_year_start(2009).
|
23
|
+
expect(Date.financial_year_start(2009)).to eql(Date.new(2009,4,1))
|
24
24
|
end
|
25
25
|
|
26
26
|
context "Forward Year settings" do
|
27
|
-
after
|
27
|
+
after :each do
|
28
28
|
Date.reset_forward_year!
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be possible to read year forward field" do
|
32
|
-
Date.uses_forward_year
|
32
|
+
expect(Date.uses_forward_year?).to eql(false)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be possible to set year forward field" do
|
36
36
|
Date.use_forward_year!
|
37
|
-
Date.uses_forward_year
|
37
|
+
expect(Date.uses_forward_year?).to eql(true)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should report the correct financial eyar if forward year is being used" do
|
41
41
|
Date.use_forward_year!
|
42
42
|
@d = Date.new(2009,1,1)
|
43
|
-
@d.financial_year.
|
43
|
+
expect(@d.financial_year).to eql(2009)
|
44
44
|
@d = Date.new(2009,4,1)
|
45
|
-
@d.financial_year.
|
45
|
+
expect(@d.financial_year).to eql(2010)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should report the correct beginning_of_financial_year when forward year is set" do
|
49
49
|
Date.use_forward_year!
|
50
50
|
@d = Date.new(2009,6,1)
|
51
|
-
@d.beginning_of_financial_year.
|
51
|
+
expect(@d.beginning_of_financial_year).to eql(Date.new(2009,4,1))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should report financial year start" do
|
55
|
+
Date.fiscal_zone = :india
|
56
|
+
Date.use_forward_year!
|
57
|
+
this_year = Date.today.year
|
58
|
+
expect(Date.financial_year_start).to eql(Date.new(this_year-1,4,1))
|
59
|
+
|
60
|
+
expect(Date.financial_year_start(2009)).to eql(Date.new(2008,4,1))
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
55
64
|
context "should report correct date field" do
|
56
|
-
before
|
65
|
+
before :each do
|
57
66
|
Date.fiscal_zone = :india
|
58
67
|
@d = Date.new(2009,1,1)
|
59
68
|
end
|
60
69
|
|
61
70
|
it "should report correct financial year" do
|
62
|
-
@d.financial_year.
|
71
|
+
expect(@d.financial_year).to eql(2008)
|
63
72
|
end
|
64
73
|
|
65
74
|
it "should report correct beginning and of financial year" do
|
66
|
-
@d.beginning_of_financial_year.
|
67
|
-
@d.end_of_financial_year.
|
75
|
+
expect(@d.beginning_of_financial_year).to eql(Date.new(2008,4,1))
|
76
|
+
expect(@d.end_of_financial_year).to eql(Date.new(2009,3,31))
|
68
77
|
end
|
69
78
|
|
70
79
|
it "should report correct beginning of financial halves and quarters" do
|
71
|
-
@d.beginning_of_financial_h1.
|
72
|
-
@d.beginning_of_financial_h2.
|
73
|
-
@d.beginning_of_financial_q1.
|
74
|
-
@d.beginning_of_financial_q2.
|
75
|
-
@d.beginning_of_financial_q3.
|
76
|
-
@d.beginning_of_financial_q4.
|
80
|
+
expect(@d.beginning_of_financial_h1).to eql(Date.new(2008,4,1))
|
81
|
+
expect(@d.beginning_of_financial_h2).to eql(Date.new(2008,10,1))
|
82
|
+
expect(@d.beginning_of_financial_q1).to eql(Date.new(2008,4,1))
|
83
|
+
expect(@d.beginning_of_financial_q2).to eql(Date.new(2008,7,1))
|
84
|
+
expect(@d.beginning_of_financial_q3).to eql(Date.new(2008,10,1))
|
85
|
+
expect(@d.beginning_of_financial_q4).to eql(Date.new(2009,1,1))
|
77
86
|
end
|
78
87
|
|
79
88
|
it "should report correct end of financial halves and quarters" do
|
80
|
-
@d.end_of_financial_h1.
|
81
|
-
@d.end_of_financial_h2.
|
82
|
-
@d.end_of_financial_q1.
|
83
|
-
@d.end_of_financial_q2.
|
84
|
-
@d.end_of_financial_q3.
|
85
|
-
@d.end_of_financial_q4.
|
89
|
+
expect(@d.end_of_financial_h1).to eql(Date.new(2008,9,30))
|
90
|
+
expect(@d.end_of_financial_h2).to eql(Date.new(2009,3,31))
|
91
|
+
expect(@d.end_of_financial_q1).to eql(Date.new(2008,6,30))
|
92
|
+
expect(@d.end_of_financial_q2).to eql(Date.new(2008,9,30))
|
93
|
+
expect(@d.end_of_financial_q3).to eql(Date.new(2008,12,31))
|
94
|
+
expect(@d.end_of_financial_q4).to eql(Date.new(2009,3,31))
|
86
95
|
|
87
|
-
Date.fiscal_zone = :us
|
96
|
+
Date.fiscal_zone = :us
|
88
97
|
|
89
|
-
@d.end_of_financial_h1.
|
90
|
-
@d.end_of_financial_h2.
|
91
|
-
@d.end_of_financial_q1.
|
92
|
-
@d.end_of_financial_q2.
|
93
|
-
@d.end_of_financial_q3.
|
94
|
-
@d.end_of_financial_q4.
|
98
|
+
expect(@d.end_of_financial_h1).to eql(Date.new(2009,3,31))
|
99
|
+
expect(@d.end_of_financial_h2).to eql(Date.new(2009,9,30))
|
100
|
+
expect(@d.end_of_financial_q1).to eql(Date.new(2008,12,31))
|
101
|
+
expect(@d.end_of_financial_q2).to eql(Date.new(2009,3,31))
|
102
|
+
expect(@d.end_of_financial_q3).to eql(Date.new(2009,6,30))
|
103
|
+
expect(@d.end_of_financial_q4).to eql(Date.new(2009,9,30))
|
95
104
|
end
|
96
105
|
|
97
106
|
it "should report financial quarters" do
|
98
|
-
@d.financial_quarter.
|
107
|
+
expect(@d.financial_quarter).to eql('Q4 2008')
|
99
108
|
end
|
100
109
|
|
101
110
|
it "should report financial half" do
|
102
|
-
@d.financial_half.
|
103
|
-
Date.new(2009,11,30).financial_half.
|
111
|
+
expect(@d.financial_half).to eql('H2 2008')
|
112
|
+
expect(Date.new(2009, 11, 30).financial_half).to eql('H2 2009')
|
104
113
|
end
|
105
114
|
|
106
115
|
it "should report next half and quarter" do
|
107
|
-
@d.next_financial_half.
|
108
|
-
Date.new(2009,6,1).next_financial_half.
|
116
|
+
expect(@d.next_financial_half).to eql(Date.new(2009,4,1))
|
117
|
+
expect(Date.new(2009,6,1).next_financial_half).to eql(Date.new(2009,10,1))
|
109
118
|
|
110
|
-
@d.next_financial_quarter.
|
111
|
-
Date.new(2009,10,30).next_financial_quarter.
|
119
|
+
expect(@d.next_financial_quarter).to eql(Date.new(2009,4,1))
|
120
|
+
expect(Date.new(2009,10,30).next_financial_quarter).to eql(Date.new(2010,1,1))
|
112
121
|
end
|
113
122
|
|
114
123
|
it "should report beginning of financial half and quarter" do
|
115
|
-
@d.beginning_of_financial_half.
|
116
|
-
@d.beginning_of_financial_quarter.
|
117
|
-
Date.new(2009,6,1).beginning_of_financial_half.
|
118
|
-
Date.new(2009,10,30).beginning_of_financial_quarter.
|
124
|
+
expect(@d.beginning_of_financial_half).to eql(Date.new(2008,10,1))
|
125
|
+
expect(@d.beginning_of_financial_quarter).to eql(Date.new(2009,1,1))
|
126
|
+
expect(Date.new(2009,6,1).beginning_of_financial_half).to eql(Date.new(2009,4,1))
|
127
|
+
expect(Date.new(2009,10,30).beginning_of_financial_quarter).to eql(Date.new(2009,10,1))
|
119
128
|
end
|
120
129
|
|
121
130
|
it "should report previous financial half and quarter" do
|
122
|
-
@d.previous_financial_half.
|
123
|
-
@d.previous_financial_quarter.
|
124
|
-
Date.new(2009,6,1).previous_financial_half.
|
125
|
-
Date.new(2009,10,30).previous_financial_quarter.
|
131
|
+
expect(@d.previous_financial_half).to eql(Date.new(2008,4,1))
|
132
|
+
expect(@d.previous_financial_quarter).to eql(Date.new(2008,10,1))
|
133
|
+
expect(Date.new(2009,6,1).previous_financial_half).to eql(Date.new(2008,10,1))
|
134
|
+
expect(Date.new(2009,10,30).previous_financial_quarter).to eql(Date.new(2009,7,1))
|
126
135
|
end
|
136
|
+
end
|
127
137
|
|
138
|
+
context 'when date is end of month' do
|
139
|
+
before do
|
140
|
+
Date.fiscal_zone = :india
|
141
|
+
@d = Date.new(2009, 3, 31)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should report correct beginning and of financial year" do
|
145
|
+
expect(@d.beginning_of_financial_year).to eql(Date.new(2008,4,1))
|
146
|
+
expect(@d.end_of_financial_year).to eql(Date.new(2009,3,31))
|
147
|
+
end
|
128
148
|
end
|
129
149
|
|
130
150
|
context "should report correct timestamp" do
|
@@ -134,23 +154,23 @@ describe "fiscali" do
|
|
134
154
|
end
|
135
155
|
|
136
156
|
it "should report beginning of year/half/quarter with timestamp at beginning of day" do
|
137
|
-
@t.beginning_of_financial_year.
|
138
|
-
@t.beginning_of_financial_h1.
|
139
|
-
@t.beginning_of_financial_h2.
|
140
|
-
@t.beginning_of_financial_q1.
|
141
|
-
@t.beginning_of_financial_q2.
|
142
|
-
@t.beginning_of_financial_q3.
|
143
|
-
@t.beginning_of_financial_q4.
|
157
|
+
expect(@t.beginning_of_financial_year).to eql(Time.new(2008,4,1,0,0,0))
|
158
|
+
expect(@t.beginning_of_financial_h1).to eql(Time.new(2008,4,1,0,0,0))
|
159
|
+
expect(@t.beginning_of_financial_h2).to eql(Time.new(2008,10,1,0,0,0))
|
160
|
+
expect(@t.beginning_of_financial_q1).to eql(Time.new(2008,4,1,0,0,0))
|
161
|
+
expect(@t.beginning_of_financial_q2).to eql(Time.new(2008,7,1,0,0,0))
|
162
|
+
expect(@t.beginning_of_financial_q3).to eql(Time.new(2008,10,1,0,0,0))
|
163
|
+
expect(@t.beginning_of_financial_q4).to eql(Time.new(2009,1,1,0,0,0))
|
144
164
|
end
|
145
165
|
|
146
166
|
it "should report end of year/half/quarter with timestamp at end of day" do
|
147
|
-
@t.end_of_financial_year.
|
148
|
-
@t.end_of_financial_h1.
|
149
|
-
@t.end_of_financial_h2.
|
150
|
-
@t.end_of_financial_q1.
|
151
|
-
@t.end_of_financial_q2.
|
152
|
-
@t.end_of_financial_q3.
|
153
|
-
@t.end_of_financial_q4.
|
167
|
+
expect(@t.end_of_financial_year).to eql(Time.new(2009,3,31).end_of_day)
|
168
|
+
expect(@t.end_of_financial_h1).to eql(Time.new(2008,9,30).end_of_day)
|
169
|
+
expect(@t.end_of_financial_h2).to eql(Time.new(2009,3,31).end_of_day)
|
170
|
+
expect(@t.end_of_financial_q1).to eql(Time.new(2008,6,30).end_of_day)
|
171
|
+
expect(@t.end_of_financial_q2).to eql(Time.new(2008,9,30).end_of_day)
|
172
|
+
expect(@t.end_of_financial_q3).to eql(Time.new(2008,12,31).end_of_day)
|
173
|
+
expect(@t.end_of_financial_q4).to eql(Time.new(2009,3,31).end_of_day)
|
154
174
|
end
|
155
175
|
end
|
156
176
|
|
@@ -158,7 +178,54 @@ describe "fiscali" do
|
|
158
178
|
Date.fiscal_zone = :india
|
159
179
|
thread = Thread.new { Thread.current["my_fiscal_zone"] = Date.fiscal_zone }
|
160
180
|
thread.join
|
161
|
-
thread[
|
181
|
+
expect(thread['my_fiscal_zone']).to eql(:india)
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when the start month is January" do
|
185
|
+
around :each do |example|
|
186
|
+
old_fy_start_month = Date.fy_start_month
|
187
|
+
Date.fy_start_month = 1
|
188
|
+
@date = Date.new(2014, 1, 1)
|
189
|
+
example.run
|
190
|
+
Date.fy_start_month = old_fy_start_month
|
191
|
+
end
|
192
|
+
|
193
|
+
it "returns the date's year as the financial year" do
|
194
|
+
expect(@date.financial_year).to eql(2014)
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when using forward year" do
|
198
|
+
around :each do |example|
|
199
|
+
Date.use_forward_year!
|
200
|
+
example.run
|
201
|
+
Date.reset_forward_year!
|
202
|
+
end
|
203
|
+
|
204
|
+
it "returns the date's year as the financial year" do
|
205
|
+
expect(@date.financial_year).to eql(2014)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "returns the date itself as the beginning_of_financial_year" do
|
209
|
+
expect(@date.beginning_of_financial_year).to eql(@date)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "returns the date itself as the end_of_financial_year" do
|
213
|
+
expect(@date.end_of_financial_year).to eql(Date.new(2014, 12, 31))
|
214
|
+
end
|
215
|
+
end
|
162
216
|
end
|
163
217
|
|
164
|
-
|
218
|
+
context 'all_* methods' do
|
219
|
+
it 'returns a range of the entire financial period' do
|
220
|
+
date = Date.today
|
221
|
+
range = date.all_financial_quarter
|
222
|
+
expect(range.first).to eql(date.beginning_of_financial_quarter)
|
223
|
+
expect(range.last).to eql(date.end_of_financial_quarter)
|
224
|
+
|
225
|
+
range = date.all_financial_year
|
226
|
+
|
227
|
+
expect(range.first).to eql(date.beginning_of_financial_year)
|
228
|
+
expect(range.last).to eql(date.end_of_financial_year)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiscali
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aditya Sanghi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,22 +44,23 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.10'
|
55
55
|
description: Fiscal Year Date Functions
|
56
56
|
email:
|
57
|
-
- asanghi@
|
57
|
+
- asanghi@hey.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".document"
|
63
|
+
- ".github/workflows/ci.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- ".travis.yml"
|
65
66
|
- CHANGELOG
|
@@ -75,7 +76,8 @@ files:
|
|
75
76
|
- spec/fiscali_spec.rb
|
76
77
|
- spec/spec_helper.rb
|
77
78
|
homepage: https://github.com/asanghi/fiscali
|
78
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- MIT
|
79
81
|
metadata: {}
|
80
82
|
post_install_message:
|
81
83
|
rdoc_options: []
|
@@ -92,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
- !ruby/object:Gem::Version
|
93
95
|
version: '0'
|
94
96
|
requirements: []
|
95
|
-
|
96
|
-
rubygems_version: 2.2.2
|
97
|
+
rubygems_version: 3.1.2
|
97
98
|
signing_key:
|
98
99
|
specification_version: 4
|
99
100
|
summary: Fiscal Year Date Functions
|