periods 0.0.8 → 0.0.9
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 +16 -8
- data/lib/periods/classes.rb +2 -1
- data/lib/periods/constants.rb +2 -0
- data/lib/periods/modules/week.rb +22 -0
- data/lib/periods/modules/weekly_period.rb +44 -0
- data/lib/periods/version.rb +1 -1
- data/lib/periods/week.rb +9 -0
- data/lib/periods/weekly_period.rb +9 -0
- data/spec/lib/monthly_period_spec.rb +17 -0
- data/spec/lib/weekly_period_spec.rb +71 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 446ed0da6cb8d02aec93a6573ff028b3e6bd1f19
|
4
|
+
data.tar.gz: dc4766070198c6d772a425c930c8007cd8ca7442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb40fd424a1e9fde278330c80bea9643f254e6ebe22679fec392a5a6babf38253649840b7bf6c407629a48caa9863357fefd520971bc60d3c1ee3b89c790958
|
7
|
+
data.tar.gz: 0cdf35d04f87cf7c5b8efb59d2f21f7597585b440058400a28823fafb2df1c66c79884b8edf475ba6f8953c1f48e253d8c1290a1695f6c49aa67d12e0e8698ae
|
data/README.md
CHANGED
@@ -109,6 +109,22 @@ Test whether a date or a period is included in the given period:
|
|
109
109
|
period.include?(Period.new('24.06.2015', '19.08.2015')) # => false
|
110
110
|
period.include?(Period.new('25.06.2015', '20.08.2015')) # => false
|
111
111
|
|
112
|
+
### WeeklyPeriod
|
113
|
+
|
114
|
+
If you need a constant weekly range use `WeeklyPeriod`:
|
115
|
+
|
116
|
+
weekly = WeeklyPeriod.for('25.06.2015') # => 25.06.2015 - 01.07.2015
|
117
|
+
weekly.next # => 02.07.2015 - 08.07.2015
|
118
|
+
weekly.previous # => 18.06.2015 - 24.06.2015
|
119
|
+
|
120
|
+
### Week
|
121
|
+
|
122
|
+
Same as `WeeklyPeriod`:
|
123
|
+
|
124
|
+
week = Week.for('25.06.2015') # => 25.06.2015 - 01.07.2015
|
125
|
+
week.next # => 02.07.2015 - 08.07.2015
|
126
|
+
week.previous # => 18.06.2015 - 24.06.2015
|
127
|
+
|
112
128
|
### MonthlyPeriod
|
113
129
|
|
114
130
|
If you need a constant monthly range use `MonthlyPeriod`:
|
@@ -202,14 +218,6 @@ Write your own classes:
|
|
202
218
|
month = MyMonth.for('01.08.2015')
|
203
219
|
...
|
204
220
|
|
205
|
-
## TODO
|
206
|
-
|
207
|
-
* Implement Week
|
208
|
-
* Use Time not Date
|
209
|
-
* Optimize README
|
210
|
-
* Comment Code
|
211
|
-
* Provide helper methods Month('25.06.2015'), Quarter(), ...
|
212
|
-
|
213
221
|
## Contributing
|
214
222
|
|
215
223
|
1. Fork it
|
data/lib/periods/classes.rb
CHANGED
data/lib/periods/constants.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'periods/date_calculator'
|
2
|
+
require 'periods/modules/weekly_period'
|
3
|
+
|
4
|
+
module Periods
|
5
|
+
module Modules
|
6
|
+
module Week
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
include Periods::Modules::WeeklyPeriod
|
11
|
+
include InstanceMethods
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'periods/modules/period'
|
2
|
+
require 'periods/modules/single_date_initialize'
|
3
|
+
|
4
|
+
module Periods
|
5
|
+
module Modules
|
6
|
+
module WeeklyPeriod
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
include Periods::Modules::Period
|
11
|
+
include SingleDateInitialize
|
12
|
+
include InstanceMethods
|
13
|
+
alias_method :succ, :next
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
##
|
19
|
+
# 25.06.2015 => 02.07.2015
|
20
|
+
#
|
21
|
+
def next
|
22
|
+
self.class.for(start_date + 7)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# 02.07.2015 => 25.06.2015
|
27
|
+
#
|
28
|
+
def previous
|
29
|
+
self.class.for(start_date - 7)
|
30
|
+
end
|
31
|
+
|
32
|
+
def days
|
33
|
+
7
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def init_with_date(date)
|
38
|
+
init_with_dates(date, date + 6)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/periods/version.rb
CHANGED
data/lib/periods/week.rb
ADDED
@@ -63,4 +63,21 @@ describe MonthlyPeriod do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe "#include?" do
|
67
|
+
context "week is included" do
|
68
|
+
it "returns true" do
|
69
|
+
expect(described_class.for('01.06.2015').include?(Week.for('01.06.2015'))).to be_truthy
|
70
|
+
expect(described_class.for('01.06.2015').include?(Week.for('02.06.2015'))).to be_truthy
|
71
|
+
expect(described_class.for('01.06.2015').include?(Week.for('07.06.2015'))).to be_truthy
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "week is not included" do
|
76
|
+
it "returns false" do
|
77
|
+
expect(described_class.for('01.06.2015').include?(Week.for('31.05.2015'))).to be_falsey
|
78
|
+
expect(described_class.for('01.06.2015').include?(Week.for('25.06.2015'))).to be_falsey
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
66
83
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'periods/constants'
|
3
|
+
require 'initialized_by_single_date'
|
4
|
+
|
5
|
+
describe WeeklyPeriod do
|
6
|
+
|
7
|
+
let(:subject) { described_class.for("1.1.2015") }
|
8
|
+
|
9
|
+
it_behaves_like "Initialized by single date" do
|
10
|
+
let(:period) { described_class.for(Date.new(2015,6,25)) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#next" do
|
14
|
+
it "returns next period" do
|
15
|
+
expect(described_class.for('25.06.2015').next).to eq described_class.for('02.07.2015')
|
16
|
+
expect(described_class.for('01.07.2015').next).to eq described_class.for('08.07.2015')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#previous" do
|
21
|
+
it "returns previous period" do
|
22
|
+
expect(described_class.for('25.06.2015').previous).to eq described_class.for('18.06.2015')
|
23
|
+
expect(described_class.for('01.07.2015').previous).to eq described_class.for('24.06.2015')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#days" do
|
28
|
+
it "returns days of period" do
|
29
|
+
expect(described_class.for("01.01.2015").days).to eq 7
|
30
|
+
expect(described_class.for("25.06.2015").days).to eq 7
|
31
|
+
expect(described_class.for("01.01.2016").days).to eq 7
|
32
|
+
expect(described_class.for("01.03.2016").days).to eq 7
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#include?" do
|
37
|
+
let(:period) { described_class.for('25.06.2015') }
|
38
|
+
|
39
|
+
context "date included" do
|
40
|
+
it "returns true" do
|
41
|
+
puts period
|
42
|
+
expect(period.include?('25.06.2015')).to be_truthy
|
43
|
+
expect(period.include?('01.07.2015')).to be_truthy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "date not included" do
|
48
|
+
it "returns false" do
|
49
|
+
expect(period.include?('24.06.2015')).to be_falsey
|
50
|
+
expect(period.include?('02.07.2015')).to be_falsey
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "period included" do
|
55
|
+
it "returns true" do
|
56
|
+
expect(period.include?(Period.new('25.06.2015', '25.06.2015'))).to be_truthy
|
57
|
+
expect(period.include?(Period.new('25.06.2015', '01.07.2015'))).to be_truthy
|
58
|
+
expect(period.include?(Period.new('26.06.2015', '01.07.2015'))).to be_truthy
|
59
|
+
expect(period.include?(Period.new('25.06.2015', '30.06.2015'))).to be_truthy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "period not included" do
|
64
|
+
it "returns false" do
|
65
|
+
expect(period.include?(Period.new('24.06.2015', '02.07.2015'))).to be_falsey
|
66
|
+
expect(period.include?(Period.new('25.06.2015', '02.07.2015'))).to be_falsey
|
67
|
+
expect(period.include?(Period.new('24.06.2015', '02.07.2015'))).to be_falsey
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Baustert
|
@@ -84,6 +84,8 @@ files:
|
|
84
84
|
- lib/periods/modules/quarter.rb
|
85
85
|
- lib/periods/modules/quarterly_period.rb
|
86
86
|
- lib/periods/modules/single_date_initialize.rb
|
87
|
+
- lib/periods/modules/week.rb
|
88
|
+
- lib/periods/modules/weekly_period.rb
|
87
89
|
- lib/periods/modules/year.rb
|
88
90
|
- lib/periods/modules/yearly_period.rb
|
89
91
|
- lib/periods/month.rb
|
@@ -93,6 +95,8 @@ files:
|
|
93
95
|
- lib/periods/quarter.rb
|
94
96
|
- lib/periods/quarterly_period.rb
|
95
97
|
- lib/periods/version.rb
|
98
|
+
- lib/periods/week.rb
|
99
|
+
- lib/periods/weekly_period.rb
|
96
100
|
- lib/periods/year.rb
|
97
101
|
- lib/periods/yearly_period.rb
|
98
102
|
- periods.gemspec
|
@@ -108,6 +112,7 @@ files:
|
|
108
112
|
- spec/lib/periods/date_calculator_spec.rb
|
109
113
|
- spec/lib/quarter_spec.rb
|
110
114
|
- spec/lib/quarterly_period_spec.rb
|
115
|
+
- spec/lib/weekly_period_spec.rb
|
111
116
|
- spec/lib/year_spec.rb
|
112
117
|
- spec/lib/yearly_period_spec.rb
|
113
118
|
- spec/spec_helper.rb
|
@@ -148,6 +153,7 @@ test_files:
|
|
148
153
|
- spec/lib/periods/date_calculator_spec.rb
|
149
154
|
- spec/lib/quarter_spec.rb
|
150
155
|
- spec/lib/quarterly_period_spec.rb
|
156
|
+
- spec/lib/weekly_period_spec.rb
|
151
157
|
- spec/lib/year_spec.rb
|
152
158
|
- spec/lib/yearly_period_spec.rb
|
153
159
|
- spec/spec_helper.rb
|