HEX
Server: Apache
System: Linux dinesh8189 5.15.98-grsec-sharedvalley-2.lc.el8.x86_64 #1 SMP Thu Mar 9 09:07:30 -03 2023 x86_64
User: cgmgerenciamento1 (814285)
PHP: 8.1.26
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/serialization/time_factory.rb
module Puppet::Pops
module Serialization
  # 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
  class TimeFactory

    NANO_DENOMINATOR = 10**9

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

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

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

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

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

    def self.now
      sec_nsec_safe(Time.now)
    end

    def self.utc(*args)
      sec_nsec_safe(Time.utc(*args))
    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
    #
    def self.from_sec_nsec(sec, nsec)
      Time.at(Rational(sec * NANO_DENOMINATOR + nsec, NANO_DENOMINATOR))
    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
    #
    def self.sec_nsec_safe(t)
      from_sec_nsec(t.tv_sec, t.tv_nsec)
    end
  end
end
end