business 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/README.md +35 -25
- data/lib/business/calendar.rb +2 -3
- data/lib/business/data/bacs.yml +8 -1
- data/lib/business/data/sepa.yml +14 -0
- data/lib/business/version.rb +1 -1
- data/spec/calendar_spec.rb +5 -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: 57d7e4abbcd7ac0f7b1e6852b70b8a79a3ce617b
|
4
|
+
data.tar.gz: 43d1b2553edbcc7871a57aba27f2dd265d310b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1483bdaffd374f8cad123855cc1c54a30e589c57fe98f8e7c47891dd74751087f5cee2bb0177d8bb11a66bacc93645ed1d94bf81bb1c1d72837da40c50ad700d
|
7
|
+
data.tar.gz: 815dd1a6e4de78b31fb6820f22348b684b91df7f8ad0f735aadc6634fde3c69624915aeb3b7fc22175ea0cc0d0bef7eaa4c235964fca7cf84bba1526027f2d6d
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,33 +1,21 @@
|
|
1
1
|
# Business
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
## But other libraries already do this
|
7
|
-
|
8
|
-
Another gem, business_time, also exists for this purpose. We previously used
|
9
|
-
business_time, but encountered several issues that prompted us to create
|
10
|
-
business.
|
3
|
+
[![Gem version](https://badge.fury.io/rb/business.svg)](http://badge.fury.io/rb/business)
|
4
|
+
[![Build status](https://travis-ci.org/gocardless/business.svg?branch=master)](https://travis-ci.org/gocardless/business)
|
11
5
|
|
12
|
-
|
13
|
-
While this enables syntax like `Time.now + 1.business_day`, it means that all
|
14
|
-
configuration has to be global. GoCardless handles payments across multiple
|
15
|
-
geographies, so being able to work with multiple working-day calendars is
|
16
|
-
essential for us. Business provides a simple `Calendar` class, that is
|
17
|
-
initialized with a configuration that specifies which days of the week are
|
18
|
-
considered to be working days, and which dates are holidays.
|
6
|
+
Date calculations based on business calendars.
|
19
7
|
|
20
|
-
|
21
|
-
our purposes, date-based calculations are sufficient. Supporting time-based
|
22
|
-
calculations as well makes the code significantly more complex. We chose to
|
23
|
-
avoid this extra complexity by sticking solely to date-based mathematics.
|
8
|
+
## Documentation
|
24
9
|
|
10
|
+
To get business, simply:
|
25
11
|
|
26
|
-
|
12
|
+
```bash
|
13
|
+
$ gem install business
|
14
|
+
```
|
27
15
|
|
28
16
|
### Getting started
|
29
17
|
|
30
|
-
Get
|
18
|
+
Get started with business by creating an instance of the calendar class,
|
31
19
|
passing in a hash that specifies with days of the week are considered working
|
32
20
|
days, and which days are holidays.
|
33
21
|
|
@@ -38,10 +26,10 @@ calendar = Business::Calendar.new(
|
|
38
26
|
)
|
39
27
|
```
|
40
28
|
|
41
|
-
A few calendar configs are bundled with the gem
|
42
|
-
`load` class method on `Calendar`. The
|
43
|
-
caches the calendars by name after loading
|
44
|
-
parsing the config file multiple times.
|
29
|
+
A few calendar configs are bundled with the gem (see lib/business/data for
|
30
|
+
details). Load them by calling the `load` class method on `Calendar`. The
|
31
|
+
`load_cached` variant of this method caches the calendars by name after loading
|
32
|
+
them, to avoid reading and parsing the config file multiple times.
|
45
33
|
|
46
34
|
```ruby
|
47
35
|
calendar = Business::Calendar.load("weekdays")
|
@@ -98,3 +86,25 @@ calendar.business_days_between(date, date + 7)
|
|
98
86
|
# => 5
|
99
87
|
```
|
100
88
|
|
89
|
+
|
90
|
+
## But other libraries already do this
|
91
|
+
|
92
|
+
Another gem, [business_time](https://github.com/bokmann/business_time), also
|
93
|
+
exists for this purpose. We previously used business_time, but encountered
|
94
|
+
several issues that prompted us to start business.
|
95
|
+
|
96
|
+
Firstly, business_time works by monkey-patching `Date`, `Time`, and `FixNum`.
|
97
|
+
While this enables syntax like `Time.now + 1.business_day`, it means that all
|
98
|
+
configuration has to be global. GoCardless handles payments across several
|
99
|
+
geographies, so being able to work with multiple working-day calendars is
|
100
|
+
essential for us. Business provides a simple `Calendar` class, that is
|
101
|
+
initialized with a configuration that specifies which days of the week are
|
102
|
+
considered to be working days, and which dates are holidays.
|
103
|
+
|
104
|
+
Secondly, business_time supports calculations on times as well as dates. For
|
105
|
+
our purposes, date-based calculations are sufficient. Supporting time-based
|
106
|
+
calculations as well makes the code significantly more complex. We chose to
|
107
|
+
avoid this extra complexity by sticking solely to date-based mathematics.
|
108
|
+
|
109
|
+
|
110
|
+
![I'm late for business](http://3.bp.blogspot.com/-aq4iOz2OZzs/Ty8xaQwMhtI/AAAAAAAABrM/-vn4tcRA9-4/s1600/daily-morning-awesomeness-243.jpeg)
|
data/lib/business/calendar.rb
CHANGED
@@ -29,7 +29,7 @@ module Business
|
|
29
29
|
set_holidays(config[:holidays])
|
30
30
|
end
|
31
31
|
|
32
|
-
# Return true if the date given is a business day (typically that
|
32
|
+
# Return true if the date given is a business day (typically that means a
|
33
33
|
# non-weekend day) and not a holiday.
|
34
34
|
def business_day?(date)
|
35
35
|
date = date.to_date
|
@@ -42,8 +42,7 @@ module Business
|
|
42
42
|
# day, that day will be returned. If the day given is a holiday or
|
43
43
|
# non-working day, the next non-holiday working day will be returned.
|
44
44
|
def roll_forward(date)
|
45
|
-
|
46
|
-
date += interval until business_day?(date)
|
45
|
+
date += day_interval_for(date) until business_day?(date)
|
47
46
|
date
|
48
47
|
end
|
49
48
|
|
data/lib/business/data/bacs.yml
CHANGED
@@ -22,4 +22,11 @@ holidays:
|
|
22
22
|
- August 25th, 2014
|
23
23
|
- December 25th, 2014
|
24
24
|
- December 26th, 2014
|
25
|
-
|
25
|
+
- January 1st, 2015
|
26
|
+
- April 3rd, 2015
|
27
|
+
- April 6th, 2015
|
28
|
+
- May 4th, 2015
|
29
|
+
- May 25th, 2015
|
30
|
+
- August 31st, 2015
|
31
|
+
- December 25th, 2015
|
32
|
+
- December 28th, 2015
|
data/lib/business/data/sepa.yml
CHANGED
@@ -33,3 +33,17 @@ holidays:
|
|
33
33
|
- December 25th, 2014
|
34
34
|
- December 26th, 2014
|
35
35
|
- December 31st, 2014
|
36
|
+
- January 1st, 2015
|
37
|
+
- April 3rd, 2015
|
38
|
+
- April 6th, 2015
|
39
|
+
- May 1st, 2015
|
40
|
+
- May 9th, 2015
|
41
|
+
- May 14th, 2015
|
42
|
+
- May 25th, 2015
|
43
|
+
- June 4th, 2015
|
44
|
+
- October 3rd, 2015
|
45
|
+
- November 1st, 2015
|
46
|
+
- December 24th, 2015
|
47
|
+
- December 25th, 2015
|
48
|
+
- December 26th, 2015
|
49
|
+
- December 31st, 2015
|
data/lib/business/version.rb
CHANGED
data/spec/calendar_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require "business/calendar"
|
2
2
|
require "time"
|
3
3
|
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
|
6
|
+
config.raise_errors_for_deprecations!
|
7
|
+
end
|
8
|
+
|
4
9
|
describe Business::Calendar do
|
5
10
|
describe ".load" do
|
6
11
|
context "when given a valid calendar" do
|
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.1.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-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
|
+
- .travis.yml
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE
|
51
52
|
- README.md
|