interpret_date 1.0.1 → 1.1.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/lib/interpret_date.rb +7 -0
- data/lib/interpret_date/version.rb +1 -1
- data/spec/interpret_date_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 761b3663c400c791352e4930bb3d4cce8cbdc4b4
|
4
|
+
data.tar.gz: 8d78cc3192b7b4dcd601e1a857affbd04f501c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ac81258a7c023b1ed9fd9de0f0ff9f96ccfd0f2a66d6f4eca0755b2187f35f5d11d8b543f7004194219a5f4930736021fae7c726b6194283e4455b0b42c28a
|
7
|
+
data.tar.gz: 793feddbc43b71c1c68510eea79d277b94662740a65261563cc4b829c5e4666ceee48b1a0cdbeec1354dfb9643c1a275fbb075cdeacfb5245cc726c12ca71d41
|
data/lib/interpret_date.rb
CHANGED
@@ -35,6 +35,8 @@ module InterpretDate
|
|
35
35
|
month = date_input[0,2].to_i
|
36
36
|
day = date_input[2,2].to_i
|
37
37
|
year = date_input[4,2].to_i
|
38
|
+
elsif db_formatted_date(date_input)
|
39
|
+
year, month, day = date_input.split("-").collect { |element| element.to_i }
|
38
40
|
elsif slash_based_date(date_input)
|
39
41
|
# Break the string apart using the delimiters '-', '/', and '.', making each element an integer
|
40
42
|
month, day, year = date_input.split(/[-\.\/]+/).collect { |element| element.to_i }
|
@@ -76,4 +78,9 @@ module InterpretDate
|
|
76
78
|
def slash_based_date(value)
|
77
79
|
/^\d{1,2}([-\.\/]+)\d{1,2}\1\d{2,4}$/ =~ value
|
78
80
|
end
|
81
|
+
|
82
|
+
# Example: 2017-01-01
|
83
|
+
def db_formatted_date(value)
|
84
|
+
/^\d{4}-\d{2}-\d{2}$/ =~ value
|
85
|
+
end
|
79
86
|
end
|
data/spec/interpret_date_spec.rb
CHANGED
@@ -53,6 +53,12 @@ RSpec.describe InterpretDate do
|
|
53
53
|
it "returns nil if the input passed in cannot be parsed into a date" do
|
54
54
|
expect(interpret_date("Kevin Bacon")).to eq(nil)
|
55
55
|
end
|
56
|
+
|
57
|
+
context "when the date is a db formatted string" do
|
58
|
+
it "interprets the string as a date" do
|
59
|
+
expect(interpret_date("2017-01-01")).to eql(Date.new(2017, 01, 01))
|
60
|
+
end
|
61
|
+
end
|
56
62
|
end
|
57
63
|
|
58
64
|
describe "#interpret_dob_date" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interpret_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Squaremouth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Mixin for easily parsing American formatted date strings into Date objects.
|