Module: Cucumber::Messages::Helpers::TimeConversion

Defined in:
lib/cucumber/messages/helpers/time_conversion.rb

Constant Summary collapse

NANOSECOND_POWER =
9
NANOSECONDS_PER_SECOND =
10**NANOSECOND_POWER

Instance Method Summary collapse

Instance Method Details

#seconds_to_duration(seconds_float) ⇒ Object



10
11
12
13
14
# File 'lib/cucumber/messages/helpers/time_conversion.rb', line 10

def seconds_to_duration(seconds_float)
  seconds, decimal = seconds_float.to_s.split('.')
  nanos = decimal.to_s.ljust(NANOSECOND_POWER, '0').to_i
  { 'seconds' => seconds.to_i, 'nanos' => nanos }
end

#time_to_timestamp(time) ⇒ Object



16
17
18
# File 'lib/cucumber/messages/helpers/time_conversion.rb', line 16

def time_to_timestamp(time)
  Cucumber::Messages::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
end

#timestamp_to_time(timestamp) ⇒ Object



20
21
22
# File 'lib/cucumber/messages/helpers/time_conversion.rb', line 20

def timestamp_to_time(timestamp)
  Time.at(timestamp.seconds, timestamp.nanos, :nanosecond)
end