1
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
5
# Time serialization/deserialization
8
# Deserializes JSON string by converting time since epoch to Time
9
def self.json_create(object)
10
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
11
object['n'] = usec * 1000
13
if instance_methods.include?(:tv_nsec)
14
at(object['s'], Rational(object['n'], 1000))
16
at(object['s'], object['n'] / 1000)
20
# Returns a hash, that will be turned into a JSON object and represent this
24
JSON.create_id => self.class.name,
26
'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
30
# Stores class name (Time) with number of seconds since epoch and number of
31
# microseconds for Time as JSON string
33
as_json.to_json(*args)