business 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/business/calendar.rb +9 -0
- data/lib/business/version.rb +1 -1
- data/spec/calendar_spec.rb +24 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2d2cb8f2fd7a20e32ebd77079819fd74a32e8d0
|
4
|
+
data.tar.gz: 9490bfa2e494111d15b3402b88ae0b4181ba8f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 565f7bcaa097777c83efbfaefb54e09ba96608f910fe4b823a1a14625419ba1177c87dfbbaf7d2566b847a75653669a65a0bf9730015e776ce69a780dff563e8
|
7
|
+
data.tar.gz: cde6cbeecffd912f1673b0174dd425ee2e43ab4ff8027d3124d19a0dcf5c6a43c45f358b80ea4387ef74aeb3af0b45d758693db91c365af603cc4633285fbf8c
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## 1.3.0 - December 2, 2014
|
2
|
+
|
3
|
+
- Add `Calendar#previous_business_day`
|
4
|
+
|
5
|
+
|
6
|
+
## 1.2.0 - November 15, 2014
|
7
|
+
|
8
|
+
- Add TARGET calendar
|
9
|
+
|
10
|
+
|
11
|
+
## 1.1.0 - September 30, 2014
|
12
|
+
|
13
|
+
- Add 2015 holiday definitions
|
14
|
+
|
15
|
+
|
16
|
+
## 1.0.0 - June 11, 2014
|
17
|
+
|
18
|
+
- Initial public release
|
19
|
+
|
data/lib/business/calendar.rb
CHANGED
@@ -63,6 +63,15 @@ module Business
|
|
63
63
|
date
|
64
64
|
end
|
65
65
|
|
66
|
+
# Roll backward to the previous business day regardless of whether the given
|
67
|
+
# date is a business day or not.
|
68
|
+
def previous_business_day(date)
|
69
|
+
begin
|
70
|
+
date -= day_interval_for(date)
|
71
|
+
end until business_day?(date)
|
72
|
+
date
|
73
|
+
end
|
74
|
+
|
66
75
|
# Add a number of business days to a date. If a non-business day is given,
|
67
76
|
# counting will start from the next business day. So,
|
68
77
|
# monday + 1 = tuesday
|
data/lib/business/version.rb
CHANGED
data/spec/calendar_spec.rb
CHANGED
@@ -181,6 +181,30 @@ describe Business::Calendar do
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
|
+
describe "#previous_business_day" do
|
185
|
+
let(:calendar) do
|
186
|
+
Business::Calendar.new(holidays: ["Tuesday 1st Jan, 2013"])
|
187
|
+
end
|
188
|
+
subject { calendar.previous_business_day(date) }
|
189
|
+
|
190
|
+
context "given a business day" do
|
191
|
+
let(:date) { date_class.parse("Thursday 3nd Jan, 2013") }
|
192
|
+
it { is_expected.to eq(date - day_interval) }
|
193
|
+
end
|
194
|
+
|
195
|
+
context "given a non-business day" do
|
196
|
+
context "with a business day before it" do
|
197
|
+
let(:date) { date_class.parse("Tuesday 1st Jan, 2013") }
|
198
|
+
it { is_expected.to eq(date - day_interval) }
|
199
|
+
end
|
200
|
+
|
201
|
+
context "preceeded by another non-business day" do
|
202
|
+
let(:date) { date_class.parse("Sunday 6th Jan, 2013") }
|
203
|
+
it { is_expected.to eq(date - 2 * day_interval) }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
184
208
|
describe "#add_business_days" do
|
185
209
|
let(:calendar) do
|
186
210
|
Business::Calendar.new(holidays: ["Tuesday 1st Jan, 2013"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Marr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
49
|
- .travis.yml
|
50
|
+
- CHANGELOG.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE
|
52
53
|
- README.md
|