fiscali 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f096b0e625d535cfab0ef4fb042d8a84c156d04
4
+ data.tar.gz: c79a080e90633c17243feb00ca795b08cb56d8ef
5
+ SHA512:
6
+ metadata.gz: cdfd4a1bdfaf3db71a9beb6c45309a59c24421a2893ed7ea7fd2d25b9b0202e5cc4bf00ed90c3ded5194cf283f9c9fa46890bccb899fa0b3d5a9e072ce06762c
7
+ data.tar.gz: 3ffae119410db7eb24c80d73c7059b6ee25bd498b4e25a255916eef4f7c682e9b41427ff8a1c70860ff5929ca10c1ce7212862415a411f2fd94df2506ff33ffb
data/CHANGELOG ADDED
@@ -0,0 +1,14 @@
1
+ v2.2.0
2
+ ======
3
+
4
+ * Added forward year support
5
+
6
+ By default the financial year is reported as the year in which the financial year starts. e.g. 2008-09 is reported as 2008.
7
+ However, some countries it is reported as 2008-09 is reported as 2009. You can now make this setting using
8
+
9
+ Date.use_forward_year! and report the currently set as Date.uses_forward_year?
10
+ The value can be reset using Date.reset_forward_year!
11
+
12
+ * Added Changelog
13
+
14
+ * Added Contributors
data/README.markdown CHANGED
@@ -15,7 +15,7 @@ Fiscali provides ONE thing:
15
15
 
16
16
  # Install the gem (from gemcutter.org):
17
17
  sudo gem install fiscali
18
-
18
+
19
19
  ## Using in your Rails project
20
20
 
21
21
  It's easy to get up and running. Update your config/environment.rb file with this gem
@@ -32,17 +32,34 @@ Next step is to provide your Date/Time class your start zone. Stick this in an i
32
32
  Time.fiscal_zone = :india
33
33
  or
34
34
  Date.start_month = 4
35
-
35
+
36
+ you can also determine the default for Year Forward by adding this to the same initializer file:
37
+
38
+ Date.use_forward_year!
39
+ Time.use_forward_year!
40
+
41
+ or if you wish to revert back to the default
42
+
43
+ Date.reset_forward_year!
44
+ Time.reset_forward_year!
45
+
46
+ Year Forward refers to the standard name for a fiscal year. For example:
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.
36
49
 
37
50
  ### Default options
38
51
 
39
- By default, the financial year start in January. (Correct me but thats not a common start of financial year!)
52
+ By default, the financial year start in January. (Correct me, but thats not a common start of financial year!)
40
53
  Known Zones are -
41
- {:india => 4, :uk => 4, :us => 10, :pakistan => 7,
42
- :australia => 7, :ireland => 1, :nz => 7, :japan => 4}
54
+
55
+ {:india => 4, :uk => 4, :us => 10, :pakistan => 7, :australia => 7, :ireland => 1, :nz => 7, :japan => 4}
56
+
57
+ By default, the Year Forward option is set to false, meaning the term FY 2008 spans 2008-2009 years.
43
58
 
44
59
  ## Date or Time Class Methods
45
-
60
+
61
+ ### Fiscal Zone and FY Start Month
62
+
46
63
  Date.fy_start_month
47
64
  => 1
48
65
  Date.fiscal_zone = :india
@@ -58,6 +75,22 @@ Known Zones are -
58
75
  Date.fiscal_zone
59
76
  => nil
60
77
 
78
+ ### Year Forward (Assume Date.today is 1st May 2009 and the fy_start_month = 4)
79
+
80
+ Date.uses_forward_year?
81
+ => false
82
+ Date.today.financial_year
83
+ => 2009
84
+
85
+ Date.use_forward_year!
86
+ => true
87
+ Date.today.financial_year
88
+ => 2010
89
+ Date.uses_forward_year?
90
+ => true
91
+
92
+
93
+
61
94
  If you want to add your own fiscal zone
62
95
 
63
96
  RisingSun::Fiscali::FISCAL_ZONE.merge!(:my_own_zone => 2)
@@ -70,11 +103,11 @@ should do the trick.
70
103
  => :india
71
104
  Date.fy_start_month
72
105
  => 4
73
-
106
+
74
107
  Indian Fiscal Year starts from 1st of April
75
108
  Assume Date.today is 1st May 2009
76
109
 
77
-
110
+
78
111
  ##### financial_year -> Returns the financial year of the date/time
79
112
  Date.today.financial_year
80
113
  => 2009
@@ -109,24 +142,24 @@ Assume Date.today is 1st May 2009
109
142
  ##### end_of_financial_h2
110
143
 
