time_clock 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/time_clock/calendar.rb +5 -4
- data/lib/time_clock/comparison.rb +14 -1
- data/lib/time_clock/shift.rb +1 -0
- data/lib/time_clock/version.rb +1 -1
- data/lib/time_clock.rb +2 -2
- data/spec/lib/time_clock/calendar_spec.rb +1 -1
- data/spec/lib/time_clock/comparison_spec.rb +15 -0
- data/spec/lib/time_clock/core_ext/time_spec.rb +15 -2
- data/spec/spec_helper.rb +5 -0
- data/time_clock.gemspec +2 -0
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3b80eff32b5fadb72dbeff176ee5b2ac58a9f09
|
4
|
+
data.tar.gz: 2fa81d1db7ea7835a56b0afeb7ad0768c27c4244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96926eed8ac4f075d0aeda39b9f3f0cdf8f0b0f6a90011e616b922285f91eb7d95a898e72c63c6e02e2faa22161867e57a0f697585a8aca60a34bf2f9fc38382
|
7
|
+
data.tar.gz: 68b0052866e7a1514c385f24ea1fd4801bbfc8476f00ae27addbb306100f8586cea3e067f9dc0ea8093a2a80e3c830c4d2ee02e891be3e202a59f5ce843aba86
|
data/README.md
CHANGED
@@ -17,10 +17,12 @@ You can also make custom calendars for each calculation (see Calendars section f
|
|
17
17
|
|
18
18
|
**Things you may like about this library:**
|
19
19
|
|
20
|
-
- No dependencies.
|
21
|
-
- Extremely simple codebase. Only 80 lines of code.
|
22
20
|
- Works with any kind of `Time`, including mixed types.
|
21
|
+
- Extremely simple codebase. Less than 100 lines of code.
|
23
22
|
- Easy to customize with totally custom business calendars.
|
23
|
+
- No dependencies.
|
24
|
+
- 100% test coverage.
|
25
|
+
- [](https://codeclimate.com/repos/5214185789af7e04ce021d7b/feed)
|
24
26
|
|
25
27
|
## Configuration
|
26
28
|
|
data/lib/time_clock/calendar.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module TimeClock
|
2
2
|
class Calendar
|
3
|
+
|
3
4
|
class OverlappingShiftError < ArgumentError; end
|
4
5
|
|
5
6
|
attr_reader :shifts
|
@@ -10,12 +11,12 @@ module TimeClock
|
|
10
11
|
|
11
12
|
def add_shift(new_shift)
|
12
13
|
starting_shift_count = @shifts.size
|
13
|
-
|
14
|
+
shifts.each_with_index do |shift, index|
|
14
15
|
raise OverlappingShiftError if new_shift.overlaps?(shift)
|
15
|
-
break
|
16
|
+
break shifts.insert(index, new_shift) if shift.start_time > new_shift.end_time
|
16
17
|
end
|
17
|
-
|
18
|
-
|
18
|
+
shifts << new_shift unless shifts.size > starting_shift_count
|
19
|
+
shifts
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module TimeClock
|
2
2
|
class Comparison
|
3
3
|
|
4
|
+
class NilCalendarError < ArgumentError; end
|
5
|
+
|
4
6
|
attr_reader :start_time, :end_time, :calendar
|
5
7
|
|
6
8
|
def initialize(start_time, end_time, calendar=TimeClock.default_calendar)
|
9
|
+
raise NilCalendarError unless calendar
|
7
10
|
@start_time, @end_time, @calendar = start_time, end_time, calendar
|
8
11
|
end
|
9
12
|
|
10
13
|
def period
|
11
|
-
@period ||= Shift.new(
|
14
|
+
@period ||= Shift.new(earlier_time, later_time)
|
12
15
|
end
|
13
16
|
|
14
17
|
def seconds
|
@@ -17,5 +20,15 @@ module TimeClock
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
23
|
+
private
|
24
|
+
|
25
|
+
def earlier_time
|
26
|
+
start_time < end_time ? start_time : end_time
|
27
|
+
end
|
28
|
+
|
29
|
+
def later_time
|
30
|
+
end_time > start_time ? end_time : start_time
|
31
|
+
end
|
32
|
+
|
20
33
|
end
|
21
34
|
end
|
data/lib/time_clock/shift.rb
CHANGED
data/lib/time_clock/version.rb
CHANGED
data/lib/time_clock.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "time_clock/version"
|
2
2
|
|
3
|
-
require "time_clock/core_ext/time"
|
4
|
-
|
5
3
|
require "time_clock/shift"
|
6
4
|
require "time_clock/calendar"
|
7
5
|
require "time_clock/comparison"
|
8
6
|
|
7
|
+
require "time_clock/core_ext/time"
|
8
|
+
|
9
9
|
module TimeClock
|
10
10
|
|
11
11
|
def self.default_calendar=(value)
|
@@ -27,6 +27,21 @@ module TimeClock
|
|
27
27
|
expect(subject.period).to eq Shift.new(start_time, end_time)
|
28
28
|
end
|
29
29
|
|
30
|
+
context "when the start time is after the end time" do
|
31
|
+
let(:start_time) { Time.now + 3600 }
|
32
|
+
let(:end_time) { Time.now }
|
33
|
+
it "should create a shift with flipped around times" do
|
34
|
+
expect(subject.period).to eq Shift.new(end_time, start_time)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when there is no default calendar and none is provided" do
|
39
|
+
it "should raise an error on initialization" do
|
40
|
+
TimeClock.stub(:default_calendar) { nil }
|
41
|
+
expect{described_class.new(start_time, end_time)}.to raise_error Comparison::NilCalendarError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
context "when calculating seconds between" do
|
31
46
|
let(:calendar) do
|
32
47
|
Calendar.new.tap do |c|
|
@@ -2,9 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Time do
|
4
4
|
subject { Time.new(2013,8,13,14,15) }
|
5
|
+
let(:end_time) { Time.new(2013,8,13,14,18) }
|
5
6
|
|
6
|
-
it "should
|
7
|
-
|
7
|
+
it "should calculate business_seconds_until" do
|
8
|
+
comparison = double("comparison", seconds: 3)
|
9
|
+
expect(TimeClock::Comparison).to receive(:new).with(subject, end_time).and_return(comparison)
|
10
|
+
expect(subject.business_seconds_until(end_time)).to eq comparison.seconds
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should calculate business minutes until" do
|
14
|
+
Time.any_instance.stub(:business_seconds_until) { 60 }
|
15
|
+
expect(subject.business_minutes_until(end_time)).to eq 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should calculate business hours until" do
|
19
|
+
Time.any_instance.stub(:business_seconds_until) { 3500 }
|
20
|
+
expect(subject.business_hours_until(end_time)).to eq 1
|
8
21
|
end
|
9
22
|
|
10
23
|
end
|
data/spec/spec_helper.rb
CHANGED
data/time_clock.gemspec
CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "guard-rspec"
|
25
25
|
spec.add_development_dependency "metric_fu"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
|
+
spec.add_development_dependency "simplecov-rcov-text"
|
26
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- barelyknown
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov-rcov-text
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Calculate the business time for a period of time.
|
84
112
|
email:
|
85
113
|
- sean@buytruckload.com
|