time_clock 0.0.5 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/time_clock.rb +3 -0
- data/lib/time_clock/business_days_until.rb +9 -0
- data/lib/time_clock/comparison.rb +24 -2
- data/lib/time_clock/core_ext/date.rb +3 -0
- data/lib/time_clock/core_ext/time_with_zone.rb +3 -1
- data/lib/time_clock/version.rb +1 -1
- data/spec/lib/time_clock/comparison_spec.rb +12 -1
- data/spec/lib/time_clock/core_ext/date_spec.rb +13 -0
- metadata +25 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6569afaf77b28081b3340d4d14d7a43c3975bfc0
|
4
|
+
data.tar.gz: 9f46fe9b779839217f334600e9c742f55701bc09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99dad2a7361d566892d3383a59b1f0c2e01052f5271d35100244f938458cd6a89a2e4c37a34053519d8e7f2da8082911214f911e5326af52cca41ee1d5f29071
|
7
|
+
data.tar.gz: 83b75b251622a3a3a4da4483c6c8d4e9ca32ca74edc762149be2fd82034b06613395f435e94440e220be6f4e976f86b50c3c7e1edbde708780d475753626c53f
|
data/lib/time_clock.rb
CHANGED
@@ -5,8 +5,11 @@ require "time_clock/calendar"
|
|
5
5
|
require "time_clock/comparison"
|
6
6
|
|
7
7
|
require "time_clock/business_time_until"
|
8
|
+
require "time_clock/business_days_until"
|
8
9
|
|
9
10
|
require "time_clock/core_ext/time"
|
11
|
+
require "time_clock/core_ext/time_with_zone"
|
12
|
+
require "time_clock/core_ext/date"
|
10
13
|
|
11
14
|
module TimeClock
|
12
15
|
|
@@ -7,7 +7,9 @@ module TimeClock
|
|
7
7
|
|
8
8
|
def initialize(start_time, end_time, calendar=TimeClock.default_calendar)
|
9
9
|
raise NilCalendarError unless calendar
|
10
|
-
@start_time
|
10
|
+
@start_time = start_time.to_time
|
11
|
+
@end_time = end_time_from_value(end_time)
|
12
|
+
@calendar = calendar
|
11
13
|
end
|
12
14
|
|
13
15
|
def period
|
@@ -20,8 +22,28 @@ module TimeClock
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
def days
|
26
|
+
dates = Set.new
|
27
|
+
calendar.shifts.each do |shift|
|
28
|
+
if period.overlapping_seconds(shift) > 0
|
29
|
+
dates.add shift.start_time.to_date
|
30
|
+
dates.add shift.end_time.to_date
|
31
|
+
end
|
32
|
+
end
|
33
|
+
dates.size
|
34
|
+
end
|
35
|
+
|
23
36
|
private
|
24
37
|
|
38
|
+
def end_time_from_value(value)
|
39
|
+
case value
|
40
|
+
when Time, ActiveSupport::TimeWithZone
|
41
|
+
value.to_time
|
42
|
+
when Date
|
43
|
+
(value + 1).to_time
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
25
47
|
def earlier_time
|
26
48
|
start_time < end_time ? start_time : end_time
|
27
49
|
end
|
@@ -31,4 +53,4 @@ module TimeClock
|
|
31
53
|
end
|
32
54
|
|
33
55
|
end
|
34
|
-
end
|
56
|
+
end
|
data/lib/time_clock/version.rb
CHANGED
@@ -60,8 +60,19 @@ module TimeClock
|
|
60
60
|
it "should calculate seconds between" do
|
61
61
|
expect(subject.seconds).to eq 60 * 60 * 4
|
62
62
|
end
|
63
|
+
it "should calculate days" do
|
64
|
+
expect(subject.days).to eq 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context "when the times are across two days" do
|
68
|
+
let(:start_time) { Time.new(2013,8,20,10) }
|
69
|
+
let(:end_time) { Time.new(2013,8,21,14) }
|
70
|
+
|
71
|
+
it "should calculate days" do
|
72
|
+
expect(subject.days).to eq 2
|
73
|
+
end
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
77
|
end
|
67
|
-
end
|
78
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Date do
|
4
|
+
subject { Date.new(2013,8,13) }
|
5
|
+
let(:end_date) { Date.new(2013,8,14) }
|
6
|
+
|
7
|
+
it "should calculate business_seconds_until" do
|
8
|
+
comparison = double("comparison", days: 3)
|
9
|
+
expect(TimeClock::Comparison).to receive(:new).with(subject, end_date).and_return(comparison)
|
10
|
+
expect(subject.business_days_until(end_date)).to eq comparison.days
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_clock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- barelyknown
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: metric_fu
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov-rcov-text
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Calculate the business time for a period of time.
|
@@ -115,23 +115,26 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .rspec
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
120
|
- Gemfile
|
121
121
|
- Guardfile
|
122
122
|
- LICENSE.txt
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- lib/time_clock.rb
|
126
|
+
- lib/time_clock/business_days_until.rb
|
126
127
|
- lib/time_clock/business_time_until.rb
|
127
128
|
- lib/time_clock/calendar.rb
|
128
129
|
- lib/time_clock/comparison.rb
|
130
|
+
- lib/time_clock/core_ext/date.rb
|
129
131
|
- lib/time_clock/core_ext/time.rb
|
130
132
|
- lib/time_clock/core_ext/time_with_zone.rb
|
131
133
|
- lib/time_clock/shift.rb
|
132
134
|
- lib/time_clock/version.rb
|
133
135
|
- spec/lib/time_clock/calendar_spec.rb
|
134
136
|
- spec/lib/time_clock/comparison_spec.rb
|
137
|
+
- spec/lib/time_clock/core_ext/date_spec.rb
|
135
138
|
- spec/lib/time_clock/core_ext/time_spec.rb
|
136
139
|
- spec/lib/time_clock/shift_spec.rb
|
137
140
|
- spec/lib/time_clock_spec.rb
|
@@ -147,25 +150,25 @@ require_paths:
|
|
147
150
|
- lib
|
148
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
152
|
requirements:
|
150
|
-
- -
|
153
|
+
- - ">="
|
151
154
|
- !ruby/object:Gem::Version
|
152
155
|
version: '0'
|
153
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
157
|
requirements:
|
155
|
-
- -
|
158
|
+
- - ">="
|
156
159
|
- !ruby/object:Gem::Version
|
157
160
|
version: '0'
|
158
161
|
requirements: []
|
159
162
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.2.2
|
161
164
|
signing_key:
|
162
165
|
specification_version: 4
|
163
166
|
summary: Calculate the business time for a period of time.
|
164
167
|
test_files:
|
165
168
|
- spec/lib/time_clock/calendar_spec.rb
|
166
169
|
- spec/lib/time_clock/comparison_spec.rb
|
170
|
+
- spec/lib/time_clock/core_ext/date_spec.rb
|
167
171
|
- spec/lib/time_clock/core_ext/time_spec.rb
|
168
172
|
- spec/lib/time_clock/shift_spec.rb
|
169
173
|
- spec/lib/time_clock_spec.rb
|
170
174
|
- spec/spec_helper.rb
|
171
|
-
has_rdoc:
|