business_time 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +13 -11
- data/lib/business_time.rb +2 -0
- data/lib/business_time/config.rb +25 -0
- data/lib/business_time/version.rb +3 -0
- data/lib/extensions/date.rb +1 -1
- data/lib/extensions/time.rb +1 -2
- data/rails_generators/business_time_config/templates/business_time.rb +1 -1
- data/rails_generators/business_time_config/templates/business_time.yml +7 -1
- metadata +44 -52
- data/.document +0 -5
- data/.gitignore +0 -21
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/test/helper.rb +0 -20
- data/test/test_business_days.rb +0 -69
- data/test/test_business_days_eastern.rb +0 -75
- data/test/test_business_days_utc.rb +0 -75
- data/test/test_business_hours.rb +0 -69
- data/test/test_business_hours_eastern.rb +0 -75
- data/test/test_business_hours_utc.rb +0 -75
- data/test/test_calculating_business_duration.rb +0 -24
- data/test/test_config.rb +0 -25
- data/test/test_date_extensions.rb +0 -33
- data/test/test_fixnum_extensions.rb +0 -17
- data/test/test_time_extensions.rb +0 -42
- data/test/test_time_with_zone_extensions.rb +0 -92
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -69,11 +69,17 @@ I needed this, but taking into account business hours/days and holidays.
|
|
69
69
|
BusinessTime::Config.holidays << three_day_weekend
|
70
70
|
friday_afternoon = Time.parse("July 2nd, 2010, 4:50 pm")
|
71
71
|
tuesday_morning = 1.business_hour.after(friday_afternoon)
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
|
73
|
+
# plus, we can change the work week:
|
74
|
+
# July 9th in 2010 is a Friday.
|
75
|
+
BusinessTime::Config.work_week = [:sun, :mon, :tue, :wed, :thu]
|
76
|
+
thursday_afternoon = Time.parse("July 8th, 2010, 4:50 pm")
|
77
|
+
sunday_morning = 1.business_hour.after(thursday_afternoon)
|
78
|
+
|
79
|
+
# you can also calculate business duration between two dates
|
80
|
+
friday = Date.parse("December 24, 2010")
|
75
81
|
monday = Date.parse("December 27, 2010")
|
76
|
-
|
82
|
+
friday.business_days_until(monday) #=> 1
|
77
83
|
|
78
84
|
== Usage in Rails
|
79
85
|
The code above should work on a rails console without any issue. You will want to add a line something like:
|
@@ -112,7 +118,8 @@ This can lead to some wierd looking effects if, say, you are in the Eastern time
|
|
112
118
|
* David Bock http://github.com/bokmann
|
113
119
|
* Enrico Bianco http://github.com/enricob
|
114
120
|
* Arild Shirazi http://github.com/ashirazi
|
115
|
-
* Piotr Jakubowski
|
121
|
+
* Piotr Jakubowski http://github.com/piotrj
|
122
|
+
* Glenn Vanderburg http://github.com/glv
|
116
123
|
|
117
124
|
(Special thanks for Arild on the complexities of dealing with TimeWithZone)
|
118
125
|
|
@@ -128,11 +135,6 @@ This can lead to some wierd looking effects if, say, you are in the Eastern time
|
|
128
135
|
|
129
136
|
== TODO
|
130
137
|
|
131
|
-
* if it doesn't pollute the logic too much, I'd like to vary the days counted as 'business days'. Bakers often
|
132
|
-
don't work on Mondays, for instance. I'd do it in something like this:
|
133
|
-
|
134
|
-
BusinessTime::Config.work_week = [:tue, :wed, :thur, :fri, :sat]
|
135
|
-
|
136
138
|
* Arild has pointed out that there may be some logical inconsistencies
|
137
139
|
regaring the beginning_of_workday and end_of workday times not actually
|
138
140
|
being considered inside of the workday. I'd like to make sure that they
|
@@ -155,4 +157,4 @@ This can lead to some wierd looking effects if, say, you are in the Eastern time
|
|
155
157
|
|
156
158
|
== Copyright
|
157
159
|
|
158
|
-
Copyright (c) 2010 bokmann. See LICENSE for details.
|
160
|
+
Copyright (c) 2010,2011,2012 bokmann. See LICENSE for details.
|
data/lib/business_time.rb
CHANGED
data/lib/business_time/config.rb
CHANGED
@@ -17,6 +17,12 @@ module BusinessTime
|
|
17
17
|
# someplace in the initializers of your application.
|
18
18
|
attr_accessor :end_of_workday
|
19
19
|
|
20
|
+
# You can set this yourself, either by the load method below, or
|
21
|
+
# by saying
|
22
|
+
# BusinessTime::Config.work_week = [:sun, :mon, :tue, :wed, :thu]
|
23
|
+
# someplace in the initializers of your application.
|
24
|
+
attr_accessor :work_week
|
25
|
+
|
20
26
|
# You can set this yourself, either by the load method below, or
|
21
27
|
# by saying
|
22
28
|
# BusinessTime::Config.holidays << my_holiday_date_object
|
@@ -25,10 +31,28 @@ module BusinessTime
|
|
25
31
|
|
26
32
|
end
|
27
33
|
|
34
|
+
def self.work_week=(days)
|
35
|
+
@work_week = days
|
36
|
+
@weekdays = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.weekdays
|
40
|
+
return @weekdays unless @weekdays.nil?
|
41
|
+
|
42
|
+
lowercase_day_names = ::Time::RFC2822_DAY_NAME.map(&:downcase)
|
43
|
+
|
44
|
+
@weekdays = work_week.each_with_object([]) do |day_name, days|
|
45
|
+
day_num = lowercase_day_names.find_index(day_name.to_s.downcase)
|
46
|
+
days << day_num unless day_num.nil?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
28
50
|
def self.reset
|
29
51
|
self.holidays = []
|
30
52
|
self.beginning_of_workday = "9:00 am"
|
31
53
|
self.end_of_workday = "5:00 pm"
|
54
|
+
self.work_week = %w[mon tue wed thu fri]
|
55
|
+
@weekdays = nil
|
32
56
|
end
|
33
57
|
|
34
58
|
# loads the config data from a yaml file written as:
|
@@ -45,6 +69,7 @@ module BusinessTime
|
|
45
69
|
data = YAML::load(File.open(filename))
|
46
70
|
self.beginning_of_workday = data["business_time"]["beginning_of_workday"]
|
47
71
|
self.end_of_workday = data["business_time"]["end_of_workday"]
|
72
|
+
self.work_week = data["business_time"]["work_week"]
|
48
73
|
data["business_time"]["holidays"].each do |holiday|
|
49
74
|
self.holidays <<
|
50
75
|
Time.zone ? Time.zone.parse(holiday) : Time.parse(holiday)
|
data/lib/extensions/date.rb
CHANGED
data/lib/extensions/time.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- bokmann
|
@@ -14,55 +15,68 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
18
|
+
date: 2012-01-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: activesupport
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
27
29
|
segments:
|
30
|
+
- 2
|
28
31
|
- 0
|
29
|
-
|
30
|
-
|
32
|
+
- 0
|
33
|
+
version: 2.0.0
|
34
|
+
type: :runtime
|
31
35
|
version_requirements: *id001
|
32
36
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
37
|
+
name: rake
|
34
38
|
prerelease: false
|
35
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
36
41
|
requirements:
|
37
42
|
- - ">="
|
38
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
39
45
|
segments:
|
40
|
-
- 2
|
41
46
|
- 0
|
42
|
-
|
43
|
-
|
44
|
-
type: :runtime
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
45
49
|
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: shoulda
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
46
64
|
description: Have you ever wanted to do things like "6.business_days.from_now" and have weekends and holidays taken into account? Now you can.
|
47
65
|
email: dbock@codesherpas.com
|
48
66
|
executables: []
|
49
67
|
|
50
68
|
extensions: []
|
51
69
|
|
52
|
-
extra_rdoc_files:
|
53
|
-
|
54
|
-
- README.rdoc
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
55
72
|
files:
|
56
|
-
- .document
|
57
|
-
- .gitignore
|
58
73
|
- LICENSE
|
59
74
|
- README.rdoc
|
60
|
-
- Rakefile
|
61
|
-
- VERSION
|
62
75
|
- lib/business_time.rb
|
63
76
|
- lib/business_time/business_days.rb
|
64
77
|
- lib/business_time/business_hours.rb
|
65
78
|
- lib/business_time/config.rb
|
79
|
+
- lib/business_time/version.rb
|
66
80
|
- lib/extensions/date.rb
|
67
81
|
- lib/extensions/fixnum.rb
|
68
82
|
- lib/extensions/time.rb
|
@@ -70,60 +84,38 @@ files:
|
|
70
84
|
- rails_generators/business_time_config/business_time_config_generator.rb
|
71
85
|
- rails_generators/business_time_config/templates/business_time.rb
|
72
86
|
- rails_generators/business_time_config/templates/business_time.yml
|
73
|
-
- test/helper.rb
|
74
|
-
- test/test_business_days.rb
|
75
|
-
- test/test_business_days_eastern.rb
|
76
|
-
- test/test_business_days_utc.rb
|
77
|
-
- test/test_business_hours.rb
|
78
|
-
- test/test_business_hours_eastern.rb
|
79
|
-
- test/test_business_hours_utc.rb
|
80
|
-
- test/test_calculating_business_duration.rb
|
81
|
-
- test/test_config.rb
|
82
|
-
- test/test_date_extensions.rb
|
83
|
-
- test/test_fixnum_extensions.rb
|
84
|
-
- test/test_time_extensions.rb
|
85
|
-
- test/test_time_with_zone_extensions.rb
|
86
|
-
has_rdoc: true
|
87
87
|
homepage: http://github.com/bokmann/business_time
|
88
88
|
licenses: []
|
89
89
|
|
90
90
|
post_install_message:
|
91
|
-
rdoc_options:
|
92
|
-
|
91
|
+
rdoc_options: []
|
92
|
+
|
93
93
|
require_paths:
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
96
97
|
requirements:
|
97
98
|
- - ">="
|
98
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
99
101
|
segments:
|
100
102
|
- 0
|
101
103
|
version: "0"
|
102
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
103
106
|
requirements:
|
104
107
|
- - ">="
|
105
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
106
110
|
segments:
|
107
111
|
- 0
|
108
112
|
version: "0"
|
109
113
|
requirements: []
|
110
114
|
|
111
115
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
116
|
+
rubygems_version: 1.8.10
|
113
117
|
signing_key:
|
114
118
|
specification_version: 3
|
115
119
|
summary: Support for doing time math in business hours and days
|
116
|
-
test_files:
|
117
|
-
|
118
|
-
- test/test_business_days.rb
|
119
|
-
- test/test_business_days_eastern.rb
|
120
|
-
- test/test_business_days_utc.rb
|
121
|
-
- test/test_business_hours.rb
|
122
|
-
- test/test_business_hours_eastern.rb
|
123
|
-
- test/test_business_hours_utc.rb
|
124
|
-
- test/test_calculating_business_duration.rb
|
125
|
-
- test/test_config.rb
|
126
|
-
- test/test_date_extensions.rb
|
127
|
-
- test/test_fixnum_extensions.rb
|
128
|
-
- test/test_time_extensions.rb
|
129
|
-
- test/test_time_with_zone_extensions.rb
|
120
|
+
test_files: []
|
121
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "business_time"
|
8
|
-
gem.summary = %Q{Support for doing time math in business hours and days}
|
9
|
-
gem.description = %Q{Have you ever wanted to do things like "6.business_days.from_now" and have weekends and holidays taken into account? Now you can.}
|
10
|
-
gem.email = "dbock@codesherpas.com"
|
11
|
-
gem.homepage = "http://github.com/bokmann/business_time"
|
12
|
-
gem.authors = ["bokmann"]
|
13
|
-
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
-
gem.add_dependency('activesupport','>= 2.0.0')
|
15
|
-
gem.files += FileList['lib/generators/**/*.rb']
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'rake/testtask'
|
24
|
-
Rake::TestTask.new(:test) do |test|
|
25
|
-
test.libs << 'lib' << 'test'
|
26
|
-
test.pattern = 'test/**/test_*.rb'
|
27
|
-
test.verbose = true
|
28
|
-
end
|
29
|
-
|
30
|
-
begin
|
31
|
-
require 'rcov/rcovtask'
|
32
|
-
Rcov::RcovTask.new do |test|
|
33
|
-
test.libs << 'test'
|
34
|
-
test.pattern = 'test/**/test_*.rb'
|
35
|
-
test.verbose = true
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
task :rcov do
|
39
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
task :test => :check_dependencies
|
44
|
-
|
45
|
-
task :default => :test
|
46
|
-
|
47
|
-
require 'rake/rdoctask'
|
48
|
-
Rake::RDocTask.new do |rdoc|
|
49
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
-
|
51
|
-
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title = "business_time #{version}"
|
53
|
-
rdoc.rdoc_files.include('README*')
|
54
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.1
|
data/test/helper.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
if RUBY_VERSION >= '1.9'
|
4
|
-
require 'time'
|
5
|
-
require 'date'
|
6
|
-
require 'active_support/time'
|
7
|
-
else
|
8
|
-
require 'active_support'
|
9
|
-
require 'active_support/core_ext'
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'shoulda'
|
14
|
-
|
15
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
-
require 'business_time'
|
18
|
-
|
19
|
-
class Test::Unit::TestCase
|
20
|
-
end
|
data/test/test_business_days.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessDays < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a standard Time object" do
|
6
|
-
|
7
|
-
should "move to tomorrow if we add a business day" do
|
8
|
-
first = Time.parse("April 13th, 2010, 11:00 am")
|
9
|
-
later = 1.business_day.after(first)
|
10
|
-
expected = Time.parse("April 14th, 2010, 11:00 am")
|
11
|
-
assert_equal expected, later
|
12
|
-
end
|
13
|
-
|
14
|
-
should "move to yesterday is we subtract a business day" do
|
15
|
-
first = Time.parse("April 13th, 2010, 11:00 am")
|
16
|
-
before = 1.business_day.before(first)
|
17
|
-
expected = Time.parse("April 12th, 2010, 11:00 am")
|
18
|
-
assert_equal expected, before
|
19
|
-
end
|
20
|
-
|
21
|
-
should "take into account the weekend when adding a day" do
|
22
|
-
first = Time.parse("April 9th, 2010, 12:33 pm")
|
23
|
-
after = 1.business_day.after(first)
|
24
|
-
expected = Time.parse("April 12th, 2010, 12:33 pm")
|
25
|
-
assert_equal expected, after
|
26
|
-
end
|
27
|
-
|
28
|
-
should "take into account the weekend when subtracting a day" do
|
29
|
-
first = Time.parse("April 12th, 2010, 12:33 pm")
|
30
|
-
before = 1.business_day.before(first)
|
31
|
-
expected = Time.parse("April 9th, 2010, 12:33 pm")
|
32
|
-
assert_equal expected, before
|
33
|
-
end
|
34
|
-
|
35
|
-
should "move forward one week when adding 5 business days" do
|
36
|
-
first = Time.parse("April 9th, 2010, 12:33 pm")
|
37
|
-
after = 5.business_days.after(first)
|
38
|
-
expected = Time.parse("April 16th, 2010, 12:33 pm")
|
39
|
-
assert_equal expected, after
|
40
|
-
end
|
41
|
-
|
42
|
-
should "move backward one week when subtracting 5 business days" do
|
43
|
-
first = Time.parse("April 16th, 2010, 12:33 pm")
|
44
|
-
before = 5.business_days.before(first)
|
45
|
-
expected = Time.parse("April 9th, 2010, 12:33 pm")
|
46
|
-
assert_equal expected, before
|
47
|
-
end
|
48
|
-
|
49
|
-
should "take into account a holiday when adding a day" do
|
50
|
-
three_day_weekend = Date.parse("July 5th, 2010")
|
51
|
-
BusinessTime::Config.holidays << three_day_weekend
|
52
|
-
friday_afternoon = Time.parse("July 2nd, 2010, 4:50 pm")
|
53
|
-
tuesday_afternoon = 1.business_day.after(friday_afternoon)
|
54
|
-
expected = Time.parse("July 6th, 2010, 4:50 pm")
|
55
|
-
assert_equal expected, tuesday_afternoon
|
56
|
-
end
|
57
|
-
|
58
|
-
should "take into account a holiday on a weekend" do
|
59
|
-
BusinessTime::Config.reset
|
60
|
-
july_4 = Date.parse("July 4th, 2010")
|
61
|
-
BusinessTime::Config.holidays << july_4
|
62
|
-
friday_afternoon = Time.parse("July 2nd, 2010, 4:50 pm")
|
63
|
-
monday_afternoon = 1.business_day.after(friday_afternoon)
|
64
|
-
expected = Time.parse("July 5th, 2010, 4:50 pm")
|
65
|
-
assert_equal expected, monday_afternoon
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessDays < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a TimeWithZone object set to the Eastern timezone" do
|
6
|
-
setup do
|
7
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
8
|
-
end
|
9
|
-
teardown do
|
10
|
-
Time.zone = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
should "move to tomorrow if we add a business day" do
|
14
|
-
first = Time.zone.parse("April 13th, 2010, 11:00 am")
|
15
|
-
later = 1.business_day.after(first)
|
16
|
-
expected = Time.zone.parse("April 14th, 2010, 11:00 am")
|
17
|
-
assert_equal expected, later
|
18
|
-
end
|
19
|
-
|
20
|
-
should "move to yesterday is we subtract a business day" do
|
21
|
-
first = Time.zone.parse("April 13th, 2010, 11:00 am")
|
22
|
-
before = 1.business_day.before(first)
|
23
|
-
expected = Time.zone.parse("April 12th, 2010, 11:00 am")
|
24
|
-
assert_equal expected, before
|
25
|
-
end
|
26
|
-
|
27
|
-
should "take into account the weekend when adding a day" do
|
28
|
-
first = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
29
|
-
after = 1.business_day.after(first)
|
30
|
-
expected = Time.zone.parse("April 12th, 2010, 12:33 pm")
|
31
|
-
assert_equal expected, after
|
32
|
-
end
|
33
|
-
|
34
|
-
should "take into account the weekend when subtracting a day" do
|
35
|
-
first = Time.zone.parse("April 12th, 2010, 12:33 pm")
|
36
|
-
before = 1.business_day.before(first)
|
37
|
-
expected = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
38
|
-
assert_equal expected, before
|
39
|
-
end
|
40
|
-
|
41
|
-
should "move forward one week when adding 5 business days" do
|
42
|
-
first = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
43
|
-
after = 5.business_days.after(first)
|
44
|
-
expected = Time.zone.parse("April 16th, 2010, 12:33 pm")
|
45
|
-
assert_equal expected, after
|
46
|
-
end
|
47
|
-
|
48
|
-
should "move backward one week when subtracting 5 business days" do
|
49
|
-
first = Time.zone.parse("April 16th, 2010, 12:33 pm")
|
50
|
-
before = 5.business_days.before(first)
|
51
|
-
expected = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
52
|
-
assert_equal expected, before
|
53
|
-
end
|
54
|
-
|
55
|
-
should "take into account a holiday when adding a day" do
|
56
|
-
three_day_weekend = Date.parse("July 5th, 2010")
|
57
|
-
BusinessTime::Config.holidays << three_day_weekend
|
58
|
-
friday_afternoon = Time.zone.parse("July 2nd, 2010, 4:50 pm")
|
59
|
-
tuesday_afternoon = 1.business_day.after(friday_afternoon)
|
60
|
-
expected = Time.zone.parse("July 6th, 2010, 4:50 pm")
|
61
|
-
assert_equal expected, tuesday_afternoon
|
62
|
-
end
|
63
|
-
|
64
|
-
should "take into account a holiday on a weekend" do
|
65
|
-
BusinessTime::Config.reset
|
66
|
-
july_4 = Date.parse("July 4th, 2010")
|
67
|
-
BusinessTime::Config.holidays << july_4
|
68
|
-
friday_afternoon = Time.zone.parse("July 2nd, 2010, 4:50 pm")
|
69
|
-
monday_afternoon = 1.business_day.after(friday_afternoon)
|
70
|
-
expected = Time.zone.parse("July 5th, 2010, 4:50 pm")
|
71
|
-
assert_equal expected, monday_afternoon
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessDays < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a TimeWithZone object set to UTC" do
|
6
|
-
setup do
|
7
|
-
Time.zone = 'UTC'
|
8
|
-
end
|
9
|
-
teardown do
|
10
|
-
Time.zone = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
should "move to tomorrow if we add a business day" do
|
14
|
-
first = Time.zone.parse("April 13th, 2010, 11:00 am")
|
15
|
-
later = 1.business_day.after(first)
|
16
|
-
expected = Time.zone.parse("April 14th, 2010, 11:00 am")
|
17
|
-
assert_equal expected, later
|
18
|
-
end
|
19
|
-
|
20
|
-
should "move to yesterday is we subtract a business day" do
|
21
|
-
first = Time.zone.parse("April 13th, 2010, 11:00 am")
|
22
|
-
before = 1.business_day.before(first)
|
23
|
-
expected = Time.zone.parse("April 12th, 2010, 11:00 am")
|
24
|
-
assert_equal expected, before
|
25
|
-
end
|
26
|
-
|
27
|
-
should "take into account the weekend when adding a day" do
|
28
|
-
first = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
29
|
-
after = 1.business_day.after(first)
|
30
|
-
expected = Time.zone.parse("April 12th, 2010, 12:33 pm")
|
31
|
-
assert_equal expected, after
|
32
|
-
end
|
33
|
-
|
34
|
-
should "take into account the weekend when subtracting a day" do
|
35
|
-
first = Time.zone.parse("April 12th, 2010, 12:33 pm")
|
36
|
-
before = 1.business_day.before(first)
|
37
|
-
expected = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
38
|
-
assert_equal expected, before
|
39
|
-
end
|
40
|
-
|
41
|
-
should "move forward one week when adding 5 business days" do
|
42
|
-
first = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
43
|
-
after = 5.business_days.after(first)
|
44
|
-
expected = Time.zone.parse("April 16th, 2010, 12:33 pm")
|
45
|
-
assert_equal expected, after
|
46
|
-
end
|
47
|
-
|
48
|
-
should "move backward one week when subtracting 5 business days" do
|
49
|
-
first = Time.zone.parse("April 16th, 2010, 12:33 pm")
|
50
|
-
before = 5.business_days.before(first)
|
51
|
-
expected = Time.zone.parse("April 9th, 2010, 12:33 pm")
|
52
|
-
assert_equal expected, before
|
53
|
-
end
|
54
|
-
|
55
|
-
should "take into account a holiday when adding a day" do
|
56
|
-
three_day_weekend = Date.parse("July 5th, 2010")
|
57
|
-
BusinessTime::Config.holidays << three_day_weekend
|
58
|
-
friday_afternoon = Time.zone.parse("July 2nd, 2010, 4:50 pm")
|
59
|
-
tuesday_afternoon = 1.business_day.after(friday_afternoon)
|
60
|
-
expected = Time.zone.parse("July 6th, 2010, 4:50 pm")
|
61
|
-
assert_equal expected, tuesday_afternoon
|
62
|
-
end
|
63
|
-
|
64
|
-
should "take into account a holiday on a weekend" do
|
65
|
-
BusinessTime::Config.reset
|
66
|
-
july_4 = Date.parse("July 4th, 2010")
|
67
|
-
BusinessTime::Config.holidays << july_4
|
68
|
-
friday_afternoon = Time.zone.parse("July 2nd, 2010, 4:50 pm")
|
69
|
-
monday_afternoon = 1.business_day.after(friday_afternoon)
|
70
|
-
expected = Time.zone.parse("July 5th, 2010, 4:50 pm")
|
71
|
-
assert_equal expected, monday_afternoon
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/test/test_business_hours.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessHours < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a standard Time object" do
|
6
|
-
|
7
|
-
should "move to tomorrow if we add 8 business hours" do
|
8
|
-
first = Time.parse("Aug 4 2010, 9:35 am")
|
9
|
-
later = 8.business_hours.after(first)
|
10
|
-
expected = Time.parse("Aug 5 2010, 9:35 am")
|
11
|
-
assert_equal expected, later
|
12
|
-
end
|
13
|
-
|
14
|
-
should "move to yesterday if we subtract 8 business hours" do
|
15
|
-
first = Time.parse("Aug 4 2010, 9:35 am")
|
16
|
-
later = 8.business_hours.before(first)
|
17
|
-
expected = Time.parse("Aug 3 2010, 9:35 am")
|
18
|
-
assert_equal expected, later
|
19
|
-
end
|
20
|
-
|
21
|
-
should "take into account a weekend when adding an hour" do
|
22
|
-
friday_afternoon = Time.parse("April 9th, 4:50 pm")
|
23
|
-
monday_morning = 1.business_hour.after(friday_afternoon)
|
24
|
-
expected = Time.parse("April 12th 2010, 9:50 am")
|
25
|
-
assert_equal expected, monday_morning
|
26
|
-
end
|
27
|
-
|
28
|
-
should "take into account a weekend when subtracting an hour" do
|
29
|
-
monday_morning = Time.parse("April 12th 2010, 9:50 am")
|
30
|
-
friday_afternoon = 1.business_hour.before(monday_morning)
|
31
|
-
expected = Time.parse("April 9th 2010, 4:50 pm")
|
32
|
-
assert_equal expected, friday_afternoon
|
33
|
-
end
|
34
|
-
|
35
|
-
should "take into account a holiday" do
|
36
|
-
BusinessTime::Config.holidays << Date.parse("July 5th, 2010")
|
37
|
-
friday_afternoon = Time.parse("July 2nd 2010, 4:50pm")
|
38
|
-
tuesday_morning = 1.business_hour.after(friday_afternoon)
|
39
|
-
expected = Time.parse("July 6th 2010, 9:50 am")
|
40
|
-
assert_equal expected, tuesday_morning
|
41
|
-
end
|
42
|
-
|
43
|
-
should "add hours in the middle of the workday" do
|
44
|
-
monday_morning = Time.parse("April 12th 2010, 9:50 am")
|
45
|
-
later = 3.business_hours.after(monday_morning)
|
46
|
-
expected = Time.parse("April 12th 2010, 12:50 pm")
|
47
|
-
assert_equal expected, later
|
48
|
-
end
|
49
|
-
|
50
|
-
should "roll forward to 9 am if asked in the early morning" do
|
51
|
-
crack_of_dawn_monday = Time.parse("Mon Apr 26, 04:30:00, 2010")
|
52
|
-
monday_morning = Time.parse("Mon Apr 26, 09:00:00, 2010")
|
53
|
-
assert_equal monday_morning, Time.roll_forward(crack_of_dawn_monday)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "roll forward to the next morning if aftern business hours" do
|
57
|
-
monday_evening = Time.parse("Mon Apr 26, 18:00:00, 2010")
|
58
|
-
tuesday_morning = Time.parse("Tue Apr 27, 09:00:00, 2010")
|
59
|
-
assert_equal tuesday_morning, Time.roll_forward(monday_evening)
|
60
|
-
end
|
61
|
-
|
62
|
-
should "consider any time on a weekend as equivalent to monday morning" do
|
63
|
-
sunday = Time.parse("Sun Apr 25 12:06:56, 2010")
|
64
|
-
monday = Time.parse("Mon Apr 26, 09:00:00, 2010")
|
65
|
-
assert_equal 1.business_hour.before(monday), 1.business_hour.before(sunday)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessHours < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a TimeWithZone object in US Eastern" do
|
6
|
-
setup do
|
7
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
8
|
-
end
|
9
|
-
teardown do
|
10
|
-
Time.zone = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
should "move to tomorrow if we add 8 business hours" do
|
14
|
-
first = Time.zone.parse("Aug 4 2010, 9:35 am")
|
15
|
-
later = 8.business_hours.after(first)
|
16
|
-
expected = Time.zone.parse("Aug 5 2010, 9:35 am")
|
17
|
-
assert_equal expected, later
|
18
|
-
end
|
19
|
-
|
20
|
-
should "move to yesterday if we subtract 8 business hours" do
|
21
|
-
first = Time.zone.parse("Aug 4 2010, 9:35 am")
|
22
|
-
later = 8.business_hours.before(first)
|
23
|
-
expected = Time.zone.parse("Aug 3 2010, 9:35 am")
|
24
|
-
assert_equal expected, later
|
25
|
-
end
|
26
|
-
|
27
|
-
should "take into account a weekend when adding an hour" do
|
28
|
-
friday_afternoon = Time.zone.parse("April 9th, 4:50 pm")
|
29
|
-
monday_morning = 1.business_hour.after(friday_afternoon)
|
30
|
-
expected = Time.zone.parse("April 12th 2010, 9:50 am")
|
31
|
-
assert_equal expected, monday_morning
|
32
|
-
end
|
33
|
-
|
34
|
-
should "take into account a weekend when subtracting an hour" do
|
35
|
-
monday_morning = Time.zone.parse("April 12th 2010, 9:50 am")
|
36
|
-
friday_afternoon = 1.business_hour.before(monday_morning)
|
37
|
-
expected = Time.zone.parse("April 9th 2010, 4:50 pm")
|
38
|
-
assert_equal expected, friday_afternoon
|
39
|
-
end
|
40
|
-
|
41
|
-
should "take into account a holiday" do
|
42
|
-
BusinessTime::Config.holidays << Date.parse("July 5th, 2010")
|
43
|
-
friday_afternoon = Time.zone.parse("July 2nd 2010, 4:50pm")
|
44
|
-
tuesday_morning = 1.business_hour.after(friday_afternoon)
|
45
|
-
expected = Time.zone.parse("July 6th 2010, 9:50 am")
|
46
|
-
assert_equal expected, tuesday_morning
|
47
|
-
end
|
48
|
-
|
49
|
-
should "add hours in the middle of the workday" do
|
50
|
-
monday_morning = Time.zone.parse("April 12th 2010, 9:50 am")
|
51
|
-
later = 3.business_hours.after(monday_morning)
|
52
|
-
expected = Time.zone.parse("April 12th 2010, 12:50 pm")
|
53
|
-
assert_equal expected, later
|
54
|
-
end
|
55
|
-
|
56
|
-
should "roll forward to 9 am if asked in the early morning" do
|
57
|
-
crack_of_dawn_monday = Time.zone.parse("Mon Apr 26, 04:30:00, 2010")
|
58
|
-
monday_morning = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
|
59
|
-
assert_equal monday_morning, Time.roll_forward(crack_of_dawn_monday)
|
60
|
-
end
|
61
|
-
|
62
|
-
should "roll forward to the next morning if aftern business hours" do
|
63
|
-
monday_evening = Time.zone.parse("Mon Apr 26, 18:00:00, 2010")
|
64
|
-
tuesday_morning = Time.zone.parse("Tue Apr 27, 09:00:00, 2010")
|
65
|
-
assert_equal tuesday_morning, Time.roll_forward(monday_evening)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "consider any time on a weekend as equivalent to monday morning" do
|
69
|
-
sunday = Time.zone.parse("Sun Apr 25 12:06:56, 2010")
|
70
|
-
monday = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
|
71
|
-
assert_equal 1.business_hour.before(monday), 1.business_hour.before(sunday)
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestBusinessHours < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "with a TimeWithZone object in UTC" do
|
6
|
-
setup do
|
7
|
-
Time.zone = 'UTC'
|
8
|
-
end
|
9
|
-
teardown do
|
10
|
-
Time.zone = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
should "move to tomorrow if we add 8 business hours" do
|
14
|
-
first = Time.zone.parse("Aug 4 2010, 9:35 am")
|
15
|
-
later = 8.business_hours.after(first)
|
16
|
-
expected = Time.zone.parse("Aug 5 2010, 9:35 am")
|
17
|
-
assert_equal expected, later
|
18
|
-
end
|
19
|
-
|
20
|
-
should "move to yesterday if we subtract 8 business hours" do
|
21
|
-
first = Time.zone.parse("Aug 4 2010, 9:35 am")
|
22
|
-
later = 8.business_hours.before(first)
|
23
|
-
expected = Time.zone.parse("Aug 3 2010, 9:35 am")
|
24
|
-
assert_equal expected, later
|
25
|
-
end
|
26
|
-
|
27
|
-
should "take into account a weekend when adding an hour" do
|
28
|
-
friday_afternoon = Time.zone.parse("April 9th, 4:50 pm")
|
29
|
-
monday_morning = 1.business_hour.after(friday_afternoon)
|
30
|
-
expected = Time.zone.parse("April 12th 2010, 9:50 am")
|
31
|
-
assert_equal expected, monday_morning
|
32
|
-
end
|
33
|
-
|
34
|
-
should "take into account a weekend when subtracting an hour" do
|
35
|
-
monday_morning = Time.zone.parse("April 12th 2010, 9:50 am")
|
36
|
-
friday_afternoon = 1.business_hour.before(monday_morning)
|
37
|
-
expected = Time.zone.parse("April 9th 2010, 4:50 pm")
|
38
|
-
assert_equal expected, friday_afternoon, "Expected #{expected} but received #{friday_afternoon}"
|
39
|
-
end
|
40
|
-
|
41
|
-
should "take into account a holiday" do
|
42
|
-
BusinessTime::Config.holidays << Date.parse("July 5th, 2010")
|
43
|
-
friday_afternoon = Time.zone.parse("July 2nd 2010, 4:50pm")
|
44
|
-
tuesday_morning = 1.business_hour.after(friday_afternoon)
|
45
|
-
expected = Time.zone.parse("July 6th 2010, 9:50 am")
|
46
|
-
assert_equal expected, tuesday_morning
|
47
|
-
end
|
48
|
-
|
49
|
-
should "add hours in the middle of the workday" do
|
50
|
-
monday_morning = Time.zone.parse("April 12th 2010, 9:50 am")
|
51
|
-
later = 3.business_hours.after(monday_morning)
|
52
|
-
expected = Time.zone.parse("April 12th 2010, 12:50 pm")
|
53
|
-
assert_equal expected, later
|
54
|
-
end
|
55
|
-
|
56
|
-
should "roll forward to 9 am if asked in the early morning" do
|
57
|
-
crack_of_dawn_monday = Time.zone.parse("Mon Apr 26, 04:30:00, 2010")
|
58
|
-
monday_morning = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
|
59
|
-
assert_equal monday_morning, Time.roll_forward(crack_of_dawn_monday)
|
60
|
-
end
|
61
|
-
|
62
|
-
should "roll forward to the next morning if aftern business hours" do
|
63
|
-
monday_evening = Time.zone.parse("Mon Apr 26, 18:00:00, 2010")
|
64
|
-
tuesday_morning = Time.zone.parse("Tue Apr 27, 09:00:00, 2010")
|
65
|
-
assert_equal tuesday_morning, Time.roll_forward(monday_evening)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "consider any time on a weekend as equivalent to monday morning" do
|
69
|
-
sunday = Time.zone.parse("Sun Apr 25 12:06:56, 2010")
|
70
|
-
monday = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
|
71
|
-
assert_equal 1.business_hour.before(monday), 1.business_hour.before(sunday)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestCalculatingBusinessDuration < Test::Unit::TestCase
|
4
|
-
should "properly calculate business duration over weekends" do
|
5
|
-
friday = Date.parse("December 24, 2010")
|
6
|
-
monday = Date.parse("December 27, 2010")
|
7
|
-
assert_equal friday.business_days_until(monday), 1
|
8
|
-
end
|
9
|
-
|
10
|
-
should "properly calculate business duration without weekends" do
|
11
|
-
monday = Date.parse("December 20, 2010")
|
12
|
-
wednesday = Date.parse("December 22, 2010")
|
13
|
-
assert_equal monday.business_days_until(wednesday), 2
|
14
|
-
end
|
15
|
-
|
16
|
-
should "properly calculate business duration with respect to holidays" do
|
17
|
-
free_friday = Date.parse("December 17, 2010")
|
18
|
-
wednesday = Date.parse("December 15,2010")
|
19
|
-
monday = Date.parse("December 20, 2010")
|
20
|
-
BusinessTime::Config.holidays << free_friday
|
21
|
-
assert_equal wednesday.business_days_until(monday), 2
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/test/test_config.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestConfig < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "keep track of the start of the day" do
|
6
|
-
assert_equal BusinessTime::Config.beginning_of_workday, "9:00 am"
|
7
|
-
BusinessTime::Config.beginning_of_workday = "8:30 am"
|
8
|
-
assert_equal BusinessTime::Config.beginning_of_workday, "8:30 am"
|
9
|
-
end
|
10
|
-
|
11
|
-
should "keep track of the end of the day" do
|
12
|
-
assert_equal BusinessTime::Config.end_of_workday, "5:00 pm"
|
13
|
-
BusinessTime::Config.end_of_workday = "5:30 pm"
|
14
|
-
assert_equal BusinessTime::Config.end_of_workday, "5:30 pm"
|
15
|
-
end
|
16
|
-
|
17
|
-
should "keep track of holidays" do
|
18
|
-
BusinessTime::Config.reset
|
19
|
-
assert BusinessTime::Config.holidays.empty?
|
20
|
-
daves_birthday = Date.parse("August 4th, 1969")
|
21
|
-
BusinessTime::Config.holidays << daves_birthday
|
22
|
-
assert BusinessTime::Config.holidays.include?(daves_birthday)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestDateExtensions < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "know what a weekend day is" do
|
6
|
-
assert(Date.parse("April 9, 2010").weekday?)
|
7
|
-
assert(!Date.parse("April 10, 2010").weekday?)
|
8
|
-
assert(!Date.parse("April 11, 2010").weekday?)
|
9
|
-
assert(Date.parse("April 12, 2010").weekday?)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "know a weekend day is not a workday" do
|
13
|
-
assert(Date.parse("April 9, 2010").workday?)
|
14
|
-
assert(!Date.parse("April 10, 2010").workday?)
|
15
|
-
assert(!Date.parse("April 11, 2010").workday?)
|
16
|
-
assert(Date.parse("April 12, 2010").workday?)
|
17
|
-
end
|
18
|
-
|
19
|
-
should "know a holiday is not a workday" do
|
20
|
-
july_4 = Date.parse("July 4, 2010")
|
21
|
-
july_5 = Date.parse("July 5, 2010")
|
22
|
-
|
23
|
-
assert(!july_4.workday?)
|
24
|
-
assert(july_5.workday?)
|
25
|
-
|
26
|
-
BusinessTime::Config.holidays << july_4
|
27
|
-
BusinessTime::Config.holidays << july_5
|
28
|
-
|
29
|
-
assert(!july_4.workday?)
|
30
|
-
assert(!july_5.workday?)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestFixnumExtensions < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "respond to business_hours by returning an instance of BusinessHours" do
|
6
|
-
assert(1.respond_to?(:business_hour))
|
7
|
-
assert(1.respond_to?(:business_hours))
|
8
|
-
assert 1.business_hour.instance_of?(BusinessTime::BusinessHours)
|
9
|
-
end
|
10
|
-
|
11
|
-
should "respond to business_days by returning an instance of BusinessDays" do
|
12
|
-
assert(1.respond_to?(:business_day))
|
13
|
-
assert(1.respond_to?(:business_days))
|
14
|
-
assert 1.business_day.instance_of?(BusinessTime::BusinessDays)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestTimeExtensions < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "know what a weekend day is" do
|
6
|
-
assert( Time.weekday?(Time.parse("April 9, 2010 10:30am")))
|
7
|
-
assert(!Time.weekday?(Time.parse("April 10, 2010 10:30am")))
|
8
|
-
assert(!Time.weekday?(Time.parse("April 11, 2010 10:30am")))
|
9
|
-
assert( Time.weekday?(Time.parse("April 12, 2010 10:30am")))
|
10
|
-
end
|
11
|
-
|
12
|
-
should "know a weekend day is not a workday" do
|
13
|
-
assert( Time.workday?(Time.parse("April 9, 2010 10:45 am")))
|
14
|
-
assert(!Time.workday?(Time.parse("April 10, 2010 10:45 am")))
|
15
|
-
assert(!Time.workday?(Time.parse("April 11, 2010 10:45 am")))
|
16
|
-
assert( Time.workday?(Time.parse("April 12, 2010 10:45 am")))
|
17
|
-
end
|
18
|
-
|
19
|
-
should "know a holiday is not a workday" do
|
20
|
-
BusinessTime::Config.reset
|
21
|
-
|
22
|
-
BusinessTime::Config.holidays << Date.parse("July 4, 2010")
|
23
|
-
BusinessTime::Config.holidays << Date.parse("July 5, 2010")
|
24
|
-
|
25
|
-
assert(!Time.workday?(Time.parse("July 4th, 2010 1:15 pm")))
|
26
|
-
assert(!Time.workday?(Time.parse("July 5th, 2010 2:37 pm")))
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
should "know the beginning of the day for an instance" do
|
31
|
-
first = Time.parse("August 17th, 2010, 11:50 am")
|
32
|
-
expecting = Time.parse("August 17th, 2010, 9:00 am")
|
33
|
-
assert_equal expecting, Time.beginning_of_workday(first)
|
34
|
-
end
|
35
|
-
|
36
|
-
should "know the end of the day for an instance" do
|
37
|
-
first = Time.parse("August 17th, 2010, 11:50 am")
|
38
|
-
expecting = Time.parse("August 17th, 2010, 5:00 pm")
|
39
|
-
assert_equal expecting, Time.end_of_workday(first)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestTimeWithZoneExtensions < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "With Eastern Standard Time" do
|
6
|
-
setup do
|
7
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
8
|
-
end
|
9
|
-
|
10
|
-
should "know what a weekend day is" do
|
11
|
-
assert( Time.weekday?(Time.zone.parse("April 9, 2010 10:30am")))
|
12
|
-
assert(!Time.weekday?(Time.zone.parse("April 10, 2010 10:30am")))
|
13
|
-
assert(!Time.weekday?(Time.zone.parse("April 11, 2010 10:30am")))
|
14
|
-
assert( Time.weekday?(Time.zone.parse("April 12, 2010 10:30am")))
|
15
|
-
end
|
16
|
-
|
17
|
-
should "know a weekend day is not a workday" do
|
18
|
-
assert( Time.workday?(Time.zone.parse("April 9, 2010 10:45 am")))
|
19
|
-
assert(!Time.workday?(Time.zone.parse("April 10, 2010 10:45 am")))
|
20
|
-
assert(!Time.workday?(Time.zone.parse("April 11, 2010 10:45 am")))
|
21
|
-
assert( Time.workday?(Time.zone.parse("April 12, 2010 10:45 am")))
|
22
|
-
end
|
23
|
-
|
24
|
-
should "know a holiday is not a workday" do
|
25
|
-
BusinessTime::Config.reset
|
26
|
-
|
27
|
-
BusinessTime::Config.holidays << Date.parse("July 4, 2010")
|
28
|
-
BusinessTime::Config.holidays << Date.parse("July 5, 2010")
|
29
|
-
|
30
|
-
assert(!Time.workday?(Time.zone.parse("July 4th, 2010 1:15 pm")))
|
31
|
-
assert(!Time.workday?(Time.zone.parse("July 5th, 2010 2:37 pm")))
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
should "know the beginning of the day for an instance" do
|
36
|
-
first = Time.zone.parse("August 17th, 2010, 11:50 am")
|
37
|
-
expecting = Time.zone.parse("August 17th, 2010, 9:00 am")
|
38
|
-
assert_equal expecting, Time.beginning_of_workday(first)
|
39
|
-
end
|
40
|
-
|
41
|
-
should "know the end of the day for an instance" do
|
42
|
-
first = Time.zone.parse("August 17th, 2010, 11:50 am")
|
43
|
-
expecting = Time.zone.parse("August 17th, 2010, 5:00 pm")
|
44
|
-
assert_equal expecting, Time.end_of_workday(first)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
context "With UTC Timezone" do
|
50
|
-
setup do
|
51
|
-
Time.zone = 'UTC'
|
52
|
-
end
|
53
|
-
|
54
|
-
should "know what a weekend day is" do
|
55
|
-
assert( Time.weekday?(Time.zone.parse("April 9, 2010 10:30am")))
|
56
|
-
assert(!Time.weekday?(Time.zone.parse("April 10, 2010 10:30am")))
|
57
|
-
assert(!Time.weekday?(Time.zone.parse("April 11, 2010 10:30am")))
|
58
|
-
assert( Time.weekday?(Time.zone.parse("April 12, 2010 10:30am")))
|
59
|
-
end
|
60
|
-
|
61
|
-
should "know a weekend day is not a workday" do
|
62
|
-
assert( Time.workday?(Time.zone.parse("April 9, 2010 10:45 am")))
|
63
|
-
assert(!Time.workday?(Time.zone.parse("April 10, 2010 10:45 am")))
|
64
|
-
assert(!Time.workday?(Time.zone.parse("April 11, 2010 10:45 am")))
|
65
|
-
assert( Time.workday?(Time.zone.parse("April 12, 2010 10:45 am")))
|
66
|
-
end
|
67
|
-
|
68
|
-
should "know a holiday is not a workday" do
|
69
|
-
BusinessTime::Config.reset
|
70
|
-
|
71
|
-
BusinessTime::Config.holidays << Date.parse("July 4, 2010")
|
72
|
-
BusinessTime::Config.holidays << Date.parse("July 5, 2010")
|
73
|
-
|
74
|
-
assert(!Time.workday?(Time.zone.parse("July 4th, 2010 1:15 pm")))
|
75
|
-
assert(!Time.workday?(Time.zone.parse("July 5th, 2010 2:37 pm")))
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
should "know the beginning of the day for an instance" do
|
80
|
-
first = Time.zone.parse("August 17th, 2010, 11:50 am")
|
81
|
-
expecting = Time.zone.parse("August 17th, 2010, 9:00 am")
|
82
|
-
assert_equal expecting, Time.beginning_of_workday(first)
|
83
|
-
end
|
84
|
-
|
85
|
-
should "know the end of the day for an instance" do
|
86
|
-
first = Time.zone.parse("August 17th, 2010, 11:50 am")
|
87
|
-
expecting = Time.zone.parse("August 17th, 2010, 5:00 pm")
|
88
|
-
assert_equal expecting, Time.end_of_workday(first)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|