jnunemaker/crack — pull request #46 by jswanner (2013-07-10 16:46:12+00:00)
Title: Fix date parsing of JSON

The current test failures stem from using YAML to parse JSON, and that Syck and Psych (really libyaml) behave differently with the JSON schema of YAML.

Syck will convert this YAML without a fuss: `{"a": 2012-12-12T12:12:12Z}`; while Psych raises an exception: "found unexpected ':' while scanning a plain scalar at line 1 column 7" -- I'm assuming it's because its JSON schema is more strict.

That said, if you tag the value as a `timestamp`, Psych will parse it just fine: `{"a": !!timestamp "2012-12-12T12:12:12Z"}`; and although Syck has no problem parsing that, it unfortunately doesn't give you a `Time` object as the value. Which is why I added an `if` statement to keep the old behavior for Syck.

There is still one failing test, and that's because this JSON `{"a": "2007-01-01 01:12:34"}` is parsed with a value of type `Time` -- instead of a `String` that the test is looking for. If you want the test to pass, and want to keep this value as a `String`, you can remove the last `?` from `DATE_REGEX` to accomplish that.