periods 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/periods/modules/halfyearly_period.rb +0 -10
- data/lib/periods/modules/period.rb +11 -3
- data/lib/periods/modules/quarterly_period.rb +0 -10
- data/lib/periods/modules/year.rb +0 -10
- data/lib/periods/modules/yearly_period.rb +0 -10
- data/lib/periods/version.rb +1 -1
- data/spec/lib/halfyear_spec.rb +2 -2
- data/spec/lib/halfyearly_period_spec.rb +2 -2
- data/spec/lib/month_spec.rb +2 -2
- data/spec/lib/monthly_period_spec.rb +2 -2
- data/spec/lib/own_class_spec.rb +19 -0
- data/spec/lib/period_spec.rb +32 -1
- data/spec/lib/periods/date_calculator_spec.rb +6 -6
- data/spec/lib/quarter_spec.rb +2 -2
- data/spec/lib/quarterly_period_spec.rb +2 -2
- data/spec/lib/year_spec.rb +2 -2
- data/spec/lib/yearly_period_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b340e86339eee67b5f7915f6df4d6e809aba2107
|
4
|
+
data.tar.gz: 0d613dce4f4898974d2953797e8cd9cd0b6b72b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f299f089e6a1c016005d0120b8784cb317bd7ed73061dd76906fb35eb1b4a2c81da882928608b974f1c54bbda33e9f9993a6c7f362754a4a77575b82e26d92d8
|
7
|
+
data.tar.gz: adc4461e7f2d1e8b2cf112a0bb8baddf9e3732ded407f6ed66d933f9493cbfc2f936d9da25336eb449cfebe817d319c17fe676c25b7d80d6aa3589354707c3e2
|
@@ -35,16 +35,6 @@ module Periods
|
|
35
35
|
(self.next.start_date - start_date).to_i
|
36
36
|
end
|
37
37
|
|
38
|
-
def include?(period)
|
39
|
-
if period.is_a?(String) || period.is_a?(Date)
|
40
|
-
super
|
41
|
-
elsif period.is_a?(Period)
|
42
|
-
start_date <= period.start_date && period.end_date <= end_date
|
43
|
-
else
|
44
|
-
false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
@@ -43,9 +43,17 @@ module Periods
|
|
43
43
|
end_date.yday - start_date.yday + 1
|
44
44
|
end
|
45
45
|
|
46
|
-
def include?(
|
47
|
-
|
48
|
-
|
46
|
+
def include?(period)
|
47
|
+
if period.is_a?(Date)
|
48
|
+
start_date <= period && period <= end_date
|
49
|
+
elsif period.is_a?(String)
|
50
|
+
date = Date.parse(period.to_s)
|
51
|
+
start_date <= date && date <= end_date
|
52
|
+
elsif period.is_a?(Period)
|
53
|
+
start_date <= period.start_date && period.end_date <= end_date
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
def to_s
|
@@ -38,16 +38,6 @@ module Periods
|
|
38
38
|
self.class.for(start_date.prev_month(3))
|
39
39
|
end
|
40
40
|
|
41
|
-
def include?(period)
|
42
|
-
if period.is_a?(String) || period.is_a?(Date)
|
43
|
-
super
|
44
|
-
elsif period.is_a?(Period)
|
45
|
-
start_date <= period.start_date && period.end_date <= end_date
|
46
|
-
else
|
47
|
-
false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
41
|
end
|
52
42
|
end
|
53
43
|
end
|
data/lib/periods/modules/year.rb
CHANGED
@@ -47,16 +47,6 @@ module Periods
|
|
47
47
|
(self.next.start_date - start_date).to_i
|
48
48
|
end
|
49
49
|
|
50
|
-
def include?(period)
|
51
|
-
if period.is_a?(String) || period.is_a?(Date)
|
52
|
-
super
|
53
|
-
elsif period.is_a?(Period)
|
54
|
-
start_date <= period.start_date && period.end_date <= end_date
|
55
|
-
else
|
56
|
-
false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
50
|
def year
|
61
51
|
start_date.year
|
62
52
|
end
|
@@ -41,16 +41,6 @@ module Periods
|
|
41
41
|
(self.next.start_date - start_date).to_i
|
42
42
|
end
|
43
43
|
|
44
|
-
def include?(period)
|
45
|
-
if period.is_a?(String) || period.is_a?(Date)
|
46
|
-
super
|
47
|
-
elsif period.is_a?(Period)
|
48
|
-
start_date <= period.start_date && period.end_date <= end_date
|
49
|
-
else
|
50
|
-
false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
44
|
end
|
55
45
|
end
|
56
46
|
end
|
data/lib/periods/version.rb
CHANGED
data/spec/lib/halfyear_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Halfyear do
|
|
11
11
|
it "returns month of given date included" do
|
12
12
|
month = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(month.start_date).to eq
|
15
|
-
expect(month.end_date).to eq
|
14
|
+
expect(month.start_date).to eq Date('01.06.2015')
|
15
|
+
expect(month.end_date).to eq Date('30.11.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -11,8 +11,8 @@ describe HalfyearlyPeriod do
|
|
11
11
|
it "returns halfyear of given date included" do
|
12
12
|
period = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(period.start_date).to eq
|
15
|
-
expect(period.end_date).to eq
|
14
|
+
expect(period.start_date).to eq Date('25.06.2015')
|
15
|
+
expect(period.end_date).to eq Date('24.12.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/spec/lib/month_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Month do
|
|
11
11
|
it "returns month of given date included" do
|
12
12
|
month = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(month.start_date).to eq
|
15
|
-
expect(month.end_date).to eq
|
14
|
+
expect(month.start_date).to eq Date('01.06.2015')
|
15
|
+
expect(month.end_date).to eq Date('30.06.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -11,8 +11,8 @@ describe MonthlyPeriod do
|
|
11
11
|
it "returns month of given date included" do
|
12
12
|
month = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(month.start_date).to eq
|
15
|
-
expect(month.end_date).to eq
|
14
|
+
expect(month.start_date).to eq Date('25.06.2015')
|
15
|
+
expect(month.end_date).to eq Date('24.07.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'periods/modules'
|
3
|
+
|
4
|
+
class MyMonth
|
5
|
+
include Periods::Modules::Month
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "defining own classes including period module" do
|
9
|
+
|
10
|
+
describe ".for" do
|
11
|
+
it "set start and end date" do
|
12
|
+
month = MyMonth.for('25.06.2015')
|
13
|
+
|
14
|
+
expect(month.start_date).to eq Date('01.06.2015')
|
15
|
+
expect(month.end_date).to eq Date('30.06.2015')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/lib/period_spec.rb
CHANGED
@@ -57,18 +57,49 @@ describe Period do
|
|
57
57
|
|
58
58
|
describe "#include?" do
|
59
59
|
context "date included" do
|
60
|
+
it "returns true" do
|
61
|
+
expect(new_period("01.02.2015", "28.02.2015").include?(Date("01.02.2015"))).to be_truthy
|
62
|
+
expect(new_period("01.02.2015", "28.02.2015").include?(Date("28.02.2015"))).to be_truthy
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "date not included" do
|
67
|
+
it "returns false" do
|
68
|
+
expect(new_period("01.02.2015", "28.02.2015").include?(Date("31.01.2015"))).to be_falsey
|
69
|
+
expect(new_period("01.02.2015", "28.02.2015").include?(Date("01.03.2015"))).to be_falsey
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "date string included" do
|
60
74
|
it "returns true" do
|
61
75
|
expect(new_period("01.02.2015", "28.02.2015").include?("01.02.2015")).to be_truthy
|
62
76
|
expect(new_period("01.02.2015", "28.02.2015").include?("28.02.2015")).to be_truthy
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
66
|
-
context "date not included" do
|
80
|
+
context "date string not included" do
|
67
81
|
it "returns false" do
|
68
82
|
expect(new_period("01.02.2015", "28.02.2015").include?("31.01.2015")).to be_falsey
|
69
83
|
expect(new_period("01.02.2015", "28.02.2015").include?("01.03.2015")).to be_falsey
|
70
84
|
end
|
71
85
|
end
|
86
|
+
|
87
|
+
context "period included" do
|
88
|
+
it "returns true" do
|
89
|
+
period = new_period("10.04.2015", "20.05.2015")
|
90
|
+
expect(period.include?(new_period("10.04.2015", "20.05.2015"))).to be_truthy
|
91
|
+
expect(period.include?(new_period("11.04.2015", "20.05.2015"))).to be_truthy
|
92
|
+
expect(period.include?(new_period("10.04.2015", "19.05.2015"))).to be_truthy
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "period not included" do
|
97
|
+
it "returns false" do
|
98
|
+
period = new_period("10.04.2015", "20.05.2015")
|
99
|
+
expect(period.include?(new_period("09.04.2015", "20.05.2015"))).to be_falsey
|
100
|
+
expect(period.include?(new_period("10.04.2015", "21.05.2015"))).to be_falsey
|
101
|
+
end
|
102
|
+
end
|
72
103
|
end
|
73
104
|
end
|
74
105
|
|
@@ -6,17 +6,17 @@ module Periods
|
|
6
6
|
|
7
7
|
describe "#beginning_of_month" do
|
8
8
|
it "returns given date with first day of month" do
|
9
|
-
expect(described_class.new('01.06.2015').beginning_of_month).to eq
|
10
|
-
expect(described_class.new('02.06.2015').beginning_of_month).to eq
|
11
|
-
expect(described_class.new('30.06.2015').beginning_of_month).to eq
|
9
|
+
expect(described_class.new('01.06.2015').beginning_of_month).to eq Date('01.06.2015')
|
10
|
+
expect(described_class.new('02.06.2015').beginning_of_month).to eq Date('01.06.2015')
|
11
|
+
expect(described_class.new('30.06.2015').beginning_of_month).to eq Date('01.06.2015')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#end_of_month" do
|
16
16
|
it "returns given date with last day of month" do
|
17
|
-
expect(described_class.new('01.06.2015').end_of_month).to eq
|
18
|
-
expect(described_class.new('02.06.2015').end_of_month).to eq
|
19
|
-
expect(described_class.new('30.06.2015').end_of_month).to eq
|
17
|
+
expect(described_class.new('01.06.2015').end_of_month).to eq Date('30.06.2015')
|
18
|
+
expect(described_class.new('02.06.2015').end_of_month).to eq Date('30.06.2015')
|
19
|
+
expect(described_class.new('30.06.2015').end_of_month).to eq Date('30.06.2015')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/spec/lib/quarter_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Quarter do
|
|
11
11
|
it "returns quarter of given date included" do
|
12
12
|
period = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(period.start_date).to eq
|
15
|
-
expect(period.end_date).to eq
|
14
|
+
expect(period.start_date).to eq Date('01.06.2015')
|
15
|
+
expect(period.end_date).to eq Date('31.08.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -11,8 +11,8 @@ describe QuarterlyPeriod do
|
|
11
11
|
it "returns quarter of given date included" do
|
12
12
|
period = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(period.start_date).to eq
|
15
|
-
expect(period.end_date).to eq
|
14
|
+
expect(period.start_date).to eq Date('25.06.2015')
|
15
|
+
expect(period.end_date).to eq Date('24.09.2015')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/spec/lib/year_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe Year do
|
|
11
11
|
it "returns month of given date included" do
|
12
12
|
month = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(month.start_date).to eq
|
15
|
-
expect(month.end_date).to eq
|
14
|
+
expect(month.start_date).to eq Date('01.06.2015')
|
15
|
+
expect(month.end_date).to eq Date('31.05.2016')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -11,8 +11,8 @@ describe YearlyPeriod do
|
|
11
11
|
it "returns year of given date included" do
|
12
12
|
period = described_class.for('25.06.2015')
|
13
13
|
|
14
|
-
expect(period.start_date).to eq
|
15
|
-
expect(period.end_date).to eq
|
14
|
+
expect(period.start_date).to eq Date('25.06.2015')
|
15
|
+
expect(period.end_date).to eq Date('24.06.2016')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: periods
|
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
|
- Thomas Baustert
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- spec/lib/january_spec.rb
|
98
98
|
- spec/lib/month_spec.rb
|
99
99
|
- spec/lib/monthly_period_spec.rb
|
100
|
+
- spec/lib/own_class_spec.rb
|
100
101
|
- spec/lib/period_spec.rb
|
101
102
|
- spec/lib/periods/date_calculator_spec.rb
|
102
103
|
- spec/lib/quarter_spec.rb
|
@@ -135,6 +136,7 @@ test_files:
|
|
135
136
|
- spec/lib/january_spec.rb
|
136
137
|
- spec/lib/month_spec.rb
|
137
138
|
- spec/lib/monthly_period_spec.rb
|
139
|
+
- spec/lib/own_class_spec.rb
|
138
140
|
- spec/lib/period_spec.rb
|
139
141
|
- spec/lib/periods/date_calculator_spec.rb
|
140
142
|
- spec/lib/quarter_spec.rb
|