timerage 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d2ce967a8b55c69a7296b30f83b8e4cbf187926
4
- data.tar.gz: fac80cd77fdacd79a53c76f54c7c15943da8b932
3
+ metadata.gz: d9c4a01a7d8ba83c2829e4bec7eaf00e33ae4beb
4
+ data.tar.gz: b60764ca0beb7a138de33035b849cd2ac132adf2
5
5
  SHA512:
6
- metadata.gz: a4eafa5361792a724815d1c90a1c44f7f63b37bfe82ee08015310c98205bb87bbb6d5984802372b8c2adfedd3d5feafc711ea5a9f29437fc8fb4eed692540465
7
- data.tar.gz: 9049a7ddff2190f712eadea970f727fa0d9ca9fcd4c1e04f65d37d7a82506e56b2b8ef97ee874c4b40e7961466062ab2c89ba27f94483df4e9d878a9107e43f0
6
+ metadata.gz: 9eac547686f938795999e6d02220917a4ac884a45f9a1c6bdef6473a8529a07ba65ead34bafd28cdd67bf6b081e3917f9f7b2e3ecc6ba17ee9f8390f1a9ff0e6
7
+ data.tar.gz: d4cb8f8dbd21380b4da2ce7d7ba9d8f8e426b8053101738b4f45c8d4b0936fe4be261e06a9fbc758ed119119e34d7d2927446c35649f32d777661fbd9a3ebdc1
@@ -23,12 +23,27 @@ module Timerage
23
23
  end
24
24
  end
25
25
 
26
+ # Return new TimeInterval that is the concatenation of self and
27
+ # other (if possible).
28
+ #
29
+ # Raises ArgumentError if other is not adjacent to self
30
+ # chronologically.
31
+ def +(other)
32
+ fail ArgumentError, "other must be adjacent to self" unless adjacent_to?(other)
33
+
34
+ self.class.new([self.begin, other.begin].min, [self.end, other.end].max)
35
+ end
36
+
26
37
  # Returns an ISO8601 interval representation of self
27
38
  # Takes same args as Time#iso8601
28
39
  def iso8601(*args)
29
40
  "#{self.begin.iso8601(*args)}/#{self.end.iso8601(*args)}"
30
41
  end
31
42
 
43
+ def adjacent_to?(other)
44
+ other.begin == self.end || other.end == self.begin
45
+ end
46
+
32
47
  protected
33
48
 
34
49
  def rangeish?(an_obj)
@@ -1,3 +1,3 @@
1
1
  module Timerage
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -34,7 +34,29 @@ 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
- context "interval include end" do
37
+ describe "+" do
38
+ let(:adjacent_preceding_time_range) { interval.begin-42..interval.begin }
39
+ let(:adjacent_following_time_range) { interval.end..interval.end+42 }
40
+ let(:nonadjacent_time_range) { interval.end+1..interval.end+42 }
41
+
42
+ specify { expect( interval + adjacent_following_time_range )
43
+ .to be_kind_of described_class }
44
+ specify { expect( interval + adjacent_following_time_range )
45
+ .to end_at adjacent_following_time_range.end }
46
+ specify { expect( interval + adjacent_following_time_range )
47
+ .to begin_at interval.begin }
48
+
49
+ specify { expect( interval + adjacent_preceding_time_range )
50
+ .to be_kind_of described_class }
51
+ specify { expect( interval + adjacent_preceding_time_range )
52
+ .to end_at interval.end }
53
+ specify { expect( interval + adjacent_preceding_time_range )
54
+ .to begin_at adjacent_preceding_time_range.begin }
55
+
56
+ specify { expect{ interval + nonadjacent_time_range }.to raise_error ArgumentError }
57
+ end
58
+
59
+ context "inclusive end" do
38
60
  specify { expect(interval.exclude_end?).to be false }
39
61
  specify { expect(interval.cover? now).to be true }
40
62
  specify { expect(interval.cover? now - duration).to be true }
@@ -51,7 +73,7 @@ describe Timerage::TimeInterval do
51
73
  end
52
74
  end
53
75
 
54
- context "interval exclude end" do
76
+ context "exclusive end" do
55
77
  subject(:interval) { described_class.new(now-duration...now) }
56
78
 
57
79
  specify { expect(interval.exclude_end?).to be true }
@@ -71,4 +93,16 @@ describe Timerage::TimeInterval do
71
93
  Set[*expected.instance_methods].subset? Set[*actual.methods]
72
94
  end
73
95
  end
96
+
97
+ matcher :begin_at do |expected|
98
+ match do |actual|
99
+ expect( actual.begin ).to eq expected
100
+ end
101
+ end
102
+
103
+ matcher :end_at do |expected|
104
+ match do |actual|
105
+ expect( actual.end ).to eq expected
106
+ end
107
+ end
74
108
  end
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.3.0
4
+ version: 1.4.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-02-24 00:00:00.000000000 Z
12
+ date: 2015-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler