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
- #seconds_to_duration(seconds_float) ⇒ Object
- #time_to_timestamp(time) ⇒ Object
- #timestamp_to_time(timestamp) ⇒ Object
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) 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 () Time.at(.seconds, .nanos, :nanosecond) end |