summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-05-13 15:26:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-05-13 15:26:59 -0700
commit8e21278d700b988fbe9c9699fb30ae9063ec9d31 (patch)
treeabc14920f2aec801c7fc61968822744daede71de
parent03e245adc7d73c3538471933bafba57972b9efcb (diff)
downloadpsych-8e21278d700b988fbe9c9699fb30ae9063ec9d31.zip
synching with ruby trunk
-rw-r--r--lib/psych/scalar_scanner.rb4
-rw-r--r--lib/psych/visitors/yaml_tree.rb2
-rw-r--r--test/psych/json/test_stream.rb2
-rw-r--r--test/psych/test_json_tree.rb2
-rw-r--r--test/psych/test_yaml.rb6
5 files changed, 11 insertions, 5 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb
index f7aaea7..29d66ee 100644
--- a/lib/psych/scalar_scanner.rb
+++ b/lib/psych/scalar_scanner.rb
@@ -80,10 +80,10 @@ module Psych
def parse_time string
date, time = *(string.split(/[ tT]/, 2))
(yy, m, dd) = date.split('-').map { |x| x.to_i }
- md = time.match(/(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/)
+ md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
(hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
- us = (md[2] ? Rational(md[2].sub(/^\./, '0.')) : 0) * 1000000
+ us = (md[2] ? Rational("0.#{md[2]}") : 0) * 1000000
time = Time.utc(yy, m, dd, hh, mm, ss, us)
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 84ebc90..6f90377 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -297,7 +297,7 @@ module Psych
private
def format_time time
if time.utc?
- time.strftime("%Y-%m-%d %H:%M:%S.%9NZ")
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
else
time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
end
diff --git a/test/psych/json/test_stream.rb b/test/psych/json/test_stream.rb
index 0af64c1..4690ad2 100644
--- a/test/psych/json/test_stream.rb
+++ b/test/psych/json/test_stream.rb
@@ -95,7 +95,7 @@ module Psych
time = Time.utc(2010, 10, 10)
@stream.push({'a' => time })
json = @io.string
- assert_match "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n", json
+ assert_match "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n", json
end
def test_datetime
diff --git a/test/psych/test_json_tree.rb b/test/psych/test_json_tree.rb
index fefa1f5..eed8cf3 100644
--- a/test/psych/test_json_tree.rb
+++ b/test/psych/test_json_tree.rb
@@ -53,7 +53,7 @@ module Psych
def test_time
time = Time.utc(2010, 10, 10)
- assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000Z\"}\n",
+ assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n",
Psych.to_json({'a' => time })
end
diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb
index 5c2f6dc..41bb377 100644
--- a/test/psych/test_yaml.rb
+++ b/test/psych/test_yaml.rb
@@ -14,6 +14,12 @@ class Psych_Unit_Tests < Psych::TestCase
Psych.domain_types.clear
end
+ def test_syck_compat
+ time = Time.utc(2010, 10, 10)
+ yaml = Psych.dump time
+ assert_match "2010-10-10 00:00:00.000000000 Z", yaml
+ end
+
# [ruby-core:34969]
def test_regexp_with_n
assert_cycle(Regexp.new('',0,'n'))