fat_core 1.2.8 → 1.3.0
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/.gitignore +1 -0
- data/lib/fat_core/date.rb +13 -6
- data/lib/fat_core/version.rb +2 -2
- data/spec/lib/date_spec.rb +20 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49d7213a1c1d8f0372f9a5f0e057dec4a194e541
|
4
|
+
data.tar.gz: 6f8ee1ddc0bfb0e8b66247453e2f4c11fc51d0d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 074407a3a3e4b7885d841b8fe351c18fd03d001620058e9364129fe82f995d3e25554c4b3c2bb364851e006faa95778929bc7342d7799ed8d8c10956421fb64f
|
7
|
+
data.tar.gz: 4d0d70cfc49d8f1152db707a8eb43672d5fcf1586f088e41646a3f33f2d49c2634c15d5944246624a80bc325e277559a960e5e9840077804d4296f2ba1b00d61
|
data/.gitignore
CHANGED
data/lib/fat_core/date.rb
CHANGED
@@ -65,8 +65,8 @@ class Date
|
|
65
65
|
end
|
66
66
|
|
67
67
|
today = Date.current
|
68
|
-
case spec
|
69
|
-
when
|
68
|
+
case spec.clean
|
69
|
+
when /\A(\d\d\d\d)[-\/](\d\d?)[-\/](\d\d?)\z/
|
70
70
|
# A specified date
|
71
71
|
Date.new($1.to_i, $2.to_i, $3.to_i)
|
72
72
|
when /\AW(\d\d?)\z/, /\A(\d\d?)W\z/
|
@@ -79,7 +79,7 @@ class Date
|
|
79
79
|
else
|
80
80
|
Date.commercial(today.year, week_num).end_of_week
|
81
81
|
end
|
82
|
-
when /\A(\d\d\d\d)
|
82
|
+
when /\A(\d\d\d\d)[-\/]W(\d\d?)\z/, /\A(\d\d\d\d)[-\/](\d\d?)W\z/
|
83
83
|
year = $1.to_i
|
84
84
|
week_num = $2.to_i
|
85
85
|
if week_num < 1 || week_num > 53
|
@@ -90,7 +90,7 @@ class Date
|
|
90
90
|
else
|
91
91
|
Date.commercial(year, week_num).end_of_week
|
92
92
|
end
|
93
|
-
when /^(\d\d\d\d)
|
93
|
+
when /^(\d\d\d\d)[-\/](\d)[Qq]$/, /^(\d\d\d\d)[-\/][Qq](\d)$/
|
94
94
|
# Year-Quarter
|
95
95
|
year = $1.to_i
|
96
96
|
quarter = $2.to_i
|
@@ -113,7 +113,7 @@ class Date
|
|
113
113
|
else
|
114
114
|
date.end_of_quarter
|
115
115
|
end
|
116
|
-
when /^(\d\d\d\d)
|
116
|
+
when /^(\d\d\d\d)[-\/](\d)[Hh]$/, /^(\d\d\d\d)[-\/][Hh](\d)$/
|
117
117
|
# Year-Half
|
118
118
|
year = $1.to_i
|
119
119
|
half = $2.to_i
|
@@ -136,13 +136,20 @@ class Date
|
|
136
136
|
else
|
137
137
|
date.end_of_half
|
138
138
|
end
|
139
|
-
when /^(\d\d\d\d)
|
139
|
+
when /^(\d\d\d\d)[-\/](\d\d?)*$/
|
140
140
|
# Year-Month only
|
141
141
|
if spec_type == :from
|
142
142
|
Date.new($1.to_i, $2.to_i, 1)
|
143
143
|
else
|
144
144
|
Date.new($1.to_i, $2.to_i, 1).end_of_month
|
145
145
|
end
|
146
|
+
when /^(\d\d?)[-\/](\d\d?)*$/
|
147
|
+
# Month-Day only
|
148
|
+
if spec_type == :from
|
149
|
+
Date.new(today.year, $1.to_i, $2.to_i)
|
150
|
+
else
|
151
|
+
Date.new(today.year, $1.to_i, $2.to_i).end_of_month
|
152
|
+
end
|
146
153
|
when /\A(\d\d?)\z/
|
147
154
|
# Month only
|
148
155
|
if spec_type == :from
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/date_spec.rb
CHANGED
@@ -211,7 +211,7 @@ describe Date do
|
|
211
211
|
|
212
212
|
it 'should parse plain iso dates correctly' do
|
213
213
|
expect(Date.parse_spec('2011-07-15')).to eq Date.parse('2011-07-15')
|
214
|
-
expect(Date.parse_spec('2011
|
214
|
+
expect(Date.parse_spec('2011/08/05')).to eq Date.parse('2011-08-05')
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should parse week numbers such as 'W23' or '23W' correctly" do
|
@@ -231,7 +231,7 @@ describe Date do
|
|
231
231
|
expect(Date.parse_spec('2003-W23')).to eq Date.parse('2003-06-02')
|
232
232
|
expect(Date.parse_spec('2003-W23', :to)).to eq Date.parse('2003-06-08')
|
233
233
|
expect(Date.parse_spec('2003-23W')).to eq Date.parse('2003-06-02')
|
234
|
-
expect(Date.parse_spec('2003
|
234
|
+
expect(Date.parse_spec('2003/23W', :to)).to eq Date.parse('2003-06-08')
|
235
235
|
expect {
|
236
236
|
Date.parse_spec('2003-W83', :to)
|
237
237
|
}.to raise_error(ArgumentError)
|
@@ -241,7 +241,7 @@ describe Date do
|
|
241
241
|
expect(Date.parse_spec('2011-2H', :from)).to eq Date.parse('2011-07-01')
|
242
242
|
expect(Date.parse_spec('2011-2H', :to)).to eq Date.parse('2011-12-31')
|
243
243
|
expect(Date.parse_spec('2011-H1', :from)).to eq Date.parse('2011-01-01')
|
244
|
-
expect(Date.parse_spec('2011
|
244
|
+
expect(Date.parse_spec('2011/H1', :to)).to eq Date.parse('2011-06-30')
|
245
245
|
expect { Date.parse_spec('2011-3H') }.to raise_error(ArgumentError)
|
246
246
|
end
|
247
247
|
|
@@ -257,7 +257,7 @@ describe Date do
|
|
257
257
|
expect(Date.parse_spec('2011-4Q', :from)).to eq Date.parse('2011-10-01')
|
258
258
|
expect(Date.parse_spec('2011-4Q', :to)).to eq Date.parse('2011-12-31')
|
259
259
|
expect(Date.parse_spec('2011-Q4', :from)).to eq Date.parse('2011-10-01')
|
260
|
-
expect(Date.parse_spec('2011
|
260
|
+
expect(Date.parse_spec('2011/Q4', :to)).to eq Date.parse('2011-12-31')
|
261
261
|
expect { Date.parse_spec('2011-5Q') }.to raise_error(ArgumentError)
|
262
262
|
end
|
263
263
|
|
@@ -271,7 +271,7 @@ describe Date do
|
|
271
271
|
|
272
272
|
it 'should parse year-month specs such as YYYY-MM' do
|
273
273
|
expect(Date.parse_spec('2010-5', :from)).to eq Date.parse('2010-05-01')
|
274
|
-
expect(Date.parse_spec('2010
|
274
|
+
expect(Date.parse_spec('2010/5', :to)).to eq Date.parse('2010-05-31')
|
275
275
|
expect { Date.parse_spec('2010-13') }.to raise_error(ArgumentError)
|
276
276
|
end
|
277
277
|
|
@@ -282,6 +282,21 @@ describe Date do
|
|
282
282
|
expect { Date.parse_spec('011') }.to raise_error(ArgumentError)
|
283
283
|
end
|
284
284
|
|
285
|
+
it 'should parse month-day specs such as MM-DD' do
|
286
|
+
expect(Date.parse_spec('10-12', :from)).to eq Date.parse('2012-10-12')
|
287
|
+
expect(Date.parse_spec('10-2', :from)).to eq Date.parse('2012-10-02')
|
288
|
+
expect(Date.parse_spec('5-12', :from)).to eq Date.parse('2012-05-12')
|
289
|
+
expect(Date.parse_spec('5-2', :from)).to eq Date.parse('2012-05-02')
|
290
|
+
expect(Date.parse_spec('10/12', :from)).to eq Date.parse('2012-10-12')
|
291
|
+
expect(Date.parse_spec('10/2', :from)).to eq Date.parse('2012-10-02')
|
292
|
+
expect(Date.parse_spec('5/12', :from)).to eq Date.parse('2012-05-12')
|
293
|
+
expect(Date.parse_spec('5/2', :from)).to eq Date.parse('2012-05-02')
|
294
|
+
expect { Date.parse_spec('99-3') }.to raise_error(ArgumentError)
|
295
|
+
expect { Date.parse_spec('3-33') }.to raise_error(ArgumentError)
|
296
|
+
expect { Date.parse_spec('99/3') }.to raise_error(ArgumentError)
|
297
|
+
expect { Date.parse_spec('3/33') }.to raise_error(ArgumentError)
|
298
|
+
end
|
299
|
+
|
285
300
|
it 'should parse year-only specs such as YYYY' do
|
286
301
|
expect(Date.parse_spec('2010', :from)).to eq Date.parse('2010-01-01')
|
287
302
|
expect(Date.parse_spec('2010', :to)).to eq Date.parse('2010-12-31')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|