module Google::Cloud::Trace::Utils
Utils
provides some internal utility methods for Trace
.
@private
Public Class Methods
grpc_to_time(grpc)
click to toggle source
Convert a Timestamp proto object to a Ruby Time object.
@private
# File lib/google/cloud/trace/utils.rb, line 48 def self.grpc_to_time grpc Time.at(grpc.seconds, Rational(grpc.nanos, 1000)).utc end
time_to_grpc(time)
click to toggle source
Convert a Ruby Time object to a timestamp proto object.
@private
# File lib/google/cloud/trace/utils.rb, line 30 def self.time_to_grpc time return nil if time.nil? # sometimes this gets called with time as a float or # int. Coerce into a time object, and move on. time = Time.at time if time.is_a? Numeric raise ArgumentError unless time.is_a? Time Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec end