Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/omf-sfa/resource/oproperty.rb
Overview
We use the JSON serialization for Time objecs from ‘json/add/core’ in order to avoid the conflicts with the ‘active_support/core_ext’ which is included in ‘omf_base’ and overrides Time objects serialization. We want ‘JSON.load’ to return actual Time objects instead of Strings.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.json_create(object) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/omf-sfa/resource/oproperty.rb', line 20 def self.json_create(object) if usec = object.delete('u') # used to be tv_usec -> tv_nsec object['n'] = usec * 1000 end if instance_methods.include?(:tv_nsec) at(object['s'], Rational(object['n'], 1000)) else at(object['s'], object['n'] / 1000) end end |
Instance Method Details
#to_json(*args) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/omf-sfa/resource/oproperty.rb', line 12 def to_json(*args) { JSON.create_id => self.class.name, 's' => tv_sec, 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000 }.to_json(*args) end |