revs-utils 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmFjYTMzM2Y5Y2E0OWEzZGJlMzQ2OWVlMWRiYzBhNWNhMGUyYTQ0Mg==
4
+ ODAzOTc4MGRiMTU0NDExMTQ2NDA2MWRlMjhmZWViMDRhMWUyMDhjMQ==
5
5
  data.tar.gz: !binary |-
6
- MmZlOGYwNzE1MWNkM2U4OTVlMDk4MDdiOGJiNGQ5NDJlMTI4YzliYg==
6
+ Y2NmOGNiZDQwNjcyOTE2ZDEyNzgzOWQ3ODBjM2UyOGQxOTVhZDgyYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2RjNzRiNjkxNzMwZWY0M2MyZTkwOGU5YWZmZTU2OGJhMzUyY2E2MDdmMjc1
10
- ZWNmMzE2MmExMjI2NzZmMmU1MjFkZWVjMzE0Y2ZmZTI4OWZhN2VlMzg1Y2Q5
11
- ZWZiNTAyZDkxOGE5M2Y5NmE5ODMwOWEzOTRmNjViNTVjZmQxNjA=
9
+ ZDEwZDY1NTQ1MjRiY2E4YjIxNWMyNzIwN2U0OTc2ZjlmMGFiMTQwODVkNzQ0
10
+ YWNmYWY2NDI0ODU1OGQ1OTdjM2I2MmI1ZjY4ODBlYzZjNjY3NTNhNmE3Y2Zi
11
+ MzVhYWE1OWJmOTI3Nzg1ODk0MTVmMmVlYzc2MDExYmU4YWJiYTc=
12
12
  data.tar.gz: !binary |-
13
- NzljOGVhNGZmNWE2Mzk3ODUyNDNkY2QyNDM2NzJkNDM5M2Y2MTkyMGZhNzll
14
- YzdiMjdiOWVjY2QwYWJhMjE1YjQ3OTU4YmViZTMwYzUwMzE2NzllNmZiYTg1
15
- MDEwYWRiNDk4MDMzODE5MzU2ZDkwNTZiMTQ1ZDgzODhlNjg2Mzk=
13
+ ZjQ3NjBkNDhkMThlZmUxNTEwZTQxMWY4ODU4MjBmMTI1NzRiOGE0ODVlOWFi
14
+ ZTdjNzU1NDlhOGNmMDNhOWJhOTRhZDAyYjQ5OWI4MWM0MzlhODlkYzYyZTI2
15
+ YzVhM2I5ODM2ZjE3ZTgyZGMwOGRhODA5NDU1NGMxMDBlODhmYmY=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- revs-utils (2.0.4)
4
+ revs-utils (2.0.5)
5
5
  actionpack (~> 4.1.6)
6
6
  countries (= 0.9.2)
7
7
  rdf
data/README.rdoc CHANGED
@@ -18,10 +18,17 @@ Shared methods and functions used by revs-indexer, pre-assembly and bulk metadat
18
18
  - <b>1.0.6</b> Add some more conditions to CSV header checks
19
19
  - <b>1.0.7</b> Label column needs to be there but does not need to have a value to register
20
20
  - <b>1.0.8</b> Update clean_collection_name method to deal with other possible names
21
+ <<<<<<< HEAD
21
22
  - <b>2.0.0</b> Updating to use ActionPack 4 for Rails 4 applications. For Rails 3, continue to use 1.x.y releases.
22
23
  - <b>2.0.1</b> Add more common format corrections
23
24
  - <b>2.0.2 and 2.0.3</b> Update valid for metadata method so it is not sensitive to blank or uppercase columns
24
25
  - <b>2.0.4</b> Fix issues with year parsing
26
+ =======
27
+ - <b>1.0.9</b> Add more common format corrections
28
+ - <b>1.0.10</b> Update valid for metadata method so it is not sensitive to blank or uppercase columns
29
+ - <b>1.0.11</b> Fix issues with year parsing
30
+ - <b>1.0.12</b> Allow two digit years in year formatting
31
+ >>>>>>> 9db8640... Allow two digit years in year formatting
25
32
 
26
33
  == Running tests
27
34
 
@@ -1,5 +1,5 @@
1
1
  module Revs
2
2
  module Utils
3
- VERSION = "2.0.4"
3
+ VERSION = "2.0.5"
4
4
  end
5
5
  end
data/lib/revs-utils.rb CHANGED
@@ -235,11 +235,14 @@ module Revs
235
235
  date_string.to_s.strip.scan(/\D/).empty? and (starting_year..Date.today.year).include?(date_string.to_i)
236
236
  end
237
237
 
238
- # 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
238
+ # 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
239
239
  def get_full_date(date_string)
240
240
  begin
241
- date_obj=Date.strptime(date_string.gsub('-','/').delete(' '), '%m/%d/%Y')
242
- return (is_valid_year?(date_obj.year.to_s) ? date_obj : false)
241
+ date_obj_string=date_string.gsub('-','/').delete(' ')
242
+ 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
243
+ date_obj = Date.strptime(date_obj_string, date_format)
244
+ 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)
245
+ is_valid_year?(date_obj.year.to_s) ? date_obj : false
243
246
  rescue
244
247
  false
245
248
  end
@@ -75,10 +75,14 @@ describe "Revs-Utils" do
75
75
  end
76
76
 
77
77
  it "should indicate if a date is valid" do
78
- @revs.get_full_date('bogus').should be_falsey
79
78
  @revs.get_full_date('5/1/1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
80
79
  @revs.get_full_date('5-1-1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
81
- @revs.get_full_date('5-1-59').should be_falsey # two digit year is not allowed
80
+ @revs.get_full_date('5-1-2014').should == Date.strptime("5/1/2014", '%m/%d/%Y')
81
+ @revs.get_full_date('5-1-59').should == Date.strptime("5/1/1959", '%m/%d/%Y') # deal with two digit years ok too
82
+ @revs.get_full_date('1/1/71').should == Date.strptime("1/1/1971", '%m/%d/%Y') # deal with two digit years ok too
83
+ @revs.get_full_date('5-1-14').should == Date.strptime("5/1/2014", '%m/%d/%Y') # deal with two digit years ok too
84
+ @revs.get_full_date('5-1-21').should == Date.strptime("5/1/1921", '%m/%d/%Y') # deal with two digit years ok too
85
+ @revs.get_full_date('bogus').should be_falsey
82
86
  end
83
87
 
84
88
  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: 2.0.4
4
+ version: 2.0.5
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-21 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: countries