fyuk 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fyuk.gemspec +2 -2
- data/lib/uk_financial_year.rb +39 -5
- data/spec/uk_financial_year_spec.rb +49 -117
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/fyuk.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fyuk"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nigel Lowry"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-12"
|
13
13
|
s.description = "Small library with methods for finding the financial or fiscal year for a particular date and suchlike"
|
14
14
|
s.email = "nigel-lowry@ultra.eclipse.co.uk"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/uk_financial_year.rb
CHANGED
@@ -19,7 +19,7 @@ class UkFinancialYear
|
|
19
19
|
# @return [String] representation in the form of the first year as four
|
20
20
|
# digits, a '/', then the last year as two digits
|
21
21
|
def to_s
|
22
|
-
"#{self.first_day.year}/#{self.last_day.year.to_s
|
22
|
+
"#{self.first_day.year}/#{self.last_day.year.to_s.last(2)}"
|
23
23
|
end
|
24
24
|
|
25
25
|
# creates a new UkFinancialYear from a string in the form '2000/01'
|
@@ -73,22 +73,56 @@ class UkFinancialYear
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def adjacent? other_financial_year
|
76
|
-
self.first_day.next_year == other_financial_year.first_day
|
76
|
+
self.first_day.next_year == other_financial_year.first_day or self.first_day.prev_year == other_financial_year.first_day
|
77
|
+
end
|
78
|
+
|
79
|
+
# tells if the given date or financial year is before this one
|
80
|
+
# @param [Date] date_or_fy date or financial year to check
|
81
|
+
# @return [Boolean] to indicate if this financial year is before
|
82
|
+
def before? date_or_fy
|
83
|
+
self.first_day.before?(date_to_compare date_or_fy)
|
84
|
+
end
|
85
|
+
|
86
|
+
# tells if the given date or financial year is after this one
|
87
|
+
# @param (see FixedOdds#before?)
|
88
|
+
# @return [Boolean] to indicate if this financial year is after
|
89
|
+
def after? date_or_fy
|
90
|
+
self.first_day.after?(date_to_compare date_or_fy)
|
77
91
|
end
|
78
92
|
|
79
93
|
# equality method
|
80
|
-
def ==
|
94
|
+
def == other
|
81
95
|
self.first_day == other.first_day
|
82
96
|
end
|
83
97
|
|
84
98
|
# lesser financial years are those which occur earliest
|
85
|
-
def <=>
|
99
|
+
def <=> other
|
86
100
|
self.first_day <=> other.first_day
|
87
101
|
end
|
88
102
|
|
89
103
|
private
|
104
|
+
def date_to_compare other
|
105
|
+
if other.is_a?(Date) then other else other.first_day end
|
106
|
+
end
|
107
|
+
|
90
108
|
def start_date date
|
91
109
|
swap_date_that_year = Date.new date.year, 4, 6
|
92
|
-
date
|
110
|
+
(date.after?(swap_date_that_year) or date == swap_date_that_year) ? swap_date_that_year : swap_date_that_year.prev_year
|
93
111
|
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class String
|
115
|
+
def last n
|
116
|
+
self[-n, n]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Date
|
121
|
+
def before? other
|
122
|
+
self < other
|
123
|
+
end
|
124
|
+
|
125
|
+
def after? other
|
126
|
+
self > other
|
127
|
+
end
|
94
128
|
end
|
@@ -1,40 +1,39 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe UkFinancialYear do
|
4
|
-
describe "#first_day" do
|
5
|
-
it "is 6 Apr of the previous year if 4 Apr" do
|
6
|
-
UkFinancialYear.new(Date.parse '4 Apr 2011').first_day.should == Date.parse('6 Apr 2010')
|
7
|
-
end
|
8
|
-
|
9
|
-
it "is 6 Apr of the previous year if 5 Apr" do
|
10
|
-
UkFinancialYear.new(Date.parse '5 Apr 2011').first_day.should == Date.parse('6 Apr 2010')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is 6 Apr for the same year if 6 Apr" do
|
14
|
-
UkFinancialYear.new(Date.parse '6 Apr 2011').first_day.should == Date.parse('6 Apr 2011')
|
15
|
-
end
|
16
4
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
5
|
+
before :all do
|
6
|
+
@fy = UkFinancialYear.from_s '2012/13'
|
20
7
|
end
|
21
8
|
|
22
|
-
|
23
|
-
it "is 5 Apr of the current year if 4 Apr" do
|
24
|
-
UkFinancialYear.new(Date.parse '4 Apr 2011').last_day.should == Date.parse('5 Apr 2011')
|
25
|
-
end
|
9
|
+
subject { @fy }
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
its(:first_day) { should == Date.parse('6 Apr 2012') }
|
12
|
+
its(:last_day) { should == Date.parse('5 Apr 2013') }
|
13
|
+
its(:next) { should == UkFinancialYear.from_s('2013/14') }
|
14
|
+
its(:previous) { should == UkFinancialYear.from_s('2011/12') }
|
15
|
+
its(:to_s) { should == '2012/13' }
|
30
16
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
17
|
+
specify { UkFinancialYear.new(Date.parse '6 Apr 2011').should == UkFinancialYear.new(Date.parse '7 Apr 2011') }
|
18
|
+
specify { UkFinancialYear.new(Date.parse '5 Apr 2011').should_not == UkFinancialYear.new(Date.parse '6 Apr 2011') }
|
34
19
|
|
35
|
-
|
36
|
-
|
37
|
-
|
20
|
+
specify { UkFinancialYear.new(Date.parse '5 Apr 2011').should be < UkFinancialYear.new(Date.parse '6 Apr 2011') }
|
21
|
+
|
22
|
+
specify { UkFinancialYear.new(Date.parse('7 Apr 2011')).to_s.should == '2011/12' }
|
23
|
+
specify { UkFinancialYear.new(Date.parse('7 Apr 1999')).to_s.should == '1999/00' }
|
24
|
+
|
25
|
+
describe "#first_day" do
|
26
|
+
specify { UkFinancialYear.new(Date.parse '4 Apr 2011').first_day.should == Date.parse('6 Apr 2010') }
|
27
|
+
specify { UkFinancialYear.new(Date.parse '5 Apr 2011').first_day.should == Date.parse('6 Apr 2010') }
|
28
|
+
specify { UkFinancialYear.new(Date.parse '6 Apr 2011').first_day.should == Date.parse('6 Apr 2011') }
|
29
|
+
specify { UkFinancialYear.new(Date.parse '7 Apr 2011').first_day.should == Date.parse('6 Apr 2011') }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#last_day" do
|
33
|
+
specify { UkFinancialYear.new(Date.parse '4 Apr 2011').last_day.should == Date.parse('5 Apr 2011') }
|
34
|
+
specify { UkFinancialYear.new(Date.parse '5 Apr 2011').last_day.should == Date.parse('5 Apr 2011') }
|
35
|
+
specify { UkFinancialYear.new(Date.parse '6 Apr 2011').last_day.should == Date.parse('5 Apr 2012') }
|
36
|
+
specify { UkFinancialYear.new(Date.parse '7 Apr 2011').last_day.should == Date.parse('5 Apr 2012') }
|
38
37
|
end
|
39
38
|
|
40
39
|
describe "#.include?" do
|
@@ -50,56 +49,10 @@ describe UkFinancialYear do
|
|
50
49
|
it { should_not include Date.parse '6 Apr 2013' }
|
51
50
|
end
|
52
51
|
|
53
|
-
describe "equality" do
|
54
|
-
it "is the same for values falling in the same FY" do
|
55
|
-
fy1 = UkFinancialYear.new(Date.parse '6 Apr 2011')
|
56
|
-
fy2 = UkFinancialYear.new(Date.parse '7 Apr 2011')
|
57
|
-
fy1.should == fy2
|
58
|
-
end
|
59
|
-
|
60
|
-
it "is different for values in different FYs" do
|
61
|
-
fy1 = UkFinancialYear.new(Date.parse '5 Apr 2011')
|
62
|
-
fy2 = UkFinancialYear.new(Date.parse '6 Apr 2011')
|
63
|
-
fy1.should_not == fy2
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#to_s" do
|
68
|
-
it "is the four-digit year then a '/' then a two-digit year" do
|
69
|
-
fy = UkFinancialYear.new Date.parse '7 Apr 2011'
|
70
|
-
fy.to_s.should == '2011/12'
|
71
|
-
end
|
72
|
-
|
73
|
-
it "is 1999/00 for the turn of the millenium" do
|
74
|
-
fy = UkFinancialYear.new Date.parse '7 Apr 1999'
|
75
|
-
fy.to_s.should == '1999/00'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
52
|
describe "#from_s" do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
fy.last_day.should == Date.parse('5 Apr 2011')
|
84
|
-
end
|
85
|
-
|
86
|
-
it "is 2002/03 for '2002/03'" do
|
87
|
-
fy = UkFinancialYear.from_s '2002/03'
|
88
|
-
fy.first_day.should == Date.parse('6 Apr 2002')
|
89
|
-
fy.last_day.should == Date.parse('5 Apr 2003')
|
90
|
-
end
|
91
|
-
|
92
|
-
it "is 1998/99 for '1998/99'" do
|
93
|
-
fy = UkFinancialYear.from_s '1998/99'
|
94
|
-
fy.first_day.should == Date.parse('6 Apr 1998')
|
95
|
-
fy.last_day.should == Date.parse('5 Apr 1999')
|
96
|
-
end
|
97
|
-
|
98
|
-
it "is 1999/00 for '1999/00'" do
|
99
|
-
fy = UkFinancialYear.from_s '1999/00'
|
100
|
-
fy.first_day.should == Date.parse('6 Apr 1999')
|
101
|
-
fy.last_day.should == Date.parse('5 Apr 2000')
|
102
|
-
end
|
53
|
+
specify { UkFinancialYear.from_s('1998/99').to_s.should == '1998/99' }
|
54
|
+
specify { UkFinancialYear.from_s('1999/00').to_s.should == '1999/00' }
|
55
|
+
specify { UkFinancialYear.from_s('2000/01').to_s.should == '2000/01' }
|
103
56
|
|
104
57
|
it "raises error if years not consecutive" do
|
105
58
|
expect {
|
@@ -120,54 +73,33 @@ describe UkFinancialYear do
|
|
120
73
|
end
|
121
74
|
end
|
122
75
|
|
123
|
-
describe "#next" do
|
124
|
-
it "returns the next financial year" do
|
125
|
-
fy = UkFinancialYear.from_s '2011/12'
|
126
|
-
fy.next.should == UkFinancialYear.from_s('2012/13')
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#previous" do
|
131
|
-
it "returns the previous financial year" do
|
132
|
-
fy = UkFinancialYear.from_s '2011/12'
|
133
|
-
fy.previous.should == UkFinancialYear.from_s('2010/11')
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
76
|
describe "#adjacent" do
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
fy2.should be_adjacent fy1
|
144
|
-
end
|
145
|
-
|
146
|
-
it "is false for financial years which do not run together" do
|
147
|
-
fy1 = UkFinancialYear.from_s '2011/12'
|
148
|
-
fy2 = UkFinancialYear.from_s '2013/14'
|
149
|
-
|
150
|
-
fy1.should_not be_adjacent fy2
|
151
|
-
fy2.should_not be_adjacent fy1
|
77
|
+
before :each do
|
78
|
+
@fy2011_12 = UkFinancialYear.from_s '2011/12'
|
79
|
+
@fy2012_13 = @fy2011_12.next
|
80
|
+
@fy2013_14 = @fy2012_13.next
|
81
|
+
@fy2013_15 = @fy2013_14.next
|
152
82
|
end
|
153
83
|
|
154
|
-
|
155
|
-
fy1 = UkFinancialYear.from_s '2011/12'
|
156
|
-
fy2 = UkFinancialYear.from_s '2011/12'
|
84
|
+
subject { @fy2012_13 }
|
157
85
|
|
158
|
-
|
159
|
-
|
160
|
-
|
86
|
+
it { should be_adjacent @fy2011_12 }
|
87
|
+
it { should be_adjacent @fy2013_14 }
|
88
|
+
it { should_not be_adjacent @fy2013_15 }
|
89
|
+
it { should_not be_adjacent @fy2012_13 }
|
161
90
|
end
|
162
91
|
|
163
|
-
describe "
|
164
|
-
|
165
|
-
|
92
|
+
describe "#before? and #after?" do
|
93
|
+
before :each do
|
94
|
+
@fy = UkFinancialYear.from_s '2011/12'
|
166
95
|
end
|
167
96
|
|
168
|
-
|
169
|
-
|
170
|
-
|
97
|
+
subject { @fy }
|
98
|
+
|
99
|
+
it { should be_before UkFinancialYear.from_s('2012/13') }
|
100
|
+
it { should be_after UkFinancialYear.from_s('2010/11') }
|
101
|
+
it { should be_before UkFinancialYear.from_s('2012/13').last_day }
|
102
|
+
it { should be_after UkFinancialYear.from_s('2010/11').first_day }
|
171
103
|
end
|
172
104
|
|
173
105
|
describe "creation without date" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fyuk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash:
|
131
|
+
hash: -2786941839308588920
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
133
|
none: false
|
134
134
|
requirements:
|