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.
Files changed (51) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +5 -3
  3. data/lib/is_business_day.rb +19 -4
  4. data/lib/is_business_day/business_days.rb +11 -0
  5. data/lib/is_business_day/business_days/calculations.rb +29 -0
  6. data/lib/is_business_day/business_days/tests.rb +17 -0
  7. data/lib/is_business_day/christmas.rb +15 -0
  8. data/lib/is_business_day/christmas/day/calculations.rb +23 -0
  9. data/lib/is_business_day/christmas/day/tests.rb +21 -0
  10. data/lib/is_business_day/christmas/eve/calculations.rb +23 -0
  11. data/lib/is_business_day/christmas/eve/tests.rb +21 -0
  12. data/lib/is_business_day/fourth_of_july.rb +11 -0
  13. data/lib/is_business_day/fourth_of_july/calculations.rb +19 -0
  14. data/lib/is_business_day/fourth_of_july/tests.rb +17 -0
  15. data/lib/is_business_day/helpers.rb +53 -0
  16. data/lib/is_business_day/holidays.rb +31 -0
  17. data/lib/is_business_day/labor_day.rb +11 -0
  18. data/lib/is_business_day/labor_day/calculations.rb +22 -0
  19. data/lib/is_business_day/labor_day/tests.rb +18 -0
  20. data/lib/is_business_day/memorial_day.rb +11 -0
  21. data/lib/is_business_day/memorial_day/calculations.rb +24 -0
  22. data/lib/is_business_day/memorial_day/tests.rb +22 -0
  23. data/lib/is_business_day/new_years_day.rb +11 -0
  24. data/lib/is_business_day/new_years_day/calculations.rb +19 -0
  25. data/lib/is_business_day/new_years_day/tests.rb +17 -0
  26. data/lib/is_business_day/thanksgiving.rb +12 -0
  27. data/lib/is_business_day/thanksgiving/calculations.rb +24 -0
  28. data/lib/is_business_day/thanksgiving/tests.rb +22 -0
  29. data/lib/is_business_day/version.rb +1 -1
  30. data/spec/is_business_day/christmas_spec.rb +147 -0
  31. data/spec/is_business_day/fourth_of_july_spec.rb +70 -0
  32. data/spec/is_business_day/is_business_day_spec.rb +50 -0
  33. data/spec/is_business_day/labor_day_spec.rb +78 -0
  34. data/spec/is_business_day/memorial_day_spec.rb +73 -0
  35. data/spec/is_business_day/new_years_day_spec.rb +65 -0
  36. data/spec/is_business_day/thanksgiving_spec.rb +73 -0
  37. data/spec/spec_helper.rb +14 -0
  38. metadata +95 -36
  39. data/.gitignore +0 -4
  40. data/.travis.yml +0 -5
  41. data/Gemfile +0 -4
  42. data/Guardfile +0 -4
  43. data/is_business_day.gemspec +0 -26
  44. data/lib/is_business_day/active_support/core_ext/date/calculations.rb +0 -6
  45. data/lib/is_business_day/active_support/core_ext/time/calculations.rb +0 -6
  46. data/lib/is_business_day/digitalopera/business_day_calculations.rb +0 -55
  47. data/lib/is_business_day/digitalopera/holiday_calculations.rb +0 -130
  48. data/lib/rails/generators/is_business_day/install/install_generator.rb +0 -16
  49. data/lib/rails/generators/is_business_day/install/templates/is_business_day.rb +0 -1
  50. data/spec/active_support/core_ext/date/calculations_spec.rb +0 -165
  51. data/spec/active_support/core_ext/time/calculations_spec.rb +0 -165