111
144
  ##### financial_quarter -> Returns Q1, Q2, Q3, Q4 depending on where the date falls
112
-
145
+
113
146
  Date.today.financial_quarter
114
147
  => Q1
115
148
  Date.today.beginning_of_year.financial_quarter
116
149
  => Q4
117
-
150
+
118
151
  ##### financial_half -> Returns H1, H2 depending on where the date falls
119
-
152
+
120
153
  Date.today.financial_half
121
154
  => H1
122
155
  Date.today.beginning_of_year.financial_half
123
156
  => H2
124
-
157
+
125
158
  ##### next_financial_quarter -> Takes you to the beginning of the next financial quarter
126
159
 
127
160
  Date.today.next_financial_quarter
128
161
  => 1st July 2009
129
-
162
+
130
163
  ##### next_financial_half -> Takes you to the beginning of the next financial half
131
164
 
132
165
  Date.today.next_financial_half
@@ -159,16 +192,21 @@ Assume Date.today is 1st May 2009
159
192
  => 1st Oct 2008
160
193
  Date.today.beginning_of_year.previous_financial_quarter
161
194
  => 1st Apr 2008
162
-
163
195
 
164
-
196
+
197
+ ## Contributors
198
+
199
+ @asanghi
200
+ @chiperific
201
+ Rachel Shallit
202
+
203
+
204
+
205
+
206
+
207
+
165
208
 
166
209
 
167
210
 
168
-
169
-
170
211
 
171
212
 
172
-
173
-
174
-
@@ -3,11 +3,11 @@ module RisingSun
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
5
  end
6
-
6
+
7
7
  FISCAL_ZONE = {:india => 4, :uk => 4, :us => 10, :pakistan => 7,
8
8
  :australia => 7, :ireland => 1, :nz => 7, :japan => 4}
9
9
  FY_START_MONTH = 1
10
-
10
+
11
11
  module ClassMethods
12
12
 
13
13
  def fiscal_zone=(zone)
@@ -27,19 +27,35 @@ module RisingSun
27
27
  @fiscali_zone = nil
28
28
  @fiscali_start_month = month
29
29
  end
30
-
30
+
31
31
  def financial_year_start(year=Date.today.year)
32
32
  new(year,fy_start_month,1)
33
33
  end
34
-
34
+
35
35
  def financial_months
36
36
  (1..12).map{|m| ((m - 1 + fy_start_month)%12.1).ceil }
37
37
  end
38
38
 
39
+ def use_forward_year!
40
+ @fy_forward = true
41
+ end
42
+
43
+ def reset_forward_year!
44
+ @fy_forward = false
45
+ end
46
+
47
+ def uses_forward_year?
48
+ @fy_forward || false
49
+ end
50
+
39
51
  end
40
52
 
41
53
  def financial_year
42
- self.month < start_month ? self.year - 1 : self.year
54
+ if self.class.uses_forward_year?
55
+ self.month < start_month ? self.year : self.year + 1
56
+ else
57
+ self.month < start_month ? self.year - 1 : self.year
58
+ end
43
59
  end
44
60
 
45
61
  def beginning_of_financial_year
@@ -116,12 +132,12 @@ module RisingSun
116
132
 
117
133
  def financial_month_of(month)
118
134
  if month < start_month
119
- Date.new(year+1,month,1)
135
+ Date.new(year+1,month,1)
120
136
  else
121
- Date.new(year,month,1)
137
+ Date.new(year,month,1)
122
138
  end
123
139
  end
124
-
140
+
125
141
  private
126
142
 
127
143
  def months_between
@@ -1,5 +1,5 @@
1
1
  module RisingSun
2
2
  module Fiscali
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
data/spec/fiscali_spec.rb CHANGED
@@ -4,17 +4,17 @@ describe "fiscali" do
4
4
  it "should be possible to read fiscal zone" do
5
5
  Date.fiscal_zone.should 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
10
  Date.fiscal_zone.should 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
15
  Date.fy_start_month.should 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
@@ -23,6 +23,29 @@ describe "fiscali" do
23
23
  Date.financial_year_start(2009).should eql(Date.new(2009,4,1))
24
24
  end
25
25
 
26
+ context "Forward Year settings" do
27
+ after(:each) do
28
+ Date.reset_forward_year!
29
+ end
30
+
31
+ it "should be possible to read year forward field" do
32
+ Date.uses_forward_year?.should eql(false)
33
+ end
34
+
35
+ it "should be possible to set year forward field" do
36
+ Date.use_forward_year!
37
+ Date.uses_forward_year?.should eql(true)
38
+ end
39
+
40
+ it "should report the correct financial eyar if forward year is being used" do
41
+ Date.use_forward_year!
42
+ @d = Date.new(2009,1,1)
43
+ @d.financial_year.should eql(2009)
44
+ @d = Date.new(2009,4,1)
45
+ @d.financial_year.should eql(2010)
46
+ end
47
+ end
48
+
26
49
  context "should report correct date field" do
