lib/json/add/time.rb in json_pure-1.7.1 vs lib/json/add/time.rb in json_pure-1.7.2
- old
+ new
@@ -18,13 +18,16 @@
end
# 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
# Stores class name (Time) with number of seconds since epoch and number of
# microseconds for Time as JSON string