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