Class: Puppet::Pops::Serialization::TimeFactory Deprecated Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/serialization/time_factory.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Deprecated.

No longer in use. Functionality replaced by Timestamp

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.

Constant Summary collapse

NANO_DENOMINATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

10**9

Class Method Summary collapse

Class Method Details

.at(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/puppet/pops/serialization/time_factory.rb', line 14

def self.at(*args)
  sec_nsec_safe(Time.at(*args))
end

.from_sec_nsec(sec, nsec) ⇒ Time

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • sec (Integer)

    seconds since Epoch

  • nsec (Integer)

    nano seconds

Returns:

  • (Time)

    the created object



54
55
56
# File 'lib/puppet/pops/serialization/time_factory.rb', line 54

def self.from_sec_nsec(sec, nsec)
  Time.at(Rational(sec * NANO_DENOMINATOR + nsec, NANO_DENOMINATOR))
end

.gm(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/puppet/pops/serialization/time_factory.rb', line 18

def self.gm(*args)
  sec_nsec_safe(Time.gm(*args))
end

.local(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/puppet/pops/serialization/time_factory.rb', line 22

def self.local(*args)
  sec_nsec_safe(Time.local(*args))
end

.mktime(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/puppet/pops/serialization/time_factory.rb', line 26

def self.mktime(*args)
  sec_nsec_safe(Time.mktime(*args))
end

.new(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/puppet/pops/serialization/time_factory.rb', line 30

def self.new(*args)
  sec_nsec_safe(Time.new(*args))
end

.nowObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/puppet/pops/serialization/time_factory.rb', line 34

def self.now
  sec_nsec_safe(Time.now)
end

.sec_nsec_safe(t) ⇒ Time

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • t (Time)

    the object to adjust

Returns:

  • (Time)

    the adjusted object



63
64
65
# File 'lib/puppet/pops/serialization/time_factory.rb', line 63

def self.sec_nsec_safe(t)
  from_sec_nsec(t.tv_sec, t.tv_nsec)
end

.utc(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/puppet/pops/serialization/time_factory.rb', line 38

def self.utc(*args)
  sec_nsec_safe(Time.utc(*args))
end