Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Date.parse() for simple iso8601 date strings
  • Loading branch information
adambeynon committed Jan 14, 2014
1 parent 9ba58b6 commit 77dfca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 7 additions & 0 deletions spec/opal/core/date_spec.rb
Expand Up @@ -3,6 +3,13 @@

# rubyspec does not have specs for these listed methods
describe Date do
describe ".parse" do
it "parses a date string into a Date instance" do
Date.parse('2013-10-4').should == Date.new(2013, 10, 4)
Date.parse('2013-06-02').should == Date.new(2013, 6, 2)
end
end

describe "#<" do
it "is true when self is before other" do
(Date.new(2013, 2, 4) < Date.new(2013, 2, 5)).should == true
Expand Down
11 changes: 2 additions & 9 deletions stdlib/date.rb
Expand Up @@ -9,7 +9,8 @@ def wrap(native)
end

def parse(string)
wrap `Date.parse(string)`
match = `/^(\d*)-(\d*)-(\d*)/.exec(string)`
wrap `new Date(parseInt(match[1]), parseInt(match[2]) - 1, parseInt(match[3]))`
end

def today
Expand Down Expand Up @@ -152,14 +153,6 @@ def to_s
}
end

def to_json
to_s.to_json
end

def as_json
to_s
end

def wday
`#@date.getDay()`
end
Expand Down

0 comments on commit 77dfca5

Please sign in to comment.