From a04856d8ea1bc5e98e9a8ef299dffd6bee365fc1 Mon Sep 17 00:00:00 2001 From: Josh Partlow Date: Fri, 18 Nov 2011 21:38:06 -0800 Subject: Fix for Time.json_create ensures == Time instances for roundtrip through JSON serialization in Ruby 1.9.2. --- lib/json/add/time.rb | 4 ++-- tests/test_json_addition.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/json/add/time.rb b/lib/json/add/time.rb index abc807a..9755707 100644 --- a/lib/json/add/time.rb +++ b/lib/json/add/time.rb @@ -10,8 +10,8 @@ class Time if usec = object.delete('u') # used to be tv_usec -> tv_nsec object['n'] = usec * 1000 end - if respond_to?(:tv_nsec) - at(*object.values_at('s', 'n')) + if instance_methods.include?(:tv_nsec) + at(object['s'], Rational(object['n'], 1000)) else at(object['s'], object['n'] / 1000) end diff --git a/tests/test_json_addition.rb b/tests/test_json_addition.rb index b9cc6d1..49ff437 100755 --- a/tests/test_json_addition.rb +++ b/tests/test_json_addition.rb @@ -129,7 +129,7 @@ class TC_JSONAddition < Test::Unit::TestCase def test_core t = Time.now - assert_equal t.inspect, JSON(JSON(t)).inspect + assert_equal t, JSON(JSON(t)) d = Date.today assert_equal d, JSON(JSON(d)) d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161) -- cgit v1.2.1