revs-utils 1.0.13 → 1.0.14
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/lib/revs-utils.rb +1 -0
- data/lib/revs-utils/version.rb +1 -1
- data/spec/revs-utils_spec.rb +21 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWQyNzQ0ZDdhYmMzZmY3OTRiOGQ4MDAwYjJmODhmOTlkNDYwOGI0Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDNjMjY4NjExMzBlODMzZDc5MzgzOWE4YWRlNzBmODhiMWRlZmQ1Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDRhYjMwYjFlYWMzNWZjMGZkYzBjMzg5ZWU2NmY3NjI3YzNmNDI2ZjhlNTdl
|
10
|
+
MTE5MmEzYzVlZTliMzQ1NTA2MDU4MTkyNTAyZjU5NmNmNTZmZDkwZjk5MTYx
|
11
|
+
NWRkYTRmYmZiNmQyZTZkZDU1Y2UwMjczMDBiNDYxOTc2MjMxYzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWFhYjRkNTYwZDI3Y2JjMDQ2YTVkMDI2NzEwZTFjYTM0ZTc3MTQzOGYxNWMw
|
14
|
+
ODZjZDIxNzU4ODFlYzBmOTkyZjIwNDA0Y2UwNzg0YThjMGEyNjc3MmMzZWVm
|
15
|
+
YjBiYmUzOWI4OTc5YmE5N2ZhMzAzMzAwMDc5YzhlNWM5Y2U4YWE=
|
data/Gemfile.lock
CHANGED
data/lib/revs-utils.rb
CHANGED
@@ -240,6 +240,7 @@ module Revs
|
|
240
240
|
# 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
|
241
241
|
def get_full_date(date_string)
|
242
242
|
begin
|
243
|
+
return false if date_string.scan(/(-|\/)/).count < 2 # we need at least two / or - characters to count as a full date
|
243
244
|
date_obj=Chronic.parse(date_string).to_date
|
244
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)
|
245
246
|
is_valid_year?(date_obj.year.to_s) ? date_obj : false
|
data/lib/revs-utils/version.rb
CHANGED
data/spec/revs-utils_spec.rb
CHANGED
@@ -76,17 +76,30 @@ describe "Revs-Utils" do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should indicate if a date is valid" do
|
79
|
+
|
80
|
+
# formats that are ok
|
79
81
|
@revs.get_full_date('5/1/1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
|
80
82
|
@revs.get_full_date('5-1-1959').should == Date.strptime("5/1/1959", '%m/%d/%Y')
|
81
83
|
@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')
|
83
|
-
@revs.get_full_date('1/1/71').should == Date.strptime("1/1/1971", '%m/%d/%Y')
|
84
|
-
@revs.get_full_date('5-1-14').should == Date.strptime("5/1/2014", '%m/%d/%Y')
|
85
|
-
@revs.get_full_date('5-1-21').should == Date.strptime("5/1/1921", '%m/%d/%Y')
|
86
|
-
@revs.get_full_date('1966-02-27').should == Date.strptime("2/27/1966", '%m/%d/%Y')
|
87
|
-
@revs.get_full_date('1966-2-5').should == Date.strptime("2/5/1966", '%m/%d/%Y')
|
88
|
-
|
89
|
-
|
84
|
+
@revs.get_full_date('5-1-59').should == Date.strptime("5/1/1959", '%m/%d/%Y')
|
85
|
+
@revs.get_full_date('1/1/71').should == Date.strptime("1/1/1971", '%m/%d/%Y')
|
86
|
+
@revs.get_full_date('5-1-14').should == Date.strptime("5/1/2014", '%m/%d/%Y')
|
87
|
+
@revs.get_full_date('5-1-21').should == Date.strptime("5/1/1921", '%m/%d/%Y')
|
88
|
+
@revs.get_full_date('1966-02-27').should == Date.strptime("2/27/1966", '%m/%d/%Y')
|
89
|
+
@revs.get_full_date('1966-2-5').should == Date.strptime("2/5/1966", '%m/%d/%Y')
|
90
|
+
|
91
|
+
# bad full dates
|
92
|
+
@revs.get_full_date('1966-14-11').should be_false # bad month
|
93
|
+
@revs.get_full_date('1966\4\11').should be_false # slashes are the wrong way
|
94
|
+
@revs.get_full_date('bogus').should be_false # crap string
|
95
|
+
@revs.get_full_date('').should be_false # blank
|
96
|
+
@revs.get_full_date('1965').should be_false # only the year
|
97
|
+
@revs.get_full_date('1965-68').should be_false # range of years
|
98
|
+
@revs.get_full_date('1965,1968').should be_false # multiple years
|
99
|
+
@revs.get_full_date('1965|1968').should be_false # multiple years
|
100
|
+
@revs.get_full_date('1965-1968').should be_false # multiple years
|
101
|
+
@revs.get_full_date('1965-8').should be_false # multiple years
|
102
|
+
|
90
103
|
end
|
91
104
|
|
92
105
|
it "should indicate if we have a valid year" do
|