aboutsummaryrefslogtreecommitdiffstats
path: root/test/psych/test_date_time.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-16 07:02:22 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-16 07:02:22 +0000
commit74c83a38ea637c19a4d33ab64fd5d3b0b169fe4e (patch)
tree06b6846cff862abde4526a2b0f997535926d96d9 /test/psych/test_date_time.rb
parent5202fcc74c5aed2afa2b779d26f0537e11e93093 (diff)
downloadruby-74c83a38ea637c19a4d33ab64fd5d3b0b169fe4e.tar.gz
Merge psych-3.0.0.beta2 from https://github.com/ruby/psych
It contains following changes from 3.0.0.beta1 * Preserve time zone offset when deserializing times https://github.com/ruby/psych/pull/316 * Enable YAML serialization of Ruby delegators https://github.com/ruby/psych/pull/158 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych/test_date_time.rb')
-rw-r--r--test/psych/test_date_time.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb
index 443669d17f..3c8b436098 100644
--- a/test/psych/test_date_time.rb
+++ b/test/psych/test_date_time.rb
@@ -9,10 +9,41 @@ module Psych
assert_cycle time
end
+ def test_usec
+ time = Time.utc(2017, 4, 13, 12, 0, 0, 5)
+ assert_cycle time
+ end
+
+ def test_non_utc
+ time = Time.new(2017, 4, 13, 12, 0, 0.5, "+09:00")
+ assert_cycle time
+ end
+
+ def test_timezone_offset
+ times = [Time.new(2017, 4, 13, 12, 0, 0, "+09:00"),
+ Time.new(2017, 4, 13, 12, 0, 0, "-05:00")]
+ cycled = Psych::load(Psych.dump times)
+ assert_match(/12:00:00 \+0900/, cycled.first.to_s)
+ assert_match(/12:00:00 -0500/, cycled.last.to_s)
+ end
+
def test_new_datetime
assert_cycle DateTime.new
end
+ def test_datetime_non_utc
+ dt = DateTime.new(2017, 4, 13, 12, 0, 0.5, "+09:00")
+ assert_cycle dt
+ end
+
+ def test_datetime_timezone_offset
+ times = [DateTime.new(2017, 4, 13, 12, 0, 0, "+09:00"),
+ DateTime.new(2017, 4, 13, 12, 0, 0, "-05:00")]
+ cycled = Psych::load(Psych.dump times)
+ assert_match(/12:00:00\+09:00/, cycled.first.to_s)
+ assert_match(/12:00:00-05:00/, cycled.last.to_s)
+ end
+
def test_invalid_date
assert_cycle "2013-10-31T10:40:07-000000000000033"
end