revs-utils 1.0.11 → 1.0.12
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 +8 -8
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -0
- data/lib/revs-utils/version.rb +1 -1
- data/lib/revs-utils.rb +6 -3
- data/spec/revs-utils_spec.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDRhNWEwYTJhYmIyOGVlM2E3YzEyYWFmYWRiYjE4Mzg2MjM2ZGI5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTM3MjNmMjY0MmY2NDA0MDhiYmJhYjM5YjQwYjAzODZhOTA4OTc1Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTc1ZjFhM2E2NzZkMjllMDg2MzRiOGI3ZmM4NmI5Mzk1Y2Y3NzU0ZDYyZmMz
|
10
|
+
ZDE3MWI0MGVhNTkxNTUwNDA3MmNjYmE3ZmQ2NjM1YTMwODkzMGZiNGVhYzVi
|
11
|
+
MGJiYjg2NDYxMDRiZDVkZDQzYmI1OTdiNTJhMDA0OGUxYTMwNDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjQ2ZGEwNDA0OWIzYjFjMDlmYWZiNDJjYWRhOGI0M2U4OWNlNzFlZjU3Mjhh
|
14
|
+
OTAzY2JjOGExNDMxOTM5MGNhMmIxOTRkMzliMmRhMDBlNzUwODgxZWVkZWRk
|
15
|
+
ZGNlZDE5ZDkxYmVhNmZiYWRkMjEwOTIwZjNlMGMzMTY0NDA5MGE=
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -21,6 +21,7 @@ Shared methods and functions used by revs-indexer, pre-assembly and bulk metadat
|
|
21
21
|
- <b>1.0.9</b> Add more common format corrections
|
22
22
|
- <b>1.0.10</b> Update valid for metadata method so it is not sensitive to blank or uppercase columns
|
23
23
|
- <b>1.0.11</b> Fix issues with year parsing
|
24
|
+
- <b>1.0.12</b> Allow two digit years in year formatting
|
24
25
|
|
25
26
|
== Running tests
|
26
27
|
|
data/lib/revs-utils/version.rb
CHANGED
data/lib/revs-utils.rb
CHANGED
@@ -236,11 +236,14 @@ module Revs
|
|
236
236
|
date_string.to_s.strip.scan(/\D/).empty? and (starting_year..Date.today.year).include?(date_string.to_i)
|
237
237
|
end
|
238
238
|
|
239
|
-
# tell us if the string passed is in is a full date of the format M/D/YYYY, and returns the date object if it is valid
|
239
|
+
# tell us if the string passed is in is a full date of the format M/D/YYYY or m-d-yyyy or m-d-yy or M/D/YY, and returns the date object if it is valid
|
240
240
|
def get_full_date(date_string)
|
241
241
|
begin
|
242
|
-
|
243
|
-
|
242
|
+
date_obj_string=date_string.gsub('-','/').delete(' ')
|
243
|
+
date_format = (date_obj_string.split('/').last.size == 4 ? '%m/%d/%Y' : '%m/%d/%y') # if we think we have a 4 digit year, parse with 4 year format, else try the two year format
|
244
|
+
date_obj = Date.strptime(date_obj_string, date_format)
|
245
|
+
date_obj=date_obj.prev_year(100) if date_obj > Date.today # if the parsing yields a date in the future, this is a problem, so adjust back a century (due to this issue: http://stackoverflow.com/questions/27058068/ruby-incorrectly-parses-2-digit-year)
|
246
|
+
is_valid_year?(date_obj.year.to_s) ? date_obj : false
|
244
247
|
rescue
|
245
248
|
false
|
246
249
|
end
|
data/spec/revs-utils_spec.rb
CHANGED
@@ -76,10 +76,14 @@ describe "Revs-Utils" do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should indicate if a date is valid" do
|
79
|
-
@revs.get_full_date('bogus').should be_false
|
80
79
|
@revs.get_full_date('5/1/1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
|
81
80
|
@revs.get_full_date('5-1-1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
|
82
|
-
@revs.get_full_date('5-1-
|
81
|
+
@revs.get_full_date('5-1-2014').should == Date.strptime("5/1/2014", '%m/%d/%Y')
|
82
|
+
@revs.get_full_date('5-1-59').should == Date.strptime("5/1/1959", '%m/%d/%Y') # deal with two digit years ok too
|
83
|
+
@revs.get_full_date('1/1/71').should == Date.strptime("1/1/1971", '%m/%d/%Y') # deal with two digit years ok too
|
84
|
+
@revs.get_full_date('5-1-14').should == Date.strptime("5/1/2014", '%m/%d/%Y') # deal with two digit years ok too
|
85
|
+
@revs.get_full_date('5-1-21').should == Date.strptime("5/1/1921", '%m/%d/%Y') # deal with two digit years ok too
|
86
|
+
@revs.get_full_date('bogus').should be_false
|
83
87
|
end
|
84
88
|
|
85
89
|
it "should indicate if we have a valid year" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revs-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: countries
|