periods 0.0.6 → 0.0.7
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 +1 -1
- data/lib/periods/modules/halfyearly_period.rb +1 -0
- data/lib/periods/modules/month.rb +4 -3
- data/lib/periods/modules/period.rb +92 -0
- data/lib/periods/modules/quarterly_period.rb +1 -0
- data/lib/periods/modules/yearly_period.rb +1 -0
- data/lib/periods/version.rb +1 -1
- data/spec/lib/halfyear_spec.rb +0 -1
- data/spec/lib/halfyearly_period_spec.rb +0 -1
- data/spec/lib/january_spec.rb +0 -2
- data/spec/lib/month_spec.rb +26 -1
- data/spec/lib/monthly_period_spec.rb +0 -1
- data/spec/lib/period_spec.rb +45 -4
- data/spec/lib/quarter_spec.rb +0 -1
- data/spec/lib/quarterly_period_spec.rb +0 -1
- data/spec/lib/year_spec.rb +0 -1
- data/spec/lib/yearly_period_spec.rb +0 -1
- data/spec/spec_helper.rb +36 -3
- metadata +3 -5
- data/spec/lint_check.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 157af8429236011f6b5d28c43df6a6c6fd96156e
|
4
|
+
data.tar.gz: 80a7b74aa78c8e08b39a41e7e1c505a748162d40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d702a50cef9515c488948d02537cf912e7694704a832b72b62e62836b86f7092bf560f4f97011444ae7582e3f127a9a82f92b3b4fe45f3b32f234a0f259fe20
|
7
|
+
data.tar.gz: 1fa325d6fb372e852759ff8cc341a0d7aaeb6ec1fcb67f9f998adc22aada49e42b4fa7cb93eb2cee355abaf7e9c82240bf381e6b077cee91e58344695f2460ca
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ If you need a constant monthly range use `MonthlyPeriod`:
|
|
111
111
|
|
112
112
|
If you need a calendar month starting at first day of month and ending at last day of month use `Month`:
|
113
113
|
|
114
|
-
june =
|
114
|
+
june = Month.for('25.06.2015') # => 01.06.2015 - 30.06.2015
|
115
115
|
june.next # => 01.07.2015 - 31.07.2015
|
116
116
|
june.previous # => 01.05.2015 - 31.05.2015
|
117
117
|
june.month # => 6
|
@@ -9,6 +9,7 @@ module Periods
|
|
9
9
|
base.class_eval do
|
10
10
|
include Periods::Modules::MonthlyPeriod
|
11
11
|
include InstanceMethods
|
12
|
+
alias_method :succ, :next
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -25,10 +26,10 @@ module Periods
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def to_s(*args)
|
28
|
-
if args.first.to_s == '
|
29
|
-
"#{start_date.strftime("%m.%Y")} (#{start_date.strftime("%d.%m.%Y")} - #{end_date.strftime("%d.%m.%Y")})"
|
30
|
-
else
|
29
|
+
if args.first.to_s == 'month'
|
31
30
|
"#{start_date.strftime("%m.%Y")}"
|
31
|
+
else
|
32
|
+
super
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -205,6 +205,98 @@ module Periods
|
|
205
205
|
"#{start_date.strftime("%d.%m.%Y")} - #{end_date.strftime("%d.%m.%Y")}"
|
206
206
|
end
|
207
207
|
|
208
|
+
##
|
209
|
+
# Returns the months included in this period including the month of the start and end date
|
210
|
+
# of this period.
|
211
|
+
#
|
212
|
+
# @return [Month] an array of months included in this period.
|
213
|
+
#
|
214
|
+
# @since 0.0.7
|
215
|
+
#
|
216
|
+
# @example
|
217
|
+
#
|
218
|
+
# Period.new('01.01.2015', '31.12.2015').months # => Jan, Feb, ..., Dec
|
219
|
+
# Period.new('17.04.2015', '26.08.2015').months # => Apr, Mai, Jun, Jul, Aug
|
220
|
+
#
|
221
|
+
def months
|
222
|
+
(Periods::Month.for(start_date)..Periods::Month.for(end_date)).to_a
|
223
|
+
end
|
224
|
+
|
225
|
+
##
|
226
|
+
# Returns the quarters included in this period including the quarter of the start date
|
227
|
+
# of this period. The quarter of the end date of this period is only included if the
|
228
|
+
# quarter's end date is before/equal the end date of this period.
|
229
|
+
#
|
230
|
+
# @return [Quarter] an array of quarters included in this period.
|
231
|
+
#
|
232
|
+
# @since 0.0.7
|
233
|
+
#
|
234
|
+
# @example
|
235
|
+
#
|
236
|
+
# Period.new('01.01.2015', '31.12.2015').quarters # => [(J,F,M),(A,M,J),(J,A,S),(O,N,D)]
|
237
|
+
# Period.new('17.04.2015', '26.08.2015').quarters # => [(A,M,J) but not (J,A,S)]
|
238
|
+
#
|
239
|
+
def quarters
|
240
|
+
quarters = []
|
241
|
+
quarter = Periods::Quarter.for(start_date)
|
242
|
+
while quarter.end_date <= end_date
|
243
|
+
quarters << quarter
|
244
|
+
quarter = quarter.next
|
245
|
+
end
|
246
|
+
quarters
|
247
|
+
end
|
248
|
+
|
249
|
+
##
|
250
|
+
# Returns the halfyears included in this period including the halfyear of the start date
|
251
|
+
# of this period. The halfyear of the end date of this period is only included if the
|
252
|
+
# halfyear's end date is before/equal the end date of this period.
|
253
|
+
#
|
254
|
+
# @return [Halfyear] an array of halfyears included in this period.
|
255
|
+
#
|
256
|
+
# @since 0.0.7
|
257
|
+
#
|
258
|
+
# @example
|
259
|
+
#
|
260
|
+
# Period.new('01.01.2015', '31.12.2015').halfyears # => [(Jan-Jun),(Jul-Dec)]
|
261
|
+
# Period.new('17.04.2015', '26.08.2015').halfyears # => []
|
262
|
+
# Period.new('01.01.2015', '31.05.2016').halfyears # => [(Jan-Jun),(Jul-Dec)]
|
263
|
+
# Period.new('01.01.2015', '30.06.2016').halfyears # => [(Jan-Jun),(Jul-Dec),(Jan-Jun)]
|
264
|
+
#
|
265
|
+
def halfyears
|
266
|
+
halfyears = []
|
267
|
+
halfyear = Periods::Halfyear.for(start_date)
|
268
|
+
while halfyear.end_date <= end_date
|
269
|
+
halfyears << halfyear
|
270
|
+
halfyear = halfyear.next
|
271
|
+
end
|
272
|
+
halfyears
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Returns the years included in this period including the year of the start date
|
277
|
+
# of this period. The year of the end date of this period is only included if the
|
278
|
+
# year's end date is before/equal the end date of this period.
|
279
|
+
#
|
280
|
+
# @return [Year] an array of halfyears included in this period.
|
281
|
+
#
|
282
|
+
# @since 0.0.7
|
283
|
+
#
|
284
|
+
# @example
|
285
|
+
#
|
286
|
+
# Period.new('01.01.2015', '31.12.2015').halfyears # => [(Jan-Dec)]
|
287
|
+
# Period.new('17.04.2015', '26.08.2015').halfyears # => []
|
288
|
+
# Period.new('01.01.2015', '31.05.2016').halfyears # => [(Jan-Dec)]
|
289
|
+
# Period.new('01.01.2015', '31.12.2016').halfyears # => [(Jan-Dec),(Jan-Dec)]
|
290
|
+
#
|
291
|
+
def years
|
292
|
+
years = []
|
293
|
+
year = Periods::Year.for(start_date)
|
294
|
+
while year.end_date <= end_date
|
295
|
+
years << year
|
296
|
+
year = year.next
|
297
|
+
end
|
298
|
+
years
|
299
|
+
end
|
208
300
|
end
|
209
301
|
end
|
210
302
|
end
|
data/lib/periods/version.rb
CHANGED
data/spec/lib/halfyear_spec.rb
CHANGED
data/spec/lib/january_spec.rb
CHANGED
data/spec/lib/month_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe Month do
|
|
6
6
|
|
7
7
|
let(:subject) { described_class.for("1.1.2015") }
|
8
8
|
|
9
|
-
it_behaves_like "Lint Check"
|
10
9
|
it_behaves_like "Initialized by single date" do
|
11
10
|
let(:period) { described_class.for(Date.new(2015,6,25)) }
|
12
11
|
end
|
@@ -50,4 +49,30 @@ describe Month do
|
|
50
49
|
expect(described_class.for('01.01.2014').year).to eq 2014
|
51
50
|
end
|
52
51
|
end
|
52
|
+
|
53
|
+
describe "#to_s" do
|
54
|
+
context "nothing passed" do
|
55
|
+
it "returns period" do
|
56
|
+
expect(described_class.for('01.03.2015').to_s).to eq "01.03.2015 - 31.03.2015"
|
57
|
+
expect(described_class.for('01.06.2015').to_s).to eq "01.06.2015 - 30.06.2015"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context ":month passed" do
|
62
|
+
it "returns month.year" do
|
63
|
+
expect(described_class.for('01.01.2015').to_s(:month)).to eq "01.2015"
|
64
|
+
expect(described_class.for('01.06.2015').to_s(:month)).to eq "06.2015"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "Range" do
|
70
|
+
it "works" do
|
71
|
+
expect((Month.for("01.01.2015")..Month.for("31.01.2015")).to_a).to eq new_months("01.01.2015", 1)
|
72
|
+
expect((Month.for("01.01.2015")..Month.for("28.02.2015")).to_a).to eq new_months("01.01.2015", 2)
|
73
|
+
expect((Month.for("01.01.2015")..Month.for("26.08.2015")).to_a).to eq new_months("01.01.2015", 8)
|
74
|
+
expect((Month.for("01.01.2015")..Month.for("31.12.2015")).to_a).to eq new_months("01.01.2015", 12)
|
75
|
+
expect((Month.for("01.01.2015")..Month.for("31.05.2016")).to_a).to eq new_months("01.01.2015", 17)
|
76
|
+
end
|
77
|
+
end
|
53
78
|
end
|
data/spec/lib/period_spec.rb
CHANGED
@@ -3,10 +3,6 @@ require 'periods/constants'
|
|
3
3
|
|
4
4
|
describe Period do
|
5
5
|
|
6
|
-
def new_period(start_date, end_date)
|
7
|
-
described_class.new(start_date, end_date)
|
8
|
-
end
|
9
|
-
|
10
6
|
describe ".new" do
|
11
7
|
it "accepts Date" do
|
12
8
|
period = described_class.new(Date.new(2015,6,25), Date.new(2016,5,20))
|
@@ -142,6 +138,51 @@ describe Period do
|
|
142
138
|
end
|
143
139
|
end
|
144
140
|
end
|
141
|
+
|
142
|
+
describe "#to_s" do
|
143
|
+
it "returns period" do
|
144
|
+
expect(new_period("09.04.2015", "20.05.2015").to_s).to eq "09.04.2015 - 20.05.2015"
|
145
|
+
expect(new_period("26.06.2014", "10.09.2015").to_s).to eq "26.06.2014 - 10.09.2015"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#months" do
|
150
|
+
it "returns months included period" do
|
151
|
+
expect(new_period("01.01.2015", "31.12.2015").months).to eq new_months("01.01.2015", 12)
|
152
|
+
expect(new_period("17.04.2015", "26.08.2015").months).to eq new_months("01.04.2015", 5)
|
153
|
+
expect(new_period("01.01.2015", "31.05.2016").months).to eq new_months("01.01.2015", 17)
|
154
|
+
expect(new_period("08.02.2015", "09.02.2015").months).to eq new_months("01.02.2015", 1)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#quarters" do
|
159
|
+
it "returns quarters included period" do
|
160
|
+
expect(new_period("01.01.2015", "31.12.2015").quarters).to eq new_quarters("01.01.2015", 4)
|
161
|
+
expect(new_period("17.04.2015", "26.08.2015").quarters).to eq new_quarters("01.04.2015", 1)
|
162
|
+
expect(new_period("17.04.2015", "31.05.2015").quarters).to eq []
|
163
|
+
expect(new_period("01.01.2015", "31.05.2016").quarters).to eq new_quarters("01.01.2015", 5)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#halfyears" do
|
168
|
+
it "returns halfyears included period" do
|
169
|
+
expect(new_period("01.01.2015", "31.12.2015").halfyears).to eq new_halfyears("01.01.2015", 2)
|
170
|
+
expect(new_period("17.04.2015", "26.08.2015").halfyears).to eq []
|
171
|
+
expect(new_period("01.01.2015", "31.05.2016").halfyears).to eq new_halfyears("01.01.2015", 2)
|
172
|
+
expect(new_period("01.01.2015", "30.06.2016").halfyears).to eq new_halfyears("01.01.2015", 3)
|
173
|
+
expect(new_period("01.01.2015", "20.07.2016").halfyears).to eq new_halfyears("01.01.2015", 3)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#years" do
|
178
|
+
it "returns years included period" do
|
179
|
+
expect(new_period("01.01.2015", "31.12.2015").years).to eq [Periods::Year.for("01.01.2015")]
|
180
|
+
expect(new_period("17.04.2015", "26.08.2015").years).to eq []
|
181
|
+
expect(new_period("01.01.2015", "31.05.2016").years).to eq [Periods::Year.for("01.01.2015")]
|
182
|
+
expect(new_period("01.01.2015", "30.06.2016").years).to eq [Periods::Year.for("01.01.2015")]
|
183
|
+
expect(new_period("01.01.2015", "31.12.2016").years).to eq [Periods::Year.for("01.01.2015"), Periods::Year.for("01.01.2016")]
|
184
|
+
end
|
185
|
+
end
|
145
186
|
end
|
146
187
|
|
147
188
|
|
data/spec/lib/quarter_spec.rb
CHANGED
data/spec/lib/year_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'lint_check'
|
2
|
-
|
3
1
|
RSpec.configure do |config|
|
4
2
|
# rspec-expectations config goes here. You can use an alternate
|
5
3
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
@@ -76,4 +74,39 @@ end
|
|
76
74
|
|
77
75
|
def Date(date)
|
78
76
|
Date.parse(date.to_s)
|
79
|
-
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def new_period(start_date, end_date)
|
80
|
+
described_class.new(start_date, end_date)
|
81
|
+
end
|
82
|
+
|
83
|
+
def new_months(start_date, count)
|
84
|
+
months = [Periods::Month.for(start_date)]
|
85
|
+
month = months.first.next
|
86
|
+
2.upto(count) do |idx|
|
87
|
+
months << month
|
88
|
+
month = month.next
|
89
|
+
end
|
90
|
+
months
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_quarters(start_date, count)
|
94
|
+
quarters = [Periods::Quarter.for(start_date)]
|
95
|
+
quarter = quarters.first.next
|
96
|
+
2.upto(count) do |idx|
|
97
|
+
quarters << quarter
|
98
|
+
quarter = quarter.next
|
99
|
+
end
|
100
|
+
quarters
|
101
|
+
end
|
102
|
+
|
103
|
+
def new_halfyears(start_date, count)
|
104
|
+
halfyears = [Periods::Halfyear.for(start_date)]
|
105
|
+
halfyear = halfyears.first.next
|
106
|
+
2.upto(count) do |idx|
|
107
|
+
halfyears << halfyear
|
108
|
+
halfyear = halfyear.next
|
109
|
+
end
|
110
|
+
halfyears
|
111
|
+
end
|
112
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Baustert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,6 @@ files:
|
|
110
110
|
- spec/lib/quarterly_period_spec.rb
|
111
111
|
- spec/lib/year_spec.rb
|
112
112
|
- spec/lib/yearly_period_spec.rb
|
113
|
-
- spec/lint_check.rb
|
114
113
|
- spec/spec_helper.rb
|
115
114
|
homepage: https://github.com/thomasbaustert/periods
|
116
115
|
licenses:
|
@@ -132,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
131
|
version: '0'
|
133
132
|
requirements: []
|
134
133
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.4.
|
134
|
+
rubygems_version: 2.4.8
|
136
135
|
signing_key:
|
137
136
|
specification_version: 4
|
138
137
|
summary: Simple period types like Week, Month, Quarter, Halfyear, Year.
|
@@ -151,5 +150,4 @@ test_files:
|
|
151
150
|
- spec/lib/quarterly_period_spec.rb
|
152
151
|
- spec/lib/year_spec.rb
|
153
152
|
- spec/lib/yearly_period_spec.rb
|
154
|
-
- spec/lint_check.rb
|
155
153
|
- spec/spec_helper.rb
|
data/spec/lint_check.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
shared_examples "Lint Check" do
|
2
|
-
|
3
|
-
it "respond #next" do
|
4
|
-
expect(subject).to respond_to(:next)
|
5
|
-
end
|
6
|
-
|
7
|
-
it "respond #previous" do
|
8
|
-
expect(subject).to respond_to(:previous)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "respond #days" do
|
12
|
-
expect(subject).to respond_to(:days)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "respond #include?" do
|
16
|
-
expect(subject).to respond_to(:include?)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "is Comparable" do
|
20
|
-
expect(subject).to be_kind_of(Comparable)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|