timeboss 1.1.2 → 1.1.3

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
  SHA256:
3
- metadata.gz: b856796bb4e37e5776aeed86c19dd42832af3091b189f01878d907de5cbf1864
4
- data.tar.gz: 824c18de591069e4c46d01dc14dc2c1a2ee54881b670218014adf3d4d220a0da
3
+ metadata.gz: 65f9e2cd955a728e0efd00e99f530f1ff6dbb7ee0c8cee7e25499466fb10edc9
4
+ data.tar.gz: 9523e2983ffff0d5d33cf9b07e7fd4cd1b26b54c68e8a3f77d8996aaa7ad991d
5
5
  SHA512:
6
- metadata.gz: 24bc5de8281c36802fb79b92b79a2381794710d320d2890d022c40f40aef4cedb1e3fe963085e3e1ea39fe9f51715994ccca4e5844c0e8bfb2784cbb65c2a339
7
- data.tar.gz: a1fb6c4825ad05f9dd21a8514c6e6dc24a4904cb235a2a1d16b888e3664fa5f92c6ea8b4ccef3c09198c8e2aea272fb662610bd25fc5ed210f2b095feb90fab3
6
+ metadata.gz: 1f850961e4659cee0b07e59d4421f1444c39e3882338f5189cd5821e5d4ec00228c4043aef7c001df8a2181cf4161671943653e7e0c843f419f4f7d91b6bb99d
7
+ data.tar.gz: 24a8f28844c20caf7f0294a5e5db155ff809f46ad76e421e97d807b929ceca37035d9b89539a5600713d9420ba8f799fa1668c61e47b040a8728c41df12a67df
@@ -84,6 +84,15 @@ module TimeBoss
84
84
  @_to_range ||= start_date..end_date
85
85
  end
86
86
 
87
+ # Clamp this unit to the range of the provided unit.
88
+ # @return [Period]
89
+ def clamp(unit)
90
+ new_start_date = start_date.clamp(unit.start_date, unit.end_date)
91
+ new_end_date = end_date.clamp(unit.start_date, unit.end_date)
92
+ return unless new_start_date.between?(start_date, end_date) && new_end_date.between?(start_date, end_date)
93
+ calendar.parse("#{new_start_date}..#{new_end_date}")
94
+ end
95
+
87
96
  def inspect
88
97
  "#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>"
89
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimeBoss
4
- VERSION = "1.1.2"
4
+ VERSION = "1.1.3"
5
5
  end
@@ -28,6 +28,57 @@ module TimeBoss
28
28
  end
29
29
  end
30
30
 
31
+ describe "#clamp" do
32
+ let(:clamp_start_date) { Date.parse("2018-06-21") }
33
+ let(:clamp_end_date) { Date.parse("2018-08-30") }
34
+ let(:result) { subject.clamp(described_class.new(calendar, clamp_start_date, clamp_end_date)) }
35
+ let(:period) { double }
36
+
37
+ context "open" do
38
+ it "does not restrict the returned period" do
39
+ expect(calendar).to receive(:parse).with("#{start_date}..#{end_date}").and_return period
40
+ expect(result).to eq period
41
+ end
42
+ end
43
+
44
+ context "left clamped" do
45
+ let(:clamp_start_date) { Date.parse("2018-06-30") }
46
+
47
+ it "brings the beginning date inward" do
48
+ expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{end_date}").and_return period
49
+ expect(result).to eq period
50
+ end
51
+ end
52
+
53
+ context "right clamped" do
54
+ let(:clamp_end_date) { Date.parse("2018-07-30") }
55
+
56
+ it "brings the beginning date inward" do
57
+ expect(calendar).to receive(:parse).with("#{start_date}..#{clamp_end_date}").and_return period
58
+ expect(result).to eq period
59
+ end
60
+ end
61
+
62
+ context "fully clamped" do
63
+ let(:clamp_start_date) { Date.parse("2018-06-30") }
64
+ let(:clamp_end_date) { Date.parse("2018-07-30") }
65
+
66
+ it "brings the beginning date inward" do
67
+ expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{clamp_end_date}").and_return period
68
+ expect(result).to eq period
69
+ end
70
+ end
71
+
72
+ context "obliterated" do
73
+ let(:clamp_start_date) { Date.parse("2018-09-01") }
74
+ let(:clamp_end_date) { Date.parse("2018-09-06") }
75
+
76
+ it "returns nil" do
77
+ expect(result).to be_nil
78
+ end
79
+ end
80
+ end
81
+
31
82
  context "periods" do
32
83
  before(:each) do
33
84
  allow(calendar).to receive(:days_for).with(subject).and_return %w[D1 D2 D3 D4 D5 D6 D7 D8]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McDonald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport