[ruby/json] Drop compatibility for missing Time#tv_nsec (Ruby 1.8)

https://github.com/ruby/json/commit/b240bde402

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
This commit is contained in:
Étienne Barrié 2024-10-21 12:02:47 +02:00 committed by Hiroshi SHIBATA
parent 11348c583f
commit 5f97468958

View File

@ -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