module Cucumber::Messages::TimeConversion

Constants

NANOSECONDS_PER_SECOND

Public Instance Methods

duration_to_seconds(duration) click to toggle source
# File lib/cucumber/messages/time_conversion.rb, line 26
def duration_to_seconds(duration)
  seconds_part = duration['seconds']
  nanos_part = duration['nanos'].to_f / NANOSECONDS_PER_SECOND
  seconds_part + nanos_part
end
seconds_to_duration(seconds_float) click to toggle source
# File lib/cucumber/messages/time_conversion.rb, line 17
def seconds_to_duration(seconds_float)
  seconds, second_modulus = seconds_float.divmod(1)
  nanos = second_modulus * NANOSECONDS_PER_SECOND
  {
    'seconds' => seconds,
    'nanos' => nanos.to_i
  }
end
time_to_timestamp(time) click to toggle source
# File lib/cucumber/messages/time_conversion.rb, line 6
def time_to_timestamp(time)
  {
    'seconds' => time.to_i,
    'nanos' => time.nsec
  }
end
timestamp_to_time(timestamp) click to toggle source
# File lib/cucumber/messages/time_conversion.rb, line 13
def timestamp_to_time(timestamp)
  Time.at(timestamp['seconds'] + timestamp['nanos'].to_f / NANOSECONDS_PER_SECOND)
end