From 5057130d95d3d92d054db7e64198cf60e96390cf Mon Sep 17 00:00:00 2001 From: Jim Meyer Date: Fri, 19 Feb 2010 06:09:39 +0800 Subject: [PATCH] Handle ISO 8601 date/time format --- lib/crack/json.rb | 2 +- test/json_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/crack/json.rb b/lib/crack/json.rb index 71c7ae8..5108e59 100644 --- a/lib/crack/json.rb +++ b/lib/crack/json.rb @@ -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: diff --git a/test/json_test.rb b/test/json_test.rb index 17e3926..8609c5c 100644 --- a/test/json_test.rb +++ b/test/json_test.rb @@ -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'},