is_business_day 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +5 -3
- data/lib/is_business_day.rb +19 -4
- data/lib/is_business_day/business_days.rb +11 -0
- data/lib/is_business_day/business_days/calculations.rb +29 -0
- data/lib/is_business_day/business_days/tests.rb +17 -0
- data/lib/is_business_day/christmas.rb +15 -0
- data/lib/is_business_day/christmas/day/calculations.rb +23 -0
- data/lib/is_business_day/christmas/day/tests.rb +21 -0
- data/lib/is_business_day/christmas/eve/calculations.rb +23 -0
- data/lib/is_business_day/christmas/eve/tests.rb +21 -0
- data/lib/is_business_day/fourth_of_july.rb +11 -0
- data/lib/is_business_day/fourth_of_july/calculations.rb +19 -0
- data/lib/is_business_day/fourth_of_july/tests.rb +17 -0
- data/lib/is_business_day/helpers.rb +53 -0
- data/lib/is_business_day/holidays.rb +31 -0
- data/lib/is_business_day/labor_day.rb +11 -0
- data/lib/is_business_day/labor_day/calculations.rb +22 -0
- data/lib/is_business_day/labor_day/tests.rb +18 -0
- data/lib/is_business_day/memorial_day.rb +11 -0
- data/lib/is_business_day/memorial_day/calculations.rb +24 -0
- data/lib/is_business_day/memorial_day/tests.rb +22 -0
- data/lib/is_business_day/new_years_day.rb +11 -0
- data/lib/is_business_day/new_years_day/calculations.rb +19 -0
- data/lib/is_business_day/new_years_day/tests.rb +17 -0
- data/lib/is_business_day/thanksgiving.rb +12 -0
- data/lib/is_business_day/thanksgiving/calculations.rb +24 -0
- data/lib/is_business_day/thanksgiving/tests.rb +22 -0
- data/lib/is_business_day/version.rb +1 -1
- data/spec/is_business_day/christmas_spec.rb +147 -0
- data/spec/is_business_day/fourth_of_july_spec.rb +70 -0
- data/spec/is_business_day/is_business_day_spec.rb +50 -0
- data/spec/is_business_day/labor_day_spec.rb +78 -0
- data/spec/is_business_day/memorial_day_spec.rb +73 -0
- data/spec/is_business_day/new_years_day_spec.rb +65 -0
- data/spec/is_business_day/thanksgiving_spec.rb +73 -0
- data/spec/spec_helper.rb +14 -0
- metadata +95 -36
- data/.gitignore +0 -4
- data/.travis.yml +0 -5
- data/Gemfile +0 -4
- data/Guardfile +0 -4
- data/is_business_day.gemspec +0 -26
- data/lib/is_business_day/active_support/core_ext/date/calculations.rb +0 -6
- data/lib/is_business_day/active_support/core_ext/time/calculations.rb +0 -6
- data/lib/is_business_day/digitalopera/business_day_calculations.rb +0 -55
- data/lib/is_business_day/digitalopera/holiday_calculations.rb +0 -130
- data/lib/rails/generators/is_business_day/install/install_generator.rb +0 -16
- data/lib/rails/generators/is_business_day/install/templates/is_business_day.rb +0 -1
- data/spec/active_support/core_ext/date/calculations_spec.rb +0 -165
- data/spec/active_support/core_ext/time/calculations_spec.rb +0 -165
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 DIGITALOPERA, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
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:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# is_business_day
|
2
|
-
[![
|
2
|
+
[ ![Codeship Status for digitalopera/is_business_day](https://www.codeship.io/projects/669283c0-2e49-0131-a1cd-5aae07d9e667/status?branch=master)](https://www.codeship.io/projects/9396)
|
3
3
|
|
4
4
|
*is_business_day* extends the Date and Time objects in Ruby to include some simple helpers for determining if a specific date is a business day, or not. It also includes helpers for getting the next or previous business days as well as testing for major holidays.
|
5
5
|
|
@@ -39,8 +39,6 @@ Valid business days are currently Monday thru Friday. In addition, the followin
|
|
39
39
|
- Christmas Eve
|
40
40
|
- Christmas Day
|
41
41
|
|
42
|
-
NOTE: A future release will allow customization of these "holidays" using either a YAML or initializer file.
|
43
|
-
|
44
42
|
##### is_a_holiday?
|
45
43
|
|
46
44
|
```rb
|
@@ -95,6 +93,10 @@ Date.today.thanksgiving_day_this_year
|
|
95
93
|
=> #<Date ...>
|
96
94
|
```
|
97
95
|
|
96
|
+
## TODO
|
97
|
+
|
98
|
+
A future release will allow customization of these "holidays" using either a YAML or initializer file.
|
99
|
+
|
98
100
|
## Bug Reports
|
99
101
|
|
100
102
|
If you run into any issues feel free to create an issue on GitHub. The more information you can provide about the issue and your environment the better. We'll do the best we can to resolve issues quickly.
|
data/lib/is_business_day.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
require "active_support"
|
1
2
|
require "is_business_day/version"
|
2
|
-
require "is_business_day/
|
3
|
-
require "is_business_day/
|
4
|
-
require "is_business_day/
|
5
|
-
|
3
|
+
require "is_business_day/holidays"
|
4
|
+
require "is_business_day/business_days"
|
5
|
+
require "is_business_day/helpers"
|
6
|
+
|
7
|
+
module IsBusinessDay
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
include Holidays
|
10
|
+
include BusinessDays
|
11
|
+
include Helpers
|
12
|
+
end
|
13
|
+
|
14
|
+
class Time
|
15
|
+
include IsBusinessDay
|
16
|
+
end
|
17
|
+
|
18
|
+
class Date
|
19
|
+
include IsBusinessDay
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module BusinessDays
|
3
|
+
module Calculations
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def next_business_day
|
8
|
+
next_business_day = self
|
9
|
+
|
10
|
+
begin
|
11
|
+
next_business_day = (next_business_day.to_time + 1.day).to_date
|
12
|
+
end while next_business_day.is_not_a_business_day?
|
13
|
+
|
14
|
+
return_business_day next_business_day
|
15
|
+
end
|
16
|
+
|
17
|
+
def previous_business_day
|
18
|
+
previous_business_day = self
|
19
|
+
|
20
|
+
begin
|
21
|
+
previous_business_day = (previous_business_day.to_time - 1.day).to_date
|
22
|
+
end while previous_business_day.is_not_a_business_day?
|
23
|
+
|
24
|
+
return_business_day previous_business_day
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module BusinessDays
|
3
|
+
module Tests
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def is_a_business_day?
|
8
|
+
(self.monday? || self.tuesday? || self.wednesday? || self.thursday? || self.friday?) && self.is_not_a_holiday?
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_not_a_business_day?
|
12
|
+
!is_a_business_day?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "christmas/eve/calculations"
|
2
|
+
require_relative "christmas/eve/tests"
|
3
|
+
require_relative "christmas/day/calculations"
|
4
|
+
require_relative "christmas/day/tests"
|
5
|
+
|
6
|
+
module IsBusinessDay
|
7
|
+
module Christmas
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
include Eve::Calculations
|
11
|
+
include Eve::Tests
|
12
|
+
include Day::Calculations
|
13
|
+
include Day::Tests
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module Christmas
|
3
|
+
module Day
|
4
|
+
module Calculations
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def christmas_day(date = Date.today)
|
9
|
+
return_business_day Date.parse("12/25/#{ date.year }")
|
10
|
+
end
|
11
|
+
alias_method :xmas_day, :christmas_day
|
12
|
+
end
|
13
|
+
|
14
|
+
included do
|
15
|
+
def christmas_day
|
16
|
+
self.class.christmas_day(self)
|
17
|
+
end
|
18
|
+
alias_method :xmas_day, :christmas_day
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module Christmas
|
3
|
+
module Day
|
4
|
+
module Tests
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def is_christmas_day?
|
9
|
+
self.month == 12 && self.mday == 25
|
10
|
+
end
|
11
|
+
alias_method :is_xmas_day?, :is_christmas_day?
|
12
|
+
|
13
|
+
def is_not_christmas_day?
|
14
|
+
self.month != 12 || self.mday != 25
|
15
|
+
end
|
16
|
+
alias_method :is_not_xmas_day?, :is_not_christmas_day?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module Christmas
|
3
|
+
module Eve
|
4
|
+
module Calculations
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def christmas_eve(date=Date.today)
|
9
|
+
return_business_day Date.parse("12/24/#{ date.year }")
|
10
|
+
end
|
11
|
+
alias_method :xmas_eve, :christmas_eve
|
12
|
+
end
|
13
|
+
|
14
|
+
included do
|
15
|
+
def christmas_eve
|
16
|
+
self.class.christmas_eve(self)
|
17
|
+
end
|
18
|
+
alias_method :xmas_eve, :christmas_eve
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module Christmas
|
3
|
+
module Eve
|
4
|
+
module Tests
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def is_christmas_eve?
|
9
|
+
self.month == 12 && self.mday == 24
|
10
|
+
end
|
11
|
+
alias_method :is_xmas_eve?, :is_christmas_eve?
|
12
|
+
|
13
|
+
def is_not_christmas_eve?
|
14
|
+
self.month != 12 || self.mday != 24
|
15
|
+
end
|
16
|
+
alias_method :is_not_xmas_eve?, :is_not_christmas_eve?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module FourthOfJuly
|
3
|
+
module Calculations
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def fourth_of_july(date=Date.today)
|
8
|
+
return_business_day Date.parse("07/04/#{ date.year }")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
included do
|
13
|
+
def fourth_of_july
|
14
|
+
self.class.fourth_of_july(self)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module FourthOfJuly
|
3
|
+
module Tests
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def is_fourth_of_july?
|
8
|
+
self.month == 7 && self.mday == 4
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_not_fourth_of_july?
|
12
|
+
self.month != 7 || self.mday != 4
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module Helpers
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
private # -------------------------------------------
|
7
|
+
|
8
|
+
def return_business_day(date)
|
9
|
+
if self == Time
|
10
|
+
return date.to_time
|
11
|
+
else
|
12
|
+
return date
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
included do
|
18
|
+
def get_all_specific_days_in_month(day=:monday)
|
19
|
+
date = self.to_date
|
20
|
+
days = date.beginning_of_month.step(date.end_of_month, 1).to_a
|
21
|
+
|
22
|
+
case day
|
23
|
+
when :monday
|
24
|
+
days.map!{ |d| d if d.monday? }
|
25
|
+
when :tuesday
|
26
|
+
days.map!{ |d| d if d.tuesday? }
|
27
|
+
when :wednesday
|
28
|
+
days.map!{ |d| d if d.wednesday? }
|
29
|
+
when :thursday
|
30
|
+
days.map!{ |d| d if d.thursday? }
|
31
|
+
when :friday
|
32
|
+
days.map!{ |d| d if d.friday? }
|
33
|
+
when :saturday
|
34
|
+
days.map!{ |d| d if d.saturday? }
|
35
|
+
when :sunday
|
36
|
+
days.map!{ |d| d if d.sunday? }
|
37
|
+
end
|
38
|
+
|
39
|
+
return days.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
private # -----------------------------------------
|
43
|
+
|
44
|
+
def return_business_day(date = self)
|
45
|
+
if self.class == Time
|
46
|
+
return date.to_time
|
47
|
+
else
|
48
|
+
return date
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "memorial_day"
|
2
|
+
require_relative "fourth_of_july"
|
3
|
+
require_relative "labor_day"
|
4
|
+
require_relative "thanksgiving"
|
5
|
+
require_relative "christmas"
|
6
|
+
require_relative "new_years_day"
|
7
|
+
|
8
|
+
module IsBusinessDay
|
9
|
+
module Holidays
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
include IsBusinessDay::MemorialDay
|
13
|
+
include IsBusinessDay::FourthOfJuly
|
14
|
+
include IsBusinessDay::LaborDay
|
15
|
+
include IsBusinessDay::Thanksgiving
|
16
|
+
include IsBusinessDay::Christmas
|
17
|
+
include IsBusinessDay::NewYearsDay
|
18
|
+
|
19
|
+
included do
|
20
|
+
def is_a_holiday?
|
21
|
+
self.is_memorial_day? || self.is_labor_day? || self.is_thanksgiving_day? || self.is_new_years_day? || self.is_xmas_day? || self.is_xmas_eve? || self.is_fourth_of_july?
|
22
|
+
end
|
23
|
+
alias_method :is_holiday?, :is_a_holiday?
|
24
|
+
|
25
|
+
def is_not_a_holiday?
|
26
|
+
self.is_not_memorial_day? && self.is_not_labor_day? && self.is_not_thanksgiving_day? && self.is_not_new_years_day? && self.is_not_xmas_day? && self.is_not_xmas_eve? && self.is_not_fourth_of_july?
|
27
|
+
end
|
28
|
+
alias_method :is_not_holiday?, :is_not_a_holiday?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module LaborDay
|
3
|
+
module Calculations
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def labor_day(date=Date.today)
|
8
|
+
september = Date.parse("09/01/#{ date.year }")
|
9
|
+
labor_day = september.get_all_specific_days_in_month(:monday).first
|
10
|
+
|
11
|
+
return_business_day labor_day
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
included do
|
16
|
+
def labor_day
|
17
|
+
self.class.labor_day(self)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module IsBusinessDay
|
2
|
+
module LaborDay
|
3
|
+
module Tests
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def is_labor_day?
|
8
|
+
labor_day = self.class.parse("09/01/#{ self.year }").get_all_specific_days_in_month(:monday).first
|
9
|
+
self.month == 9 && self.day == labor_day.day
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_not_labor_day?
|
13
|
+
!is_labor_day?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|