american_date 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/american_date.rb +12 -1
- data/spec/american_date_spec.rb +80 -0
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6fc099c8faff7f7a245c01f54bcc32c4770fa8d
|
4
|
+
data.tar.gz: 0b072c3a750fc6fb6ac0bc81c730ff1fae5e6889
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: deff8c7fd14b1b48d4e88fd6f3257931623206746cdd2f8947f329ec441edf136fe94b3fce081cecfb4e2601563669b0bdc5ed33288a06e690ce14fefa8e4803
|
7
|
+
data.tar.gz: 1a9b4920b7396ba32f4589168943fa1870d256e3ef6fa5c7ed529fc396fc9d05d32f53513b8cff6a4b61f893c2ddd7292276a7b2a90058dbcf95a4f869b29377
|
data/CHANGELOG
CHANGED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
data/lib/american_date.rb
CHANGED
@@ -4,7 +4,7 @@ if RUBY_VERSION >= '1.9'
|
|
4
4
|
# Modify parsing methods to handle american date format correctly.
|
5
5
|
class << Date
|
6
6
|
# American date format detected by the library.
|
7
|
-
AMERICAN_DATE_RE = %r_\A\s*(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})_
|
7
|
+
AMERICAN_DATE_RE = %r_\A\s*(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})_
|
8
8
|
|
9
9
|
# Alias for stdlib Date._parse
|
10
10
|
alias _parse_without_american_date _parse
|
@@ -28,6 +28,17 @@ if RUBY_VERSION >= '1.9'
|
|
28
28
|
|
29
29
|
# Transform american date fromat into ISO format.
|
30
30
|
def convert_american_to_iso(string)
|
31
|
+
unless string.is_a?(String)
|
32
|
+
if string.respond_to?(:to_str)
|
33
|
+
str = string.to_str
|
34
|
+
unless str.is_a?(String)
|
35
|
+
raise TypeError, "no implicit conversion of #{string.inspect} into String"
|
36
|
+
end
|
37
|
+
string = str
|
38
|
+
else
|
39
|
+
raise TypeError, "no implicit conversion of #{string.inspect} into String"
|
40
|
+
end
|
41
|
+
end
|
31
42
|
string.sub(AMERICAN_DATE_RE){|m| "#$3-#$1-#$2"}
|
32
43
|
end
|
33
44
|
end
|
data/spec/american_date_spec.rb
CHANGED
@@ -26,6 +26,26 @@ describe "Date.parse" do
|
|
26
26
|
specify "should ignore preceding whitespace" do
|
27
27
|
Date.parse(' 01/02/2003').should == Date.new(2003, 1, 2)
|
28
28
|
end
|
29
|
+
|
30
|
+
if RUBY_VERSION > '1.9'
|
31
|
+
specify "should raise TypeError for invalid values" do
|
32
|
+
[nil, 1, 1.0, [], {}].each do |x|
|
33
|
+
proc{Date.parse(x)}.should raise_error(TypeError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should handle values implicitly convertible to String" do
|
38
|
+
o = Object.new
|
39
|
+
def o.to_str() '01/02/2003' end
|
40
|
+
Date.parse(o).should == Date.new(2003, 1, 2)
|
41
|
+
end
|
42
|
+
|
43
|
+
specify "should handle values implicitly convertible to String" do
|
44
|
+
o = Object.new
|
45
|
+
def o.to_str() 1 end
|
46
|
+
proc{Date.parse(o)}.should raise_error(TypeError)
|
47
|
+
end
|
48
|
+
end
|
29
49
|
end
|
30
50
|
|
31
51
|
describe "DateTime.parse" do
|
@@ -57,6 +77,26 @@ describe "DateTime.parse" do
|
|
57
77
|
specify "should work with times" do
|
58
78
|
DateTime.parse('01/02/2003 10:20:30').should == DateTime.new(2003, 1, 2, 10, 20, 30)
|
59
79
|
end
|
80
|
+
|
81
|
+
if RUBY_VERSION > '1.9'
|
82
|
+
specify "should raise TypeError for invalid values" do
|
83
|
+
[nil, 1, 1.0, [], {}].each do |x|
|
84
|
+
proc{DateTime.parse(x)}.should raise_error(TypeError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
specify "should handle values implicitly convertible to String" do
|
89
|
+
o = Object.new
|
90
|
+
def o.to_str() '01/02/2003' end
|
91
|
+
DateTime.parse(o).should == DateTime.new(2003, 1, 2)
|
92
|
+
end
|
93
|
+
|
94
|
+
specify "should handle values implicitly convertible to String" do
|
95
|
+
o = Object.new
|
96
|
+
def o.to_str() 1 end
|
97
|
+
proc{DateTime.parse(o)}.should raise_error(TypeError)
|
98
|
+
end
|
99
|
+
end
|
60
100
|
end
|
61
101
|
|
62
102
|
describe "Time.parse" do
|
@@ -87,6 +127,26 @@ describe "Time.parse" do
|
|
87
127
|
specify "should work with times" do
|
88
128
|
Time.parse('01/02/2003 10:20:30').should == Time.local(2003, 1, 2, 10, 20, 30)
|
89
129
|
end
|
130
|
+
|
131
|
+
if RUBY_VERSION > '1.9'
|
132
|
+
specify "should raise TypeError for invalid values" do
|
133
|
+
[nil, 1, 1.0, [], {}].each do |x|
|
134
|
+
proc{Time.parse(x)}.should raise_error(TypeError)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
specify "should handle values implicitly convertible to String" do
|
139
|
+
o = Object.new
|
140
|
+
def o.to_str() '01/02/2003' end
|
141
|
+
Time.parse(o).should == Time.local(2003, 1, 2)
|
142
|
+
end
|
143
|
+
|
144
|
+
specify "should handle values implicitly convertible to String" do
|
145
|
+
o = Object.new
|
146
|
+
def o.to_str() 1 end
|
147
|
+
proc{Time.parse(o)}.should raise_error(TypeError)
|
148
|
+
end
|
149
|
+
end
|
90
150
|
end
|
91
151
|
|
92
152
|
describe "Date._parse" do
|
@@ -118,4 +178,24 @@ describe "Date._parse" do
|
|
118
178
|
specify "should work with times" do
|
119
179
|
DateTime._parse('01/02/2003 10:20:30').should == {:year=>2003, :mon=>1, :mday=>2, :hour=>10, :min=>20, :sec=>30}
|
120
180
|
end
|
181
|
+
|
182
|
+
if RUBY_VERSION > '1.9'
|
183
|
+
specify "should raise TypeError for invalid values" do
|
184
|
+
[nil, 1, 1.0, [], {}].each do |x|
|
185
|
+
proc{DateTime._parse(x)}.should raise_error(TypeError)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
specify "should handle values implicitly convertible to String" do
|
190
|
+
o = Object.new
|
191
|
+
def o.to_str() '01/02/2003' end
|
192
|
+
DateTime._parse(o).should == {:year=>2003, :mon=>1, :mday=>2}
|
193
|
+
end
|
194
|
+
|
195
|
+
specify "should handle values implicitly convertible to String" do
|
196
|
+
o = Object.new
|
197
|
+
def o.to_str() 1 end
|
198
|
+
proc{DateTime._parse(o)}.should raise_error(TypeError)
|
199
|
+
end
|
200
|
+
end
|
121
201
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: american_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jeremy Evans
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: American style month/day/year date parsing for ruby 1.9
|
15
14
|
email: code@jeremyevans.net
|
@@ -28,33 +27,32 @@ files:
|
|
28
27
|
- lib/american_date.rb
|
29
28
|
homepage: https://github.com/jeremyevans/ruby-american_date
|
30
29
|
licenses: []
|
30
|
+
metadata: {}
|
31
31
|
post_install_message:
|
32
32
|
rdoc_options:
|
33
33
|
- --quiet
|
34
34
|
- --inline-source
|
35
35
|
- --line-numbers
|
36
36
|
- --title
|
37
|
-
-
|
37
|
+
- 'american_date: American style month/day/year date parsing for ruby 1.9'
|
38
38
|
- --main
|
39
39
|
- README.rdoc
|
40
40
|
require_paths:
|
41
41
|
- lib
|
42
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
43
|
requirements:
|
45
|
-
- -
|
44
|
+
- - '>='
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '0'
|
48
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
48
|
requirements:
|
51
|
-
- -
|
49
|
+
- - '>='
|
52
50
|
- !ruby/object:Gem::Version
|
53
51
|
version: '0'
|
54
52
|
requirements: []
|
55
53
|
rubyforge_project:
|
56
|
-
rubygems_version:
|
54
|
+
rubygems_version: 2.0.0
|
57
55
|
signing_key:
|
58
|
-
specification_version:
|
56
|
+
specification_version: 4
|
59
57
|
summary: American style month/day/year date parsing for ruby 1.9
|
60
58
|
test_files: []
|