timerage 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timerage/time_interval.rb +36 -0
- data/lib/timerage/version.rb +1 -1
- data/spec/timerage/time_interval_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9622b03dc29826d6fd62282884dc1de42fb7bd04
|
4
|
+
data.tar.gz: 8c1c012b9584779d84822c8f6a2358f1a1daaeff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b876dde86b6aa1542e29a80f46e59a9b24de9a7b72255ac5772e7ec1de61430001a76ad1874eaee071a0bcfe37dd85b838c392dc331c9b148948e420a6d63f7a
|
7
|
+
data.tar.gz: 62bc60b3fb6b6e5c5e3d1234139ba5fc270856dfa824f643b22cb4c9b5e01aba0256e8e1150cb3776310312af06953f1a19aa4b6b0fbf6731e524aa5d47ae1e4
|
@@ -44,6 +44,42 @@ module Timerage
|
|
44
44
|
other.begin == self.end || other.end == self.begin
|
45
45
|
end
|
46
46
|
|
47
|
+
|
48
|
+
def cover?(time_or_interval)
|
49
|
+
return super unless rangeish?(time_or_interval)
|
50
|
+
|
51
|
+
other = time_or_interval
|
52
|
+
|
53
|
+
self.begin <= other.begin &&
|
54
|
+
if self.exclude_end? && other.exclude_end?
|
55
|
+
self.end > other.begin && self.begin < other.end && other.end <= self.end
|
56
|
+
|
57
|
+
elsif self.exclude_end?
|
58
|
+
self.end > other.begin && self.begin <= other.end && other.end < self.end
|
59
|
+
|
60
|
+
elsif other.exclude_end?
|
61
|
+
self.end >= other.begin && self.begin < other.end && other.end <= self.end
|
62
|
+
|
63
|
+
else
|
64
|
+
self.end >= other.begin && self.begin <= other.end && other.end <= self.end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def overlap?(other)
|
69
|
+
cover?(other) ||
|
70
|
+
other.cover?(self) ||
|
71
|
+
cover?(other.begin) ||
|
72
|
+
other.cover?(self.begin) ||
|
73
|
+
cover?(other.end) && (!other.exclude_end? || other.end != self.begin) ||
|
74
|
+
other.cover?(self.end) && (!self.exclude_end? || other.begin != self.end)
|
75
|
+
end
|
76
|
+
|
77
|
+
def <=>(other)
|
78
|
+
return super unless rangeish?(other)
|
79
|
+
|
80
|
+
self.begin <=> other.begin
|
81
|
+
end
|
82
|
+
|
47
83
|
protected
|
48
84
|
|
49
85
|
def rangeish?(an_obj)
|
data/lib/timerage/version.rb
CHANGED
@@ -34,6 +34,22 @@ describe Timerage::TimeInterval do
|
|
34
34
|
specify { expect(interval.iso8601(3))
|
35
35
|
.to eq "#{interval.begin.iso8601(3)}/#{interval.end.iso8601(3)}" }
|
36
36
|
|
37
|
+
specify { expect(interval.cover? interval.begin+1..interval.end-1).to be_truthy }
|
38
|
+
specify { expect(interval.cover? interval.begin...interval.end).to be_truthy }
|
39
|
+
specify { expect(interval.cover? interval.begin-1..interval.end-1).to be_falsy }
|
40
|
+
specify { expect(interval.cover? interval.begin+1..interval.end+1).to be_falsy }
|
41
|
+
|
42
|
+
specify { expect(interval.overlap? interval.begin+1..interval.end-1).to be_truthy }
|
43
|
+
specify { expect(interval.overlap? interval.begin...interval.end).to be_truthy }
|
44
|
+
specify { expect(interval.overlap? interval.begin-1..interval.end-1).to be_truthy }
|
45
|
+
specify { expect(interval.overlap? interval.begin+1..interval.end+1).to be_truthy }
|
46
|
+
specify { expect(interval.overlap? interval.end+1..interval.end+2).to be_falsy }
|
47
|
+
specify { expect(interval.overlap? interval.begin-2..interval.begin-1).to be_falsy }
|
48
|
+
|
49
|
+
specify { expect(interval <=> (interval.begin-2..interval.begin-1)).to eq 1}
|
50
|
+
specify { expect(interval <=> (interval.end+1..interval.end+2)).to eq -1}
|
51
|
+
specify { expect(interval <=> interval).to eq 0}
|
52
|
+
|
37
53
|
describe "+" do
|
38
54
|
let(:adjacent_preceding_time_range) { interval.begin-42..interval.begin }
|
39
55
|
let(:adjacent_following_time_range) { interval.end..interval.end+42 }
|
@@ -56,6 +72,7 @@ describe Timerage::TimeInterval do
|
|
56
72
|
specify { expect{ interval + nonadjacent_time_range }.to raise_error ArgumentError }
|
57
73
|
end
|
58
74
|
|
75
|
+
|
59
76
|
context "inclusive end" do
|
60
77
|
specify { expect(interval.exclude_end?).to be false }
|
61
78
|
specify { expect(interval.cover? now).to be true }
|
@@ -63,6 +80,13 @@ describe Timerage::TimeInterval do
|
|
63
80
|
specify { expect(interval.cover? now - (duration/2)).to be true }
|
64
81
|
specify { expect(interval.cover? now + 1).to be false }
|
65
82
|
specify { expect(interval.cover? now - (duration + 1)).to be false }
|
83
|
+
specify { expect(interval.cover? interval.begin..interval.end).to be_truthy }
|
84
|
+
specify { expect(interval.cover? interval.begin...interval.end).to be_truthy}
|
85
|
+
|
86
|
+
specify { expect(interval.overlap? interval.begin..interval.end).to be_truthy }
|
87
|
+
specify { expect(interval.overlap? interval.begin...interval.end).to be_truthy }
|
88
|
+
specify { expect(interval.overlap? interval.end-1..interval.end+1).to be_truthy }
|
89
|
+
specify { expect(interval.overlap? interval.end..interval.end+1).to be_truthy }
|
66
90
|
|
67
91
|
specify { expect{|b| interval.step(1200, &b) }
|
68
92
|
.to yield_successive_args now-duration, now-(duration-1200), now-(duration-2400), now }
|
@@ -82,6 +106,14 @@ describe Timerage::TimeInterval do
|
|
82
106
|
specify { expect(interval.cover? now - (duration/2)).to be true }
|
83
107
|
specify { expect(interval.cover? now + 1).to be false }
|
84
108
|
specify { expect(interval.cover? now - (duration + 1)).to be false }
|
109
|
+
specify { expect(interval.cover? interval.end).to be false }
|
110
|
+
specify { expect(interval.cover? interval.begin..interval.end).to be_falsy }
|
111
|
+
specify { expect(interval.cover? interval.begin...interval.end).to be_truthy}
|
112
|
+
|
113
|
+
specify { expect(interval.overlap? interval.begin..interval.end).to be_truthy }
|
114
|
+
specify { expect(interval.overlap? interval.begin...interval.end).to be_truthy }
|
115
|
+
specify { expect(interval.overlap? interval.end-1..interval.end+1).to be_truthy }
|
116
|
+
specify { expect(interval.overlap? interval.end..interval.end+1).to be_falsy }
|
85
117
|
|
86
118
|
specify { expect{|b| interval.step(1200, &b) }
|
87
119
|
.to yield_successive_args now-duration, now-(duration-1200), now-(duration-2400) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timerage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Williams
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|