summaryrefslogtreecommitdiff
path: root/ext/json/lib/json/add/time.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-12 10:51:49 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-12 10:51:49 +0000
commit43f6fdfb42d3f4c9025c290bdf5aeffe5959f1bf (patch)
treebc2260bf09b94eef5c9ce2b08f366a822a9a2fed /ext/json/lib/json/add/time.rb
parent395d7bb34624d69bf54e121a4f385ef84537e996 (diff)
* ext/json: merge JSON 1.7.5.
fix tests and other fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/lib/json/add/time.rb')
-rw-r--r--ext/json/lib/json/add/time.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/json/lib/json/add/time.rb b/ext/json/lib/json/add/time.rb
index 9755707..338209d 100644
--- a/ext/json/lib/json/add/time.rb
+++ b/ext/json/lib/json/add/time.rb
@@ -20,10 +20,13 @@ class Time
# Returns a hash, that will be turned into a JSON object and represent this
# object.
def as_json(*)
+ nanoseconds = [ tv_usec * 1000 ]
+ respond_to?(:tv_nsec) and nanoseconds << tv_nsec
+ nanoseconds = nanoseconds.max
{
JSON.create_id => self.class.name,
's' => tv_sec,
- 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
+ 'n' => nanoseconds,
}
end