timelord 0.0.10 → 0.0.11
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/README.md +1 -1
- data/lib/timelord.rb +1 -1
- data/lib/timelord/matchers/year_last_matcher.rb +13 -2
- data/spec/timelord_spec.rb +5 -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: 60169c613d4bfbc330e87f3bd81f39bd07c1a7cc
|
4
|
+
data.tar.gz: 184555c3231a91a8a3057dacfb1fa527fc176967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baf409a8ef5a0dcd8a42683bf2e52f9c9b8d811f29cf7eb326cc30d04a2ce4b06cfe3231e5ff87a0589ed4ded915c79384b3f410a851364a5d0f2268a0996aa5
|
7
|
+
data.tar.gz: 732b6c734a74ee0a40cf638f92ea4fceecbef9c9a7471012153b4b2dcbae48cab1be6302648d1f387429a101b287136d287a710c5808333693a55b7d4d3f7663
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ To use the american date format pass in :american as the second parameter
|
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
Timelord.parse("11/01").to_s # "2011-01-11"
|
27
|
-
Timelord.parse("11/01", :american) # "2011-11-01"
|
27
|
+
Timelord.parse("11/01", format: :american) # "2011-11-01"
|
28
28
|
```
|
29
29
|
|
30
30
|
## In the future
|
data/lib/timelord.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
module Timelord
|
2
2
|
class YearLastMatcher < Matcher
|
3
3
|
REGEX = /\b(\d{1,2})\/(\d{1,2})\/(\d{2}(\d{2})?)\b/i
|
4
|
+
CURRENT_PREFIX = 2000
|
4
5
|
|
5
6
|
def to_date
|
6
7
|
if format == :american
|
7
|
-
Date.civil(match[3]
|
8
|
+
Date.civil(to_year(match[3]), match[1].to_i, match[2].to_i)
|
8
9
|
else
|
9
|
-
Date.civil(match[3]
|
10
|
+
Date.civil(to_year(match[3]), match[2].to_i, match[1].to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def to_year(year_number)
|
17
|
+
if year_number.length == 2
|
18
|
+
CURRENT_PREFIX + year_number.to_i
|
19
|
+
else
|
20
|
+
year_number.to_i
|
10
21
|
end
|
11
22
|
end
|
12
23
|
end
|
data/spec/timelord_spec.rb
CHANGED
@@ -128,6 +128,11 @@ describe Timelord, 'parse' do
|
|
128
128
|
Timelord.parse("March 1 I need to do stuff.").should == first_of_march
|
129
129
|
end
|
130
130
|
|
131
|
+
it 'parses mm/dd/yy correctly' do
|
132
|
+
oct_12 = Date.civil(2015, 10, 12)
|
133
|
+
Timelord.parse("Stuff 10/12/15", format: :american).should == oct_12
|
134
|
+
end
|
135
|
+
|
131
136
|
after do
|
132
137
|
Timecop.return
|
133
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timelord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Mongeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timecop
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.5.1
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Pull dates out of strings
|