class Puppet::Pops::Serialization::TimeFactory
Implements all the constructors found in the Time
class and ensures that the created Time
object can be serialized and deserialized using its seconds and nanoseconds without loss of precision.
@deprecated No longer in use. Functionality replaced by Timestamp @api private
Constants
- NANO_DENOMINATOR
Public Class Methods
# File lib/puppet/pops/serialization/time_factory.rb 13 def self.at(*args) 14 sec_nsec_safe(Time.at(*args)) 15 end
Creates a Time
object from a Rational defined as:
(sec * #NANO_DENOMINATOR + nsec) / #NANO_DENOMINATOR
This ensures that a Time
object can be reliably serialized and using its its tv_sec and tv_nsec values and then recreated again (using this method) without loss of precision.
@param sec [Integer] seconds since Epoch @param nsec [Integer] nano seconds @return [Time] the created object
# File lib/puppet/pops/serialization/time_factory.rb 53 def self.from_sec_nsec(sec, nsec) 54 Time.at(Rational(sec * NANO_DENOMINATOR + nsec, NANO_DENOMINATOR)) 55 end
# File lib/puppet/pops/serialization/time_factory.rb 17 def self.gm(*args) 18 sec_nsec_safe(Time.gm(*args)) 19 end
# File lib/puppet/pops/serialization/time_factory.rb 21 def self.local(*args) 22 sec_nsec_safe(Time.local(*args)) 23 end
# File lib/puppet/pops/serialization/time_factory.rb 25 def self.mktime(*args) 26 sec_nsec_safe(Time.mktime(*args)) 27 end
# File lib/puppet/pops/serialization/time_factory.rb 29 def self.new(*args) 30 sec_nsec_safe(Time.new(*args)) 31 end
# File lib/puppet/pops/serialization/time_factory.rb 33 def self.now 34 sec_nsec_safe(Time.now) 35 end
Returns a new Time
object that is adjusted to ensure that precision is not lost when it is serialized and deserialized using its seconds and nanoseconds @param t [Time] the object to adjust @return [Time] the adjusted object
# File lib/puppet/pops/serialization/time_factory.rb 62 def self.sec_nsec_safe(t) 63 from_sec_nsec(t.tv_sec, t.tv_nsec) 64 end
# File lib/puppet/pops/serialization/time_factory.rb 37 def self.utc(*args) 38 sec_nsec_safe(Time.utc(*args)) 39 end