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.

API:

  • private

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.

API:

  • private

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.

API:

  • private



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

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:

  • seconds since Epoch

  • nano seconds

Returns:

  • the created object

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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:

  • the object to adjust

Returns:

  • the adjusted object

API:

  • private



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

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.

API:

  • private



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

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