Skip to content

Commit

Permalink
Behave even more like 1.8, where datetime strings can have any kind o…
Browse files Browse the repository at this point in the history
…f characters
  • Loading branch information
sd committed Mar 18, 2013
1 parent b535bba commit 898ac6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/american_date.rb
Expand Up @@ -4,7 +4,7 @@
# Modify parsing methods to handle american date format correctly.
class << Date
# American date format detected by the library.
AMERICAN_DATE_RE = %r_\b(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})\b_.freeze
AMERICAN_DATE_RE = %r_(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})_.freeze

# Alias for stdlib Date._parse
alias _parse_without_american_date _parse
Expand Down
13 changes: 13 additions & 0 deletions spec/american_date_spec.rb
Expand Up @@ -30,6 +30,10 @@
specify "should ignore preceding weekday" do
Date.parse('Day 01/02/2003').should == Date.new(2003, 1, 2)
end

specify "should work just like 1.8 does" do
Date.parse('10:20:30something01/02/2003else').should == Date.new(2003, 1, 2)
end
end

describe "DateTime.parse" do
Expand Down Expand Up @@ -69,6 +73,11 @@
specify "should work with times and weekdays" do
DateTime.parse('Day 01/02/2003 10:20:30').should == DateTime.new(2003, 1, 2, 10, 20, 30)
end

specify "should work just like 1.8 does" do
DateTime.parse('10:20:30something01/02/2003else').should == DateTime.new(2003, 1, 2, 10, 20, 30)
end

end

describe "Time.parse" do
Expand Down Expand Up @@ -115,6 +124,10 @@
specify "should work with time first and date second and weekday in the middle" do
Time.parse('10:20:30 Thu 01/02/2003').should == Time.local(2003, 1, 2, 10, 20, 30)
end

specify "should work just like 1.8 does" do
Time.parse('10:20:30something01/02/2003else').should == Time.local(2003, 1, 2, 10, 20, 30)
end
end

describe "Date._parse" do
Expand Down

0 comments on commit 898ac6b

Please sign in to comment.