27
50
  before(:each) do
28
51
  @d = Date.new(2009,1,1)
@@ -30,12 +53,12 @@ describe "fiscali" do
30
53
  it "should report correct financial year" do
31
54
  @d.financial_year.should eql(2008)
32
55
  end
33
-
56
+
34
57
  it "should report correct beginning and of financial year" do
35
58
  @d.beginning_of_financial_year.should eql(Date.new(2008,4,1))
36
59
  @d.end_of_financial_year.should eql(Date.new(2009,3,31))
37
60
  end
38
-
61
+
39
62
  it "should report correct beginning of financial halves and quarters" do
40
63
  @d.beginning_of_financial_h1.should eql(Date.new(2008,4,1))
41
64
  @d.beginning_of_financial_h2.should eql(Date.new(2008,10,1))
@@ -44,7 +67,7 @@ describe "fiscali" do
44
67
  @d.beginning_of_financial_q3.should eql(Date.new(2008,10,1))
45
68
  @d.beginning_of_financial_q4.should eql(Date.new(2009,1,1))
46
69
  end
47
-
70
+
48
71
  it "should report correct end of financial halves and quarters" do
49
72
  @d.end_of_financial_h1.should eql(Date.new(2008,9,30))
50
73
  @d.end_of_financial_h2.should eql(Date.new(2009,3,31))
@@ -62,7 +85,7 @@ describe "fiscali" do
62
85
  @d.financial_half.should eql('H2 2008')
63
86
  Date.new(2009,11,30).financial_half.should eql("H2 2009")
64
87
  end
65
-
88
+
66
89
  it "should report next half and quarter" do
67
90
  @d.next_financial_half.should eql(Date.new(2009,4,1))
68
91
  Date.new(2009,6,1).next_financial_half.should eql(Date.new(2009,10,1))
@@ -70,14 +93,14 @@ describe "fiscali" do
70
93
  @d.next_financial_quarter.should eql(Date.new(2009,4,1))
71
94
  Date.new(2009,10,30).next_financial_quarter.should eql(Date.new(2010,1,1))
72
95
  end
73
-
96
+
74
97
  it "should report beginning of financial half and quarter" do
75
98
  @d.beginning_of_financial_half.should eql(Date.new(2008,10,1))
76
99
  @d.beginning_of_financial_quarter.should eql(Date.new(2009,1,1))
77
100
  Date.new(2009,6,1).beginning_of_financial_half.should eql(Date.new(2009,4,1))
78
101
  Date.new(2009,10,30).beginning_of_financial_quarter.should eql(Date.new(2009,10,1))
79
102
  end
80
-
103
+
81
104
  it "should report previous financial half and quarter" do
82
105
  @d.previous_financial_half.should eql(Date.new(2008,4,1))
83
106
  @d.previous_financial_quarter.should eql(Date.new(2008,10,1))
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiscali
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
5
- prerelease:
4
+ version: 2.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Aditya Sanghi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-16 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '2.8'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '2.8'
62
55
  description: Fiscal Year Date Functions
@@ -66,9 +59,10 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .document
70
- - .gitignore
71
- - .travis.yml
62
+ - ".document"
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CHANGELOG
72
66
  - Gemfile
73
67
  - LICENSE
74
68
  - README.markdown
@@ -82,27 +76,26 @@ files:
82
76
  - spec/spec_helper.rb
83
77
  homepage: https://github.com/asanghi/fiscali
84
78
  licenses: []
79
+ metadata: {}
85
80
  post_install_message:
86
81
  rdoc_options: []
87
82
  require_paths:
88
83
  - lib
89
84
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
85
  requirements:
92
- - - ! '>='
86
+ - - ">="
93
87
  - !ruby/object:Gem::Version
94
88
  version: '0'
95
89
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
90
  requirements:
98
- - - ! '>='
91
+ - - ">="
99
92
  - !ruby/object:Gem::Version
100
93
  version: '0'
101
94
  requirements: []
102
95
  rubyforge_project:
103
- rubygems_version: 1.8.21
96
+ rubygems_version: 2.2.2
104
97
  signing_key:
105
- specification_version: 3
98
+ specification_version: 4
106
99
  summary: Fiscal Year Date Functions
107
100
  test_files:
108
101
  - spec/fiscali_spec.rb