is_business_day 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ before_script: bundle exec rspec spec
5
+ script: rake build
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in is_business_day.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,4 @@
1
+ guard 'rspec', :version => 2, :cli => '--color --format doc' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb}) { |match| "spec/#{match[1]}_spec.rb" }
4
+ end
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # is_business_day
2
+ [![Build Status](https://secure.travis-ci.org/noiseunion/is_business_day.png)](http://travis-ci.org/noiseunion/is_business_day)
3
+
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
+
6
+ ## Installation
7
+
8
+ Add it to your Gemfile
9
+
10
+ `gem "is_business_day"`
11
+
12
+ And then run `bundle install` to install it.
13
+
14
+ ## Usage
15
+
16
+ After installing the gem you can now take advantage of the additional instance methods made available to the standard Ruby Date & Time objects.
17
+
18
+ ### Boolean Test Helpers
19
+
20
+ ##### is_a_business_day?
21
+
22
+ ```rb
23
+ # Test that today is a valid business day
24
+ Date.today.is_a_business_day?
25
+ => true
26
+
27
+ # Test that today is NOT a valid business day
28
+ Date.today.is_not_a_business_day?
29
+ => false
30
+ ```
31
+
32
+ Valid business days are currently Monday thru Friday. In addition, the following major holidays are also recognized as not being valid business days:
33
+
34
+ - New Year's Day
35
+ - Memorial Day
36
+ - Fourth of July
37
+ - Labor Day
38
+ - Thanksgiving Day
39
+ - Christmas Eve
40
+ - Christmas Day
41
+
42
+ NOTE: A future release will allow customization of these "holidays" using either a YAML or initializer file.
43
+
44
+ ##### is_a_holiday?
45
+
46
+ ```rb
47
+ # Test that today is a holiday
48
+ Date.today.is_a_holiday?
49
+ => true
50
+
51
+ # Test that today is not a holiday
52
+ Date.today.is_not_a_holiday?
53
+ => false
54
+ ```
55
+
56
+ This method currently only checks for the previously mentioned holidays.
57
+
58
+ You can also test the following specific holidays using the format `is_[holiday_name]_day?` and `is_not_[holiday_name]_day?` respectively.
59
+
60
+ ```rb
61
+ # Test for labor day
62
+ Date.today.is_labor_day?
63
+ => false
64
+
65
+ Date.today.is_not_labor_day?
66
+ => true
67
+ ```
68
+
69
+ ### Additional Helpers
70
+
71
+ ```rb
72
+ # next_business_day
73
+ # Returns the next valid business day accounting for weekends and/or holidays.
74
+ Date.today.next_business_day
75
+ => #<Date ...>
76
+
77
+ # previous_business_day
78
+ # Returns the previous valid business day account for weekends and/or holidays.
79
+ Date.today.previous_business_day
80
+ => #<Date ...>
81
+
82
+ # memorial_day_this_year
83
+ # Returns the date memorial day falls on for the year identified by the date instance
84
+ Date.today.memorial_day_this_year
85
+ => #<Date ...>
86
+
87
+ # labor_day_this_year
88
+ # Returns the date labor day falls on for the year identified by the date instance
89
+ Date.today.labor_day_this_year
90
+ => #<Date ...>
91
+
92
+ # thanksgiving_day_this_year
93
+ # Returns the date thanksgiving falls on for the year identified by the date instance
94
+ Date.today.thanksgiving_day_this_year
95
+ => #<Date ...>
96
+ ```
97
+
98
+ ## Bug Reports
99
+
100
+ 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.
101
+
102
+ ## License
103
+
104
+ MIT License. Copyright &copy; 2012 Digital Opera, LLC. [www.digitalopera.com](http://www.digitalopera.com/ "Digital Opera, LLC")
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "is_business_day/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "is_business_day"
7
+ s.version = IsBusinessDay::VERSION
8
+ s.authors = ["JD Hendrickson"]
9
+ s.email = ["jd@digitalopera.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Simple business day detection}
12
+ s.description = %q{Adds some methods to the Ruby Date object for testing whether or not a specific date falls on a valid business day or not}
13
+
14
+ s.rubyforge_project = "is_business_day"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # Dependencies --------------------------------------------------------------
22
+ s.add_development_dependency "rspec", "~> 2.6"
23
+ s.add_development_dependency "guard-rspec", "~> 0.0"
24
+ s.add_development_dependency "rake", "~> 0.9.2"
25
+ s.add_dependency "activesupport", "~>3.0"
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'date'
2
+
3
+ class Date
4
+ include DigitalOpera::BusinessDayCalculations
5
+ include DigitalOpera::HolidayCalculations
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'time'
2
+
3
+ class Time
4
+ include DigitalOpera::BusinessDayCalculations
5
+ include DigitalOpera::HolidayCalculations
6
+ end
@@ -0,0 +1,55 @@
1
+ require 'active_support/core_ext/numeric/time'
2
+ require 'active_support/core_ext/date/calculations'
3
+ require 'active_support/core_ext/time/calculations'
4
+
5
+ module DigitalOpera
6
+ module BusinessDayCalculations
7
+ # Returns TRUE || FALSE if the date is a valid business day
8
+ # this also accounts for holidays
9
+ #
10
+ def is_a_business_day?
11
+ (self.monday? || self.tuesday? || self.wednesday? || self.thursday? || self.friday?)
12
+ end
13
+
14
+ # Returns TRUE || FALSE if the date IS NOT a valid business day
15
+ # this also accounts for holidays
16
+ #
17
+ def is_not_a_business_day?
18
+ self.saturday? || self.sunday?
19
+ end
20
+
21
+ # Returns the first business day following the date. This will account for
22
+ # ANY non-business day, holidays included.
23
+ #
24
+ def next_business_day
25
+ next_business_day = self
26
+
27
+ begin
28
+ next_business_day = (next_business_day.to_time + 1.day).to_date
29
+ end while next_business_day.is_not_a_business_day?
30
+
31
+ if self.class.name == "Time"
32
+ return next_business_day.to_time
33
+ else
34
+ return next_business_day
35
+ end
36
+ end
37
+
38
+ # Returns the first business day preceding the date. This will account for
39
+ # ANY non-business day, holidays included.
40
+ #
41
+ def previous_business_day
42
+ previous_business_day = self
43
+
44
+ begin
45
+ previous_business_day = (previous_business_day.to_time - 1.day).to_date
46
+ end while previous_business_day.is_not_a_business_day?
47
+
48
+ if self.class.name == "Time"
49
+ return previous_business_day.to_time
50
+ else
51
+ return previous_business_day
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,130 @@
1
+ require 'active_support/core_ext/numeric/time'
2
+ require 'active_support/core_ext/date/calculations'
3
+ require 'active_support/core_ext/time/calculations'
4
+ require 'active_support/core_ext/array/access'
5
+
6
+ module DigitalOpera
7
+ module HolidayCalculations
8
+ # Returns TRUE || FALSE if the date is a recognized holiday
9
+ #
10
+ def is_a_holiday?
11
+ 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?
12
+ end
13
+
14
+ # Returns TRUE || FALSE if the date IS NOT a recognized holiday
15
+ #
16
+ def is_not_a_holiday?
17
+ 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?
18
+ end
19
+
20
+ # Labor Day (First monday in september)
21
+ # http://en.wikipedia.org/wiki/Labor_Day
22
+ #
23
+ def labor_day_this_year
24
+ september = Date.parse("01/09/#{self.year}")
25
+ labor_day = september.beginning_of_month.step(september.end_of_month, 1).map{ |day| day if day.monday? }.compact.first
26
+ if self.class.name == "Time"
27
+ return labor_day.to_time
28
+ else
29
+ return labor_day
30
+ end
31
+ end
32
+
33
+ def is_labor_day?
34
+ self == self.labor_day_this_year
35
+ end
36
+
37
+ def is_not_labor_day?
38
+ self != self.labor_day_this_year
39
+ end
40
+
41
+ # Memorial Day (Last monday in may)
42
+ # http://en.wikipedia.org/wiki/Memorial_Day
43
+ #
44
+ def memorial_day_this_year
45
+ may = Date.parse("01/05/#{self.year}")
46
+ memorial_day = may.beginning_of_month.step(may.end_of_month, 1).map{ |day| day if day.monday? }.compact.last
47
+ if self.class.name == "Time"
48
+ return memorial_day.to_time
49
+ else
50
+ return memorial_day
51
+ end
52
+ end
53
+
54
+ def is_memorial_day?
55
+ self == self.memorial_day_this_year
56
+ end
57
+
58
+ def is_not_memorial_day?
59
+ self != self.memorial_day_this_year
60
+ end
61
+
62
+ # Thanksgiving Day (fourth thursday in november in the US)
63
+ # http://en.wikipedia.org/wiki/Thanksgiving
64
+ #
65
+ def thanksgiving_day_this_year
66
+ november = Date.parse("01/11/#{self.year}")
67
+ thanksgiving_day = november.beginning_of_month.step(november.end_of_month, 1).map{ |day| day if day.thursday? }.compact.fourth
68
+ if self.class.name == "Time"
69
+ return thanksgiving_day.to_time
70
+ else
71
+ return thanksgiving_day
72
+ end
73
+ end
74
+
75
+ def is_thanksgiving_day?
76
+ self == self.thanksgiving_day_this_year
77
+ end
78
+
79
+ def is_not_thanksgiving_day?
80
+ self != self.thanksgiving_day_this_year
81
+ end
82
+
83
+ # Christmas Day (December 25th) & Christmas Eve (December 24th)
84
+ # Since these holidays do not change from year to year, we are only providing
85
+ # boolean checks
86
+ #
87
+ def is_christmas_day?
88
+ self.month == 12 && self.mday == 25
89
+ end
90
+ alias_method :is_xmas_day?, :is_christmas_day?
91
+
92
+ def is_not_christmas_day?
93
+ self.month != 12 || self.mday != 25
94
+ end
95
+ alias_method :is_not_xmas_day?, :is_not_christmas_day?
96
+
97
+ def is_christmas_eve?
98
+ self.month == 12 && self.mday == 24
99
+ end
100
+ alias_method :is_xmas_eve?, :is_christmas_eve?
101
+
102
+ def is_not_christmas_eve?
103
+ self.month != 12 || self.mday != 24
104
+ end
105
+ alias_method :is_not_xmas_eve?, :is_not_christmas_eve?
106
+
107
+ # New Years Day (January 1st)
108
+ # Since this holiday does not change, it is always January 1st, we are only providing
109
+ # boolean checks
110
+ #
111
+ def is_new_years_day?
112
+ self.yday == 1
113
+ end
114
+
115
+ def is_not_new_years_day?
116
+ self.yday != 1
117
+ end
118
+
119
+ # July 4th
120
+ # Since this holiday does not change we are only providing boolean checks
121
+ #
122
+ def is_fourth_of_july?
123
+ self.month == 7 && self.mday == 4
124
+ end
125
+
126
+ def is_not_fourth_of_july?
127
+ self.month != 7 || self.mday != 4
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,3 @@
1
+ module IsBusinessDay
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "is_business_day/version"
2
+ require "is_business_day/digitalopera/business_day_calculations"
3
+ require "is_business_day/digitalopera/holiday_calculations"
4
+ require "is_business_day/active_support/core_ext/date/calculations"
5
+ require "is_business_day/active_support/core_ext/time/calculations"
@@ -0,0 +1,16 @@
1
+
2
+ module IsBusinessDay
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Creates an initializer file that can be used to specify business day rules"
6
+
7
+ def self.source_root
8
+ @_ibd_source_root ||= File.expand_path("../templates", __FILE__)
9
+ end
10
+
11
+ def create_initializer_file
12
+ template "is_business_day.rb", File.join('config/initializers', "is_business_day.rb")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ # is_business_day initializer
@@ -0,0 +1,151 @@
1
+ require "is_business_day"
2
+
3
+ describe Date do
4
+ it "should know that monday is a valid business day" do
5
+ Date.parse("26/03/2012").is_a_business_day?.should be_true
6
+ end
7
+
8
+ it "should know that tuesday is a valid business day" do
9
+ Date.parse("27/03/2012").is_a_business_day?.should be_true
10
+ end
11
+
12
+ it "should know that wednesday is a valid business day" do
13
+ Date.parse("28/03/2012").is_a_business_day?.should be_true
14
+ end
15
+
16
+ it "should know that thursday is a valid business day" do
17
+ Date.parse("29/03/2012").is_a_business_day?.should be_true
18
+ end
19
+
20
+ it "should know that friday is a valid business day" do
21
+ Date.parse("30/03/2012").is_a_business_day?.should be_true
22
+ end
23
+
24
+ it "should know that saturday is not a valid business day" do
25
+ Date.parse("31/03/2012").is_not_a_business_day?.should be_true
26
+ Date.parse("31/03/2012").is_a_business_day?.should be_false
27
+ end
28
+
29
+ it "should know that sunday is not a valid business day" do
30
+ Date.parse("01/04/2012").is_not_a_business_day?.should be_true
31
+ Date.parse("01/04/2012").is_a_business_day?.should be_false
32
+ end
33
+
34
+ it "should know that the next business day for a friday is monday" do
35
+ next_business_day = Date.parse("30/03/2012").next_business_day
36
+ next_business_day.should eql(Date.parse("02/04/2012"))
37
+ next_business_day.monday?.should be_true
38
+ end
39
+
40
+ it "should know that the business day previous a monday was friday" do
41
+ previous_business_day = Date.parse("26/03/2012").previous_business_day
42
+ previous_business_day.should eql(Date.parse("23/03/2012"))
43
+ previous_business_day.friday?.should be_true
44
+ end
45
+
46
+ it "should know when labor day is" do
47
+ test_date = Date.parse("06/06/2012")
48
+ test_date.labor_day_this_year.should eql(Date.parse("03/09/2012"))
49
+ end
50
+
51
+ it "should know when memorial day is" do
52
+ test_date = Date.parse("06/06/2012")
53
+ test_date.memorial_day_this_year.should eql(Date.parse("28/05/2012"))
54
+ end
55
+
56
+ it "should know when thanksgiving is" do
57
+ test_date = Date.parse("06/06/2012")
58
+ test_date.thanksgiving_day_this_year.should eql(Date.parse("22/11/2012"))
59
+ end
60
+
61
+ it "should be able to tell if it is memorial day" do
62
+ bad_date = Date.parse("06/06/2012")
63
+ good_date = Date.parse("28/05/2012")
64
+ bad_date.is_memorial_day?.should be_false
65
+ bad_date.is_not_memorial_day?.should be_true
66
+ good_date.is_memorial_day?.should be_true
67
+ good_date.is_not_memorial_day?.should be_false
68
+ end
69
+
70
+ it "should be able to tell if it is labor day" do
71
+ bad_date = Date.parse("06/06/2012")
72
+ good_date = Date.parse("03/09/2012")
73
+ bad_date.is_labor_day?.should be_false
74
+ bad_date.is_not_labor_day?.should be_true
75
+ good_date.is_labor_day?.should be_true
76
+ good_date.is_not_labor_day?.should be_false
77
+ end
78
+
79
+ it "should be able to tell if it is thanksgiving day" do
80
+ bad_date = Date.parse("06/06/2012")
81
+ good_date = Date.parse("22/11/2012")
82
+ bad_date.is_thanksgiving_day?.should be_false
83
+ bad_date.is_not_thanksgiving_day?.should be_true
84
+ good_date.is_thanksgiving_day?.should be_true
85
+ good_date.is_not_thanksgiving_day?.should be_false
86
+ end
87
+
88
+ it "should be able to tell if it is xmas day" do
89
+ bad_date = Date.parse("06/06/2012")
90
+ good_date = Date.parse("25/12/2012")
91
+ bad_date.is_christmas_day?.should be_false
92
+ bad_date.is_not_christmas_day?.should be_true
93
+ good_date.is_christmas_day?.should be_true
94
+ good_date.is_not_christmas_day?.should be_false
95
+ end
96
+
97
+ it "should be able to tell if it is xmas eve" do
98
+ bad_date = Date.parse("06/06/2012")
99
+ good_date = Date.parse("24/12/2012")
100
+ bad_date.is_christmas_eve?.should be_false
101
+ bad_date.is_not_christmas_eve?.should be_true
102
+ good_date.is_christmas_eve?.should be_true
103
+ good_date.is_not_christmas_eve?.should be_false
104
+ end
105
+
106
+ it "should be able to tell if it is new year's day" do
107
+ bad_date = Date.parse("06/06/2012")
108
+ good_date = Date.parse("01/01/2012")
109
+ bad_date.is_new_years_day?.should be_false
110
+ bad_date.is_not_new_years_day?.should be_true
111
+ good_date.is_new_years_day?.should be_true
112
+ good_date.is_not_new_years_day?.should be_false
113
+ end
114
+
115
+ it "should be able to tell if it is the fourth of july" do
116
+ bad_date = Date.parse("06/06/2012")
117
+ good_date = Date.parse("04/07/2012")
118
+ bad_date.is_fourth_of_july?.should be_false
119
+ bad_date.is_not_fourth_of_july?.should be_true
120
+ good_date.is_fourth_of_july?.should be_true
121
+ good_date.is_not_fourth_of_july?.should be_false
122
+ end
123
+
124
+ it "should be able to tell if it is a holiday or not" do
125
+ new_years_day = Date.parse("01/01/2012")
126
+ memorial_day = Date.parse("28/05/2012")
127
+ fourth_of_july = Date.parse("04/07/2012")
128
+ labor_day = Date.parse("03/09/2012")
129
+ thanksgiving_day = Date.parse("22/11/2012")
130
+ xmas_eve = Date.parse("24/12/2012")
131
+ xmas_day = Date.parse("25/12/2012")
132
+ bad_date = Date.parse("06/06/2012")
133
+
134
+ new_years_day.is_a_holiday?.should be_true
135
+ new_years_day.is_not_a_holiday?.should be_false
136
+ memorial_day.is_a_holiday?.should be_true
137
+ memorial_day.is_not_a_holiday?.should be_false
138
+ fourth_of_july.is_a_holiday?.should be_true
139
+ fourth_of_july.is_not_a_holiday?.should be_false
140
+ labor_day.is_a_holiday?.should be_true
141
+ labor_day.is_not_a_holiday?.should be_false
142
+ thanksgiving_day.is_a_holiday?.should be_true
143
+ thanksgiving_day.is_not_a_holiday?.should be_false
144
+ xmas_eve.is_a_holiday?.should be_true
145
+ xmas_eve.is_not_a_holiday?.should be_false
146
+ xmas_day.is_a_holiday?.should be_true
147
+ xmas_day.is_not_a_holiday?.should be_false
148
+ bad_date.is_a_holiday?.should be_false
149
+ bad_date.is_not_a_holiday?.should be_true
150
+ end
151
+ end
@@ -0,0 +1,151 @@
1
+ require "is_business_day"
2
+
3
+ describe Time do
4
+ it "should know that monday is a valid business day" do
5
+ Time.parse("26/03/2012").is_a_business_day?.should be_true
6
+ end
7
+
8
+ it "should know that tuesday is a valid business day" do
9
+ Time.parse("27/03/2012").is_a_business_day?.should be_true
10
+ end
11
+
12
+ it "should know that wednesday is a valid business day" do
13
+ Time.parse("28/03/2012").is_a_business_day?.should be_true
14
+ end
15
+
16
+ it "should know that thursday is a valid business day" do
17
+ Time.parse("29/03/2012").is_a_business_day?.should be_true
18
+ end
19
+
20
+ it "should know that friday is a valid business day" do
21
+ Time.parse("30/03/2012").is_a_business_day?.should be_true
22
+ end
23
+
24
+ it "should know that saturday is not a valid business day" do
25
+ Time.parse("31/03/2012").is_not_a_business_day?.should be_true
26
+ Time.parse("31/03/2012").is_a_business_day?.should be_false
27
+ end
28
+
29
+ it "should know that sunday is not a valid business day" do
30
+ Time.parse("01/04/2012").is_not_a_business_day?.should be_true
31
+ Time.parse("01/04/2012").is_a_business_day?.should be_false
32
+ end
33
+
34
+ it "should know that the next business day for a friday is monday" do
35
+ next_business_day = Time.parse("30/03/2012").next_business_day
36
+ next_business_day.should eql(Time.parse("02/04/2012"))
37
+ next_business_day.monday?.should be_true
38
+ end
39
+
40
+ it "should know that the business day previous a monday was friday" do
41
+ previous_business_day = Time.parse("26/03/2012").previous_business_day
42
+ previous_business_day.should eql(Time.parse("23/03/2012"))
43
+ previous_business_day.friday?.should be_true
44
+ end
45
+
46
+ it "should know when labor day is" do
47
+ test_time = Time.parse("06/06/2012")
48
+ test_time.labor_day_this_year.should eql(Time.parse("03/09/2012"))
49
+ end
50
+
51
+ it "should know when memorial day is" do
52
+ test_time = Time.parse("06/06/2012")
53
+ test_time.memorial_day_this_year.should eql(Time.parse("28/05/2012"))
54
+ end
55
+
56
+ it "should know when thanksgiving is" do
57
+ test_time = Time.parse("06/06/2012")
58
+ test_time.thanksgiving_day_this_year.should eql(Time.parse("22/11/2012"))
59
+ end
60
+
61
+ it "should be able to tell if it is memorial day" do
62
+ bad_date = Time.parse("06/06/2012")
63
+ good_date = Time.parse("28/05/2012")
64
+ bad_date.is_memorial_day?.should be_false
65
+ bad_date.is_not_memorial_day?.should be_true
66
+ good_date.is_memorial_day?.should be_true
67
+ good_date.is_not_memorial_day?.should be_false
68
+ end
69
+
70
+ it "should be able to tell if it is labor day" do
71
+ bad_date = Time.parse("06/06/2012")
72
+ good_date = Time.parse("03/09/2012")
73
+ bad_date.is_labor_day?.should be_false
74
+ bad_date.is_not_labor_day?.should be_true
75
+ good_date.is_labor_day?.should be_true
76
+ good_date.is_not_labor_day?.should be_false
77
+ end
78
+
79
+ it "should be able to tell if it is thanksgiving day" do
80
+ bad_date = Time.parse("06/06/2012")
81
+ good_date = Time.parse("22/11/2012")
82
+ bad_date.is_thanksgiving_day?.should be_false
83
+ bad_date.is_not_thanksgiving_day?.should be_true
84
+ good_date.is_thanksgiving_day?.should be_true
85
+ good_date.is_not_thanksgiving_day?.should be_false
86
+ end
87
+
88
+ it "should be able to tell if it is xmas day" do
89
+ bad_date = Time.parse("06/06/2012")
90
+ good_date = Time.parse("25/12/2012")
91
+ bad_date.is_christmas_day?.should be_false
92
+ bad_date.is_not_christmas_day?.should be_true
93
+ good_date.is_christmas_day?.should be_true
94
+ good_date.is_not_christmas_day?.should be_false
95
+ end
96
+
97
+ it "should be able to tell if it is xmas eve" do
98
+ bad_date = Time.parse("06/06/2012")
99
+ good_date = Time.parse("24/12/2012")
100
+ bad_date.is_christmas_eve?.should be_false
101
+ bad_date.is_not_christmas_eve?.should be_true
102
+ good_date.is_christmas_eve?.should be_true
103
+ good_date.is_not_christmas_eve?.should be_false
104
+ end
105
+
106
+ it "should be able to tell if it is new year's day" do
107
+ bad_date = Time.parse("06/06/2012")
108
+ good_date = Time.parse("01/01/2012")
109
+ bad_date.is_new_years_day?.should be_false
110
+ bad_date.is_not_new_years_day?.should be_true
111
+ good_date.is_new_years_day?.should be_true
112
+ good_date.is_not_new_years_day?.should be_false
113
+ end
114
+
115
+ it "should be able to tell if it is the fourth of july" do
116
+ bad_date = Time.parse("06/06/2012")
117
+ good_date = Time.parse("04/07/2012")
118
+ bad_date.is_fourth_of_july?.should be_false
119
+ bad_date.is_not_fourth_of_july?.should be_true
120
+ good_date.is_fourth_of_july?.should be_true
121
+ good_date.is_not_fourth_of_july?.should be_false
122
+ end
123
+
124
+ it "should be able to tell if it is a holiday or not" do
125
+ new_years_day = Time.parse("01/01/2012")
126
+ memorial_day = Time.parse("28/05/2012")
127
+ fourth_of_july = Time.parse("04/07/2012")
128
+ labor_day = Time.parse("03/09/2012")
129
+ thanksgiving_day = Time.parse("22/11/2012")
130
+ xmas_eve = Time.parse("24/12/2012")
131
+ xmas_day = Time.parse("25/12/2012")
132
+ bad_date = Time.parse("06/06/2012")
133
+
134
+ new_years_day.is_a_holiday?.should be_true
135
+ new_years_day.is_not_a_holiday?.should be_false
136
+ memorial_day.is_a_holiday?.should be_true
137
+ memorial_day.is_not_a_holiday?.should be_false
138
+ fourth_of_july.is_a_holiday?.should be_true
139
+ fourth_of_july.is_not_a_holiday?.should be_false
140
+ labor_day.is_a_holiday?.should be_true
141
+ labor_day.is_not_a_holiday?.should be_false
142
+ thanksgiving_day.is_a_holiday?.should be_true
143
+ thanksgiving_day.is_not_a_holiday?.should be_false
144
+ xmas_eve.is_a_holiday?.should be_true
145
+ xmas_eve.is_not_a_holiday?.should be_false
146
+ xmas_day.is_a_holiday?.should be_true
147
+ xmas_day.is_not_a_holiday?.should be_false
148
+ bad_date.is_a_holiday?.should be_false
149
+ bad_date.is_not_a_holiday?.should be_true
150
+ end
151
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_business_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - JD Hendrickson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ description: Adds some methods to the Ruby Date object for testing whether or not
79
+ a specific date falls on a valid business day or not
80
+ email:
81
+ - jd@digitalopera.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - Guardfile
90
+ - README.md
91
+ - Rakefile
92
+ - is_business_day.gemspec
93
+ - lib/is_business_day.rb
94
+ - lib/is_business_day/active_support/core_ext/date/calculations.rb
95
+ - lib/is_business_day/active_support/core_ext/time/calculations.rb
96
+ - lib/is_business_day/digitalopera/business_day_calculations.rb
97
+ - lib/is_business_day/digitalopera/holiday_calculations.rb
98
+ - lib/is_business_day/version.rb
99
+ - lib/rails/generators/is_business_day/install/install_generator.rb
100
+ - lib/rails/generators/is_business_day/install/templates/is_business_day.rb
101
+ - spec/active_support/core_ext/date/calculations_spec.rb
102
+ - spec/active_support/core_ext/time/calculations_spec.rb
103
+ homepage: ''
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project: is_business_day
123
+ rubygems_version: 1.8.18
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Simple business day detection
127
+ test_files:
128
+ - spec/active_support/core_ext/date/calculations_spec.rb
129
+ - spec/active_support/core_ext/time/calculations_spec.rb
130
+ has_rdoc: