Skip to content

Commit b240bde

Browse files
etiennebarriebyroot
andcommitted
Drop compatibility for missing Time#tv_nsec (Ruby 1.8)
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
1 parent 5394278 commit b240bde

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

lib/json/add/time.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ def self.json_create(object)
1010
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
1111
object['n'] = usec * 1000
1212
end
13-
if method_defined?(:tv_nsec)
14-
at(object['s'], Rational(object['n'], 1000))
15-
else
16-
at(object['s'], object['n'] / 1000)
17-
end
13+
at(object['s'], Rational(object['n'], 1000))
1814
end
1915

2016
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
@@ -34,13 +30,10 @@ def self.json_create(object)
3430
# # => 2023-11-25 11:00:56.472846644 -0600
3531
#
3632
def as_json(*)
37-
nanoseconds = [ tv_usec * 1000 ]
38-
respond_to?(:tv_nsec) and nanoseconds << tv_nsec
39-
nanoseconds = nanoseconds.max
4033
{
4134
JSON.create_id => self.class.name,
4235
's' => tv_sec,
43-
'n' => nanoseconds,
36+
'n' => tv_nsec,
4437
}
4538
end
4639

0 commit comments

Comments
 (0)