summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Barrié <[email protected]>2024-10-21 12:02:47 +0200
committerHiroshi SHIBATA <[email protected]>2024-10-26 18:44:15 +0900
commit5f9746895847be1e2dd202207d7a12f3f556294c (patch)
treee9aff83597b90654f8bcacb469975e9c05588de2
parent11348c583f228ef76ed95d8c468fbe13616826c6 (diff)
[ruby/json] Drop compatibility for missing Time#tv_nsec (Ruby 1.8)
https://github.com/ruby/json/commit/b240bde402 Co-authored-by: Jean Boussier <[email protected]>
-rw-r--r--ext/json/lib/json/add/time.rb11
1 files changed, 2 insertions, 9 deletions
diff --git a/ext/json/lib/json/add/time.rb b/ext/json/lib/json/add/time.rb
index 599ed9e24b..0ee9c9ed2c 100644
--- a/ext/json/lib/json/add/time.rb
+++ b/ext/json/lib/json/add/time.rb
@@ -10,11 +10,7 @@ class Time
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
object['n'] = usec * 1000
end
- if method_defined?(:tv_nsec)
- at(object['s'], Rational(object['n'], 1000))
- else
- at(object['s'], object['n'] / 1000)
- end
+ at(object['s'], Rational(object['n'], 1000))
end
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
@@ -34,13 +30,10 @@ class Time
# # => 2023-11-25 11:00:56.472846644 -0600
#
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' => nanoseconds,
+ 'n' => tv_nsec,
}
end