Skip to content

Commit

Permalink
Handle ISO 8601 date/time format
Browse files Browse the repository at this point in the history
  • Loading branch information
purp authored and pengwynn committed Feb 21, 2010
1 parent e70b421 commit 5057130
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/crack/json.rb
Expand Up @@ -20,7 +20,7 @@ def self.unescape(str)
end

# matches YAML-formatted dates
DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/
DATE_REGEX = /^\d{4}-\d{2}-\d{2}$|^\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/

# Ensure that ":" and "," are always followed by a space
def self.convert_json_to_yaml(json) #:nodoc:
Expand Down
2 changes: 2 additions & 0 deletions test/json_test.rb
Expand Up @@ -14,6 +14,8 @@ class JsonTest < Test::Unit::TestCase
%({a: "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
%({a: "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
%({a: "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
# Handle ISO 8601 date/time format http://en.wikipedia.org/wiki/ISO_8601
%({a: "2007-01-01T01:12:34Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
# no time zone
%({a: "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
%({"bio": "1985-01-29: birthdate"}) => {'bio' => '1985-01-29: birthdate'},
Expand Down

0 comments on commit 5057130

Please sign in to comment.