business_seconds 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +12 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/business_seconds.rb +1 -0
- data/lib/business_seconds/extensions/time.rb +53 -0
- data/test/helper.rb +21 -0
- data/test/test_time_extensions.rb +97 -0
- data/test/test_time_with_zone_extensions.rb +211 -0
- metadata +113 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 slawosz@gmail.com
|
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.rdoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
= business_seconds
|
2
|
+
|
3
|
+
This is an extension for bokmann/business_time gem. It adds method to count
|
4
|
+
business time (in seconds):
|
5
|
+
|
6
|
+
begin = Time.parse("June 11th, 2010, 4:50 pm")
|
7
|
+
end = Time.parse("June 14th, 2010, 9:50 am")
|
8
|
+
begin.business_seconds_to(end)
|
9
|
+
|
10
|
+
This gem is dependent from bokmann/business_time gem:
|
11
|
+
|
12
|
+
http://github.com/bokmann/business_time
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "business_seconds"
|
8
|
+
gem.summary = %Q{Extension for bokmann/business_time to calculating duration in business seconds between two times}
|
9
|
+
gem.email = "slawosz@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/slawosz/business_seconds"
|
11
|
+
gem.authors = ["slawosz"]
|
12
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
13
|
+
gem.add_dependency('activesupport','>= 2.0.0')
|
14
|
+
gem.add_dependency('business_time','>= 0.3.0')
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "business_seconds #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
require "business_seconds/extensions/time"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Time
|
2
|
+
class << self
|
3
|
+
|
4
|
+
# Checks if time is during business hours
|
5
|
+
def during_business_hours?(time)
|
6
|
+
workday?(time) && !before_business_hours?(time) && !after_business_hours?(time)
|
7
|
+
end
|
8
|
+
|
9
|
+
def business_seconds_from_the_beginning_of_day(time)
|
10
|
+
time = Time.zone ? Time.zone.parse(time.to_s) : time
|
11
|
+
if during_business_hours?(time)
|
12
|
+
time - beginning_of_workday(time)
|
13
|
+
elsif after_business_hours?(time)
|
14
|
+
end_of_workday(time) - beginning_of_workday(time)
|
15
|
+
else
|
16
|
+
0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def business_seconds_left_to_the_end_of_day(time)
|
21
|
+
time = Time.zone ? Time.zone.parse(time.to_s) : time
|
22
|
+
if during_business_hours?(time)
|
23
|
+
end_of_workday(time) - time
|
24
|
+
elsif before_business_hours?(time)
|
25
|
+
end_of_workday(time) - beginning_of_workday(time)
|
26
|
+
else
|
27
|
+
0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def business_seconds_duration_from_to(start_time, end_time)
|
32
|
+
start_time = Time.zone ? Time.zone.parse(start_time.to_s) : start_time
|
33
|
+
end_time = Time.zone ? Time.zone.parse(end_time.to_s) : end_time
|
34
|
+
if start_time > end_time
|
35
|
+
return 0
|
36
|
+
end
|
37
|
+
if end_time.to_date == start_time.to_date
|
38
|
+
return business_seconds_from_the_beginning_of_day(end_time) - business_seconds_from_the_beginning_of_day(start_time)
|
39
|
+
end
|
40
|
+
time_left = 0
|
41
|
+
start_day = start_time
|
42
|
+
while start_day.to_date < end_time.to_date
|
43
|
+
parsed_start_day = Time.parse(start_day.to_s)
|
44
|
+
time_left += business_seconds_left_to_the_end_of_day(start_day)
|
45
|
+
start_day = beginning_of_workday(parsed_start_day) + 1.day
|
46
|
+
end
|
47
|
+
time_left += business_seconds_from_the_beginning_of_day(end_time)
|
48
|
+
time_left
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
require 'business_time'
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
|
+
require 'business_seconds'
|
19
|
+
|
20
|
+
#class Test::Unit::TestCase
|
21
|
+
#end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTimeExtensions < Test::Unit::TestCase
|
4
|
+
|
5
|
+
|
6
|
+
should "know if instance is during business hours" do
|
7
|
+
assert(!Time.during_business_hours?(Time.parse("April 11, 2010 10:45 am")))
|
8
|
+
assert(!Time.during_business_hours?(Time.parse("April 12, 2010 8:45 am")))
|
9
|
+
assert(Time.during_business_hours?(Time.parse("April 12, 2010 9:45 am")))
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Business duration" do
|
13
|
+
|
14
|
+
should "know a seconds to an instance" do
|
15
|
+
start_time = Time.parse("August 17th, 2010, 8:50 am")
|
16
|
+
end_time = Time.parse("August 17th, 2010, 13:00 pm")
|
17
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
18
|
+
assert_equal expecting, 3600 * 4
|
19
|
+
|
20
|
+
start_time = Time.parse("August 17th, 2010, 11:50 am")
|
21
|
+
end_time = Time.parse("August 17th, 2010, 13:50 pm")
|
22
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
23
|
+
assert_equal expecting, 7200
|
24
|
+
|
25
|
+
start_time = Time.parse("August 17th, 2010, 17:50 pm")
|
26
|
+
end_time = Time.parse("August 17th, 2010, 18:50 pm")
|
27
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
28
|
+
assert_equal expecting, 0
|
29
|
+
|
30
|
+
start_time = Time.parse("August 22th, 2010, 11:50 am")
|
31
|
+
end_time = Time.parse("August 22th, 2010, 13:50 pm")
|
32
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
33
|
+
assert_equal expecting, 0
|
34
|
+
end
|
35
|
+
|
36
|
+
should "know a seconds to an instance between holidays" do
|
37
|
+
# weekend day
|
38
|
+
start_time = Time.parse("August 22th, 2010, 11:50 am")
|
39
|
+
BusinessTime::Config.reset
|
40
|
+
|
41
|
+
BusinessTime::Config.holidays << Date.parse("August 24, 2010")
|
42
|
+
end_time = Time.parse("August 24th, 2010, 13:50 pm")
|
43
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
44
|
+
assert_equal expecting, 8 * 3600
|
45
|
+
end
|
46
|
+
|
47
|
+
should "know a seconds to an other day instance" do
|
48
|
+
start_time = Time.parse("August 17th, 2010, 16:00 pm")
|
49
|
+
end_time = Time.parse("August 18th, 2010, 9:00 am")
|
50
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
51
|
+
assert_equal expecting, 3600
|
52
|
+
|
53
|
+
start_time = Time.parse("August 21th, 2010, 13:00 pm")
|
54
|
+
end_time = Time.parse("August 22th, 2010, 17:00 pm")
|
55
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
56
|
+
assert_equal expecting, 0
|
57
|
+
end
|
58
|
+
|
59
|
+
should "know a seconds to an other week instance" do
|
60
|
+
start_time = Time.parse("August 17th, 2010, 16:00 pm")
|
61
|
+
end_time = Time.parse("August 23th, 2010, 10:00 am")
|
62
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
63
|
+
assert_equal expecting, (3600 * 26)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
should "know a seconds to end of business hours" do
|
68
|
+
time = Time.parse("August 17th, 2010, 16:00 pm")
|
69
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
70
|
+
assert_equal expecting, 3600
|
71
|
+
time = Time.parse("August 17th, 2010, 8:00 am")
|
72
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
73
|
+
assert_equal expecting, 3600 * 8
|
74
|
+
time = Time.parse("August 17th, 2010, 18:00 pm")
|
75
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
76
|
+
assert_equal expecting, 0
|
77
|
+
time = Time.parse("August 21th, 2010, 16:00 pm")
|
78
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
79
|
+
assert_equal expecting, 0
|
80
|
+
end
|
81
|
+
|
82
|
+
should "know a seconds from beginning of business hours" do
|
83
|
+
time = Time.parse("August 17th, 2010, 16:00 pm")
|
84
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
85
|
+
assert_equal expecting, 3600 * 7
|
86
|
+
time = Time.parse("August 17th, 2010, 8:00 am")
|
87
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
88
|
+
assert_equal expecting, 0
|
89
|
+
time = Time.parse("August 17th, 2010, 18:00 pm")
|
90
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
91
|
+
assert_equal expecting, 3600 * 8
|
92
|
+
time = Time.parse("August 21th, 2010, 16:00 pm")
|
93
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
94
|
+
assert_equal expecting, 0
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,211 @@
|
|
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
|
+
context "Business duration" do
|
11
|
+
|
12
|
+
should "know a seconds to an instance" do
|
13
|
+
start_time = Time.zone.parse("August 17th, 2010, 8:50 am")
|
14
|
+
end_time = Time.zone.parse("August 17th, 2010, 13:00 pm")
|
15
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
16
|
+
assert_equal expecting, 3600 * 4
|
17
|
+
|
18
|
+
start_time = Time.zone.parse("August 17th, 2010, 11:50 am")
|
19
|
+
end_time = Time.zone.parse("August 17th, 2010, 13:50 pm")
|
20
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
21
|
+
assert_equal expecting, 7200
|
22
|
+
|
23
|
+
start_time = Time.zone.parse("August 17th, 2010, 17:50 pm")
|
24
|
+
end_time = Time.zone.parse("August 17th, 2010, 18:50 pm")
|
25
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
26
|
+
assert_equal expecting, 0
|
27
|
+
|
28
|
+
start_time = Time.zone.parse("August 22th, 2010, 11:50 am")
|
29
|
+
end_time = Time.zone.parse("August 22th, 2010, 13:50 pm")
|
30
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
31
|
+
assert_equal expecting, 0
|
32
|
+
end
|
33
|
+
|
34
|
+
should "know a seconds to an instance between holidays" do
|
35
|
+
# weekend day
|
36
|
+
start_time = Time.zone.parse("August 22th, 2010, 11:50 am")
|
37
|
+
BusinessTime::Config.reset
|
38
|
+
|
39
|
+
BusinessTime::Config.holidays << Date.parse("August 24, 2010")
|
40
|
+
end_time = Time.zone.parse("August 24th, 2010, 13:50 pm")
|
41
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
42
|
+
assert_equal expecting, 8 * 3600
|
43
|
+
end
|
44
|
+
|
45
|
+
should "know a seconds to an other day instance" do
|
46
|
+
start_time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
47
|
+
end_time = Time.zone.parse("August 18th, 2010, 9:00 am")
|
48
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
49
|
+
assert_equal expecting, 3600
|
50
|
+
|
51
|
+
start_time = Time.zone.parse("August 21th, 2010, 13:00 pm")
|
52
|
+
end_time = Time.zone.parse("August 22th, 2010, 17:00 pm")
|
53
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
54
|
+
assert_equal expecting, 0
|
55
|
+
end
|
56
|
+
|
57
|
+
should "know a seconds to an other week instance" do
|
58
|
+
start_time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
59
|
+
end_time = Time.zone.parse("August 23th, 2010, 10:00 am")
|
60
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
61
|
+
assert_equal expecting, (3600 * 26)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "know a seconds to end of business hours" do
|
65
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
66
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
67
|
+
assert_equal expecting, 3600
|
68
|
+
time = Time.zone.parse("August 17th, 2010, 8:00 am")
|
69
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
70
|
+
assert_equal expecting, 3600 * 8
|
71
|
+
time = Time.zone.parse("August 17th, 2010, 18:00 pm")
|
72
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
73
|
+
assert_equal expecting, 0
|
74
|
+
time = Time.zone.parse("August 21th, 2010, 16:00 pm")
|
75
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
76
|
+
assert_equal expecting, 0
|
77
|
+
end
|
78
|
+
|
79
|
+
should "know a seconds from beginning of business hours" do
|
80
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
81
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
82
|
+
assert_equal expecting, 3600 * 7
|
83
|
+
time = Time.zone.parse("August 17th, 2010, 8:00 am")
|
84
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
85
|
+
assert_equal expecting, 0
|
86
|
+
time = Time.zone.parse("August 17th, 2010, 18:00 pm")
|
87
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
88
|
+
assert_equal expecting, 3600 * 8
|
89
|
+
time = Time.zone.parse("August 21th, 2010, 16:00 pm")
|
90
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
91
|
+
assert_equal expecting, 0
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
should "know if instance is during business hours" do
|
97
|
+
BusinessTime::Config.holidays = []
|
98
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 11, 2010 10:45 am")))
|
99
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 12, 2010 8:45 am")))
|
100
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 12, 2010 18:15 pm")))
|
101
|
+
assert(Time.during_business_hours?(Time.zone.parse("April 12, 2010 9:45 am")))
|
102
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
103
|
+
assert(Time.during_business_hours?(time))
|
104
|
+
assert(Time.during_business_hours?(Time.zone.parse("April 12, 2010 16:00 pm")))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "With UTC Timezone" do
|
109
|
+
setup do
|
110
|
+
Time.zone = 'UTC'
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
context "Business duration" do
|
115
|
+
|
116
|
+
should "know a seconds to an instance" do
|
117
|
+
start_time = Time.zone.parse("August 17th, 2010, 8:50 am")
|
118
|
+
end_time = Time.zone.parse("August 17th, 2010, 13:00 pm")
|
119
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
120
|
+
assert_equal expecting, 3600 * 4
|
121
|
+
|
122
|
+
start_time = Time.zone.parse("August 17th, 2010, 11:50 am")
|
123
|
+
end_time = Time.zone.parse("August 17th, 2010, 13:50 pm")
|
124
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
125
|
+
assert_equal expecting, 7200
|
126
|
+
|
127
|
+
start_time = Time.zone.parse("August 17th, 2010, 17:50 pm")
|
128
|
+
end_time = Time.zone.parse("August 17th, 2010, 18:50 pm")
|
129
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
130
|
+
assert_equal expecting, 0
|
131
|
+
|
132
|
+
start_time = Time.zone.parse("August 22th, 2010, 11:50 am")
|
133
|
+
end_time = Time.zone.parse("August 22th, 2010, 13:50 pm")
|
134
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
135
|
+
assert_equal expecting, 0
|
136
|
+
end
|
137
|
+
|
138
|
+
should "know a seconds to an instance between holidays" do
|
139
|
+
# weekend day
|
140
|
+
start_time = Time.zone.parse("August 22th, 2010, 11:50 am")
|
141
|
+
BusinessTime::Config.reset
|
142
|
+
|
143
|
+
BusinessTime::Config.holidays << Date.parse("August 24, 2010")
|
144
|
+
end_time = Time.zone.parse("August 24th, 2010, 13:50 pm")
|
145
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
146
|
+
assert_equal expecting, 8 * 3600
|
147
|
+
end
|
148
|
+
|
149
|
+
should "know a seconds to an other day instance" do
|
150
|
+
start_time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
151
|
+
end_time = Time.zone.parse("August 18th, 2010, 9:00 am")
|
152
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
153
|
+
assert_equal expecting, 3600
|
154
|
+
|
155
|
+
start_time = Time.zone.parse("August 21th, 2010, 13:00 pm")
|
156
|
+
end_time = Time.zone.parse("August 22th, 2010, 17:00 pm")
|
157
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
158
|
+
assert_equal expecting, 0
|
159
|
+
end
|
160
|
+
|
161
|
+
should "know a seconds to an other week instance" do
|
162
|
+
start_time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
163
|
+
end_time = Time.zone.parse("August 23th, 2010, 10:00 am")
|
164
|
+
expecting = Time.business_seconds_duration_from_to(start_time, end_time)
|
165
|
+
assert_equal expecting, (3600 * 26)
|
166
|
+
end
|
167
|
+
|
168
|
+
should "know a seconds to end of business hours" do
|
169
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
170
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
171
|
+
assert_equal expecting, 3600
|
172
|
+
time = Time.zone.parse("August 17th, 2010, 8:00 am")
|
173
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
174
|
+
assert_equal expecting, 3600 * 8
|
175
|
+
time = Time.zone.parse("August 17th, 2010, 18:00 pm")
|
176
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
177
|
+
assert_equal expecting, 0
|
178
|
+
time = Time.zone.parse("August 21th, 2010, 16:00 pm")
|
179
|
+
expecting = Time.business_seconds_left_to_the_end_of_day(time)
|
180
|
+
assert_equal expecting, 0
|
181
|
+
end
|
182
|
+
|
183
|
+
should "know a seconds from beginning of business hours" do
|
184
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
185
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
186
|
+
assert_equal expecting, 3600 * 7
|
187
|
+
time = Time.zone.parse("August 17th, 2010, 8:00 am")
|
188
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
189
|
+
assert_equal expecting, 0
|
190
|
+
time = Time.zone.parse("August 17th, 2010, 18:00 pm")
|
191
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
192
|
+
assert_equal expecting, 3600 * 8
|
193
|
+
time = Time.zone.parse("August 21th, 2010, 16:00 pm")
|
194
|
+
expecting = Time.business_seconds_from_the_beginning_of_day(time)
|
195
|
+
assert_equal expecting, 0
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
should "know if instance is during business hours" do
|
201
|
+
BusinessTime::Config.holidays = []
|
202
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 11, 2010 10:45 am")))
|
203
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 12, 2010 8:45 am")))
|
204
|
+
assert(!Time.during_business_hours?(Time.zone.parse("April 12, 2010 18:15 pm")))
|
205
|
+
assert(Time.during_business_hours?(Time.zone.parse("April 12, 2010 9:45 am")))
|
206
|
+
time = Time.zone.parse("August 17th, 2010, 16:00 pm")
|
207
|
+
assert(Time.during_business_hours?(time))
|
208
|
+
assert(Time.during_business_hours?(Time.zone.parse("April 12, 2010 16:00 pm")))
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: business_seconds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- slawosz
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-14 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: activesupport
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 2
|
41
|
+
- 0
|
42
|
+
- 0
|
43
|
+
version: 2.0.0
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: business_time
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
- 3
|
56
|
+
- 0
|
57
|
+
version: 0.3.0
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
60
|
+
description:
|
61
|
+
email: slawosz@gmail.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- LICENSE
|
72
|
+
- README.rdoc
|
73
|
+
- Rakefile
|
74
|
+
- VERSION
|
75
|
+
- lib/business_seconds.rb
|
76
|
+
- lib/business_seconds/extensions/time.rb
|
77
|
+
- test/helper.rb
|
78
|
+
- test/test_time_extensions.rb
|
79
|
+
- test/test_time_with_zone_extensions.rb
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/slawosz/business_seconds
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options:
|
86
|
+
- --charset=UTF-8
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.3.6
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Extension for bokmann/business_time to calculating duration in business seconds between two times
|
110
|
+
test_files:
|
111
|
+
- test/test_time_with_zone_extensions.rb
|
112
|
+
- test/test_time_extensions.rb
|
113
|
+
- test/helper.rb
|