@@ -0,0 +1,24 @@
1
+ module IsBusinessDay
2
+ module MemorialDay
3
+ module Calculations
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def memorial_day(date=Date.today)
8
+ memorial_day = Date
9
+ .parse("05/01/#{ date.year }")
10
+ .get_all_specific_days_in_month(:monday)
11
+ .last
12
+
13
+ return_business_day memorial_day
14
+ end
15
+ end
16
+
17
+ included do
18
+ def memorial_day
19
+ self.class.memorial_day(self)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module IsBusinessDay
2
+ module MemorialDay
3
+ module Tests
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ def is_memorial_day?
8
+ memorial_day = self.class
9
+ .parse("05/01/#{ self.year }")
10
+ .get_all_specific_days_in_month(:monday)
11
+ .last
12
+
13
+ self.month == 5 && self.day == memorial_day.day
14
+ end
15
+
16
+ def is_not_memorial_day?
17
+ !is_memorial_day?
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "new_years_day/calculations"
2
+ require_relative "new_years_day/tests"
3
+
4
+ module IsBusinessDay
5
+ module NewYearsDay
6
+ extend ActiveSupport::Concern
7
+
8
+ include Calculations
9
+ include Tests
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module IsBusinessDay
2
+ module NewYearsDay
3
+ module Calculations
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def new_years_day(date=Date.today)
8
+ return_business_day Date.parse("01/01/#{ date.year }")
9
+ end
10
+ end
11
+
12
+ included do
13
+ def new_years_day
14
+ self.class.new_years_day(self)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module IsBusinessDay
2
+ module NewYearsDay
3
+ module Tests
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ def is_new_years_day?
8
+ self.yday == 1
9
+ end
10
+
11
+ def is_not_new_years_day?
12
+ self.yday != 1
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'thanksgiving/calculations'
2
+ require_relative 'thanksgiving/tests'
3
+
4
+ module IsBusinessDay
5
+ module Thanksgiving
6
+ extend ActiveSupport::Concern
7
+
8
+ include Calculations
9
+ include Tests
10
+
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module IsBusinessDay
2
+ module Thanksgiving
3
+ module Calculations
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def thanksgiving_day(date = Date.today)
8
+ turkey_day = Date
9
+ .parse("11/01/#{ date.year }")
10
+ .get_all_specific_days_in_month(:thursday)
11
+ .last
12
+
13
+ return_business_day turkey_day
14
+ end
15
+ end
16
+
17
+ included do
18
+ def thanksgiving_day
19
+ self.class.thanksgiving_day(self)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module IsBusinessDay
2
+ module Thanksgiving
3
+ module Tests
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ def is_thanksgiving_day?
8
+ turkey_day = self.class
9
+ .parse("11/01/#{ self.year }")
10
+ .get_all_specific_days_in_month(:thursday)
11
+ .last
12
+
13
+ self.month == 11 && self.day == turkey_day.day
14
+ end
15
+
16
+ def is_not_thanksgiving_day?
17
+ !is_thanksgiving_day?
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module IsBusinessDay
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'christmas' do
4
+ let(:some_date){ Date.parse("06/06/1979") }
5
+ let(:some_time){ Time.parse("06/06/1979 6:45pm") }
6
+
7
+ it 'should not return true when testing the some_date' do
8
+ expect(some_date.is_xmas_eve?).to be_false
9
+ expect(some_date.is_xmas_day?).to be_false
10
+ expect(some_time.is_xmas_eve?).to be_false
11
+ expect(some_time.is_xmas_day?).to be_false
12
+ end
13
+
14
+ describe 'christmas eve' do
15
+ context 'Date Class' do
16
+ subject{ Date.christmas_eve }
17
+
18
+ its(:day){ should be 24 }
19
+ its(:month){ should be 12 }
20
+ its(:year){ should be Date.today.year }
21
+ its(:is_a_holiday?){ should be_true }
22
+ its(:is_christmas_eve?){ should be_true }
23
+ its(:is_xmas_eve?){ should be_true }
24
+
25
+ it 'should be a Date object' do
26
+ expect(subject).to be_a Date
27
+ end
28
+ end
29
+
30
+ context 'Time Class' do
31
+ subject{ Time.christmas_eve }
32
+
33
+ its(:day){ should be 24 }
34
+ its(:month){ should be 12 }
35
+ its(:year){ should be Date.today.year }
36
+ its(:is_a_holiday?){ should be_true }
37
+ its(:is_christmas_eve?){ should be_true }
38
+ its(:is_xmas_eve?){ should be_true }
39
+
40
+ it 'should be a Date object' do
41
+ expect(subject).to be_a Time
42
+ end
43
+ end
44
+
45
+ context 'Date instance' do
46
+ subject{ some_date.christmas_eve }
47
+
48
+ its(:day){ should be 24 }
49
+ its(:month){ should be 12 }
50
+ its(:year){ should be some_date.year }
51
+ its(:is_a_holiday?){ should be_true }
52
+ its(:is_christmas_eve?){ should be_true }
53
+ its(:is_xmas_eve?){ should be_true }
54
+ its(:is_not_christmas_eve?){ should be_false }
55
+ its(:is_not_xmas_eve?){ should be_false }
56
+
57
+ it 'should be a Date object' do
58
+ expect(subject).to be_a Date
59
+ end
60
+ end
61
+
62
+ context 'Time instance' do
63
+ subject{ some_time.christmas_eve }
64
+
65
+ its(:day){ should be 24 }
66
+ its(:month){ should be 12 }
67
+ its(:year){ should be some_date.year }
68
+ its(:is_a_holiday?){ should be_true }
69
+ its(:is_christmas_eve?){ should be_true }
70
+ its(:is_xmas_eve?){ should be_true }
71
+ its(:is_not_christmas_eve?){ should be_false }
72
+ its(:is_not_xmas_eve?){ should be_false }
73
+
74
+ it 'should be a Date object' do
75
+ expect(subject).to be_a Time
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'christmas day' do
81
+ context 'Date Class' do
82
+ subject{ Date.christmas_day }
83
+
84
+ its(:day){ should be 25 }
85
+ its(:month){ should be 12 }
86
+ its(:year){ should be Date.today.year }
87
+ its(:is_a_holiday?){ should be_true }
88
+ its(:is_christmas_day?){ should be_true }
89
+ its(:is_xmas_day?){ should be_true }
90
+ its(:is_not_christmas_day?){ should be_false }
91
+
92
+ it 'should be a Date object' do
93
+ expect(subject).to be_a Date
94
+ end
95
+ end
96
+
97
+ context 'Time Class' do
98
+ subject{ Time.christmas_day }
99
+
100
+ its(:day){ should be 25 }
101
+ its(:month){ should be 12 }
102
+ its(:year){ should be Date.today.year }
103
+ its(:is_a_holiday?){ should be_true }
104
+ its(:is_christmas_day?){ should be_true }
105
+ its(:is_xmas_day?){ should be_true }
106
+ its(:is_not_christmas_day?){ should be_false }
107
+
108
+ it 'should be a Date object' do
109
+ expect(subject).to be_a Time
110
+ end
111
+ end
112
+
113
+ context 'a date instance' do
114
+ subject{ some_date.christmas_day }
115
+
116
+ its(:day){ should be 25 }
117
+ its(:month){ should be 12 }
118
+ its(:year){ should be some_date.year }
119
+ its(:is_a_holiday?){ should be_true }
120
+ its(:is_christmas_day?){ should be_true }
121
+ its(:is_xmas_day?){ should be_true }
122
+ its(:is_not_christmas_day?){ should be_false }
123
+ its(:is_not_xmas_day?){ should be_false }
124
+
125
+ it 'should be a Date object' do
126
+ expect(subject).to be_a Date
127
+ end
128
+ end
129
+
130
+ context 'a time instance' do
131
+ subject{ some_time.christmas_day }
132
+
133
+ its(:day){ should be 25 }
134
+ its(:month){ should be 12 }
135
+ its(:year){ should be some_date.year }
136
+ its(:is_a_holiday?){ should be_true }
137
+ its(:is_christmas_day?){ should be_true }
138
+ its(:is_xmas_day?){ should be_true }
139
+ its(:is_not_christmas_day?){ should be_false }
140
+ its(:is_not_xmas_day?){ should be_false }
141
+
142
+ it 'should be a Date object' do
143
+ expect(subject).to be_a Time
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'fourth_of_july' do
4
+ let(:some_date){ Date.parse("06/06/1979") }
5
+ let(:some_time){ Time.parse("06/06/1979 6:45pm") }
6
+ let(:date){ Date.fourth_of_july }
7
+ let(:time){ Time.fourth_of_july }
8
+
9
+ it 'should not be the fourth of july' do
10
+ expect(some_date.is_fourth_of_july?).to be_false
11
+ expect(some_time.is_fourth_of_july?).to be_false
12
+ end
13
+
14
+ it 'should return the proper objects' do
15
+ expect(date).to be_a Date
16
+ expect(time).to be_a Time
17
+ end
18
+
19
+ describe Date do
20
+ context 'Class' do
21
+ subject{ date }
22
+
23
+ its(:day){ should be 4 }
24
+ its(:month){ should be 7 }
25
+ its(:year){ should be Date.today.year }
26
+ its(:is_a_holiday?){ should be_true }
27
+ its(:is_fourth_of_july?){ should be_true }
28
+ its(:is_not_fourth_of_july?){ should be_false }
29
+ its(:is_a_business_day?){ should be_false }
30
+ end
31
+
32
+ context 'instance' do
33
+ subject{ some_date.fourth_of_july }
34
+
35
+ its(:day){ should be 4 }
36
+ its(:month){ should be 7 }
37
+ its(:year){ should be some_date.year }
38
+ its(:is_a_holiday?){ should be_true }
39
+ its(:is_fourth_of_july?){ should be_true }
40
+ its(:is_not_fourth_of_july?){ should be_false }
41
+ its(:is_a_business_day?){ should be_false }
42
+ end
43
+ end
44
+
45
+ describe Time do
46
+ context 'Class' do
47
+ subject{ time }
48
+
49
+ its(:day){ should be 4 }
50
+ its(:month){ should be 7 }
51
+ its(:year){ should be Date.today.year }
52
+ its(:is_a_holiday?){ should be_true }
53
+ its(:is_fourth_of_july?){ should be_true }
54
+ its(:is_not_fourth_of_july?){ should be_false }
55
+ its(:is_a_business_day?){ should be_false }
56
+ end
57
+
58
+ context 'instance' do
59
+ subject{ some_time.fourth_of_july }
60
+
61
+ its(:day){ should be 4 }
62
+ its(:month){ should be 7 }
63
+ its(:year){ should be some_date.year }
64
+ its(:is_a_holiday?){ should be_true }
65
+ its(:is_fourth_of_july?){ should be_true }
66
+ its(:is_not_fourth_of_july?){ should be_false }
67
+ its(:is_a_business_day?){ should be_false }
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'IsBusinessday' do
4
+ let(:business_day){ Date.parse("11/12/13") }
5
+ let(:saturday){ Date.parse("11/16/13") }
6
+ let(:fourth_of_july){ Date.parse("07/04/13") }
7
+ let(:friday){ Date.parse("11/15/13") }
8
+ let(:monday){ Date.parse("11/11/13") }
9
+
10
+ describe 'business day tests' do
11
+ context 'valid business day' do
12
+ subject{ business_day }
13
+ its(:tuesday?){ should be_true }
14
+ its(:is_a_business_day?){ should be_true }
15
+ its(:is_not_a_business_day?){ should be_false }
16
+ its(:next_business_day){ should == Date.parse("11/13/13") }
17
+ its(:previous_business_day){ should == Date.parse("11/11/13") }
18
+ end
19
+
20
+ context 'weekend' do
21
+ subject{ saturday }
22
+ its(:saturday?){ should be_true }
23
+ its(:is_a_business_day?){ should be_false }
24
+ its(:is_not_a_business_day?){ should be_true }
25
+ its(:next_business_day){ should == Date.parse("11/18/13") }
26
+ its(:previous_business_day){ should == friday }
27
+ end
28
+
29
+ context 'friday' do
30
+ subject{ friday }
31
+ its(:friday?){ should be_true }
32
+ its(:next_business_day){ should == Date.parse("11/18/13") }
33
+ its(:previous_business_day){ should == Date.parse("11/14/13") }
34
+ end
35
+ end
36
+
37
+ describe 'holiday tests' do
38
+ context 'business day' do
39
+ subject{ business_day }
40
+ its(:is_a_holiday?){ should be_false }
41
+ its(:is_not_a_holiday?){ should be_true }
42
+ end
43
+
44
+ context 'holiday' do
45
+ subject{ fourth_of_july }
46
+ its(:is_a_holiday?){ should be_true }
47
+ its(:is_not_a_holiday?){ should be_false }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'labor_day' do
4
+ let(:some_date){ Date.parse("06/06/1979") }
5
+ let(:some_time){ Time.parse("06/06/1979 6:45pm") }
6
+ let(:date){ Date.labor_day }
7
+ let(:time){ Time.labor_day }
8
+
9
+ it 'should not be labor day' do
10
+ expect(some_date.is_labor_day?).to be_false
11
+ expect(some_time.is_labor_day?).to be_false
12
+ end
13
+
14
+ it 'should be proper objects' do
15
+ expect(date).to be_a Date
16
+ expect(time).to be_a Time
17
+ end
18
+
19
+ describe Date do
20
+ context 'Class' do
21
+ let(:september){ Date.parse("09/01/#{ date.year }") }
22
+ let(:first_monday){ september.get_all_specific_days_in_month(:monday).first }
23
+ subject{ date }
24
+
25
+ its(:month){ should be 9 }
26
+ its(:day){ should be first_monday.day }
27
+ its(:year){ should be Date.today.year }
28
+ its(:is_a_holiday?){ should be_true }
29
+ its(:is_labor_day?){ should be_true }
30
+ its(:is_not_labor_day?){ should be_false }
31
+ its(:is_a_business_day?){ should be_false }
32
+ end
33
+
34
+ context 'instance' do
35
+ let(:september){ Date.parse("09/01/#{ some_date.year }")}
36
+ let(:first_monday){ september.get_all_specific_days_in_month(:monday).first }
37
+ subject{ some_date.labor_day }
38
+
39
+ its(:month){ should be 9 }
40
+ its(:day){ should be first_monday.day }
41
+ its(:year){ should be some_date.year }
42
+ its(:is_a_holiday?){ should be_true }
43
+ its(:is_labor_day?){ should be_true }
44
+ its(:is_not_labor_day?){ should be_false }
45
+ its(:is_a_business_day?){ should be_false }
46
+ end
47
+ end
48
+
49
+ describe Time do
50
+ context 'Class' do
51
+ let(:september){ Date.parse("09/01/#{ time.year }")}
52
+ let(:first_monday){ september.get_all_specific_days_in_month(:monday).first }
53
+ subject{ time }
54
+
55
+ its(:month){ should be 9 }
56
+ its(:day){ should be first_monday.day }
57
+ its(:year){ should be Date.today.year }
58
+ its(:is_a_holiday?){ should be_true }
59
+ its(:is_labor_day?){ should be_true }
60
+ its(:is_not_labor_day?){ should be_false }
61
+ its(:is_a_business_day?){ should be_false }
62
+ end
63
+
64
+ context 'instance' do
65
+ let(:september){ Date.parse("09/01/#{ some_time.year }")}
66
+ let(:first_monday){ september.get_all_specific_days_in_month(:monday).first }
67
+ subject{ some_time.labor_day }
68
+
69
+ its(:month){ should be 9 }
70
+ its(:day){ should be first_monday.day }
71
+ its(:year){ should be some_time.year }
72
+ its(:is_a_holiday?){ should be_true }
73
+ its(:is_labor_day?){ should be_true }
74
+ its(:is_not_labor_day?){ should be_false }
75
+ its(:is_a_business_day?){ should be_false }
76
+ end
77
+ end
78
+ end