Sha256: ac874b038dbb5029144712439e31354fd3fcada932c2cdae8147954cd18e0bf1

Contents?: true

Size: 840 Bytes

Versions: 26

Compression:

Stored size: 840 Bytes

Contents

module Cucumber
  module Messages
    module TimeConversion
      NANOSECONDS_PER_SECOND = 1000000000

      def time_to_timestamp(time)
        {
          'seconds' => time.to_i,
          'nanos' => time.nsec
        }
      end

      def timestamp_to_time(timestamp)
        Time.at(timestamp['seconds'] + timestamp['nanos'].to_f / NANOSECONDS_PER_SECOND)
      end

      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

      def duration_to_seconds(duration)
        seconds_part = duration['seconds']
        nanos_part = duration['nanos'].to_f / NANOSECONDS_PER_SECOND
        seconds_part + nanos_part
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
cucumber-messages-24.1.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-24.0.1 lib/cucumber/messages/time_conversion.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-messages-22.0.0/lib/cucumber/messages/time_conversion.rb
cucumber-messages-0.0.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-24.0.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-23.0.0 lib/cucumber/messages/time_conversion.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-messages-21.0.1/lib/cucumber/messages/time_conversion.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/time_conversion.rb
cucumber-messages-22.0.0 lib/cucumber/messages/time_conversion.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/time_conversion.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/time_conversion.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/time_conversion.rb
cucumber-messages-21.0.1 lib/cucumber/messages/time_conversion.rb
cucumber-messages-21.0.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-20.0.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-19.1.4 lib/cucumber/messages/time_conversion.rb
cucumber-messages-19.1.3 lib/cucumber/messages/time_conversion.rb
cucumber-messages-19.1.2 lib/cucumber/messages/time_conversion.rb
cucumber-messages-19.1.1 lib/cucumber/messages/time_conversion.rb
cucumber-messages-19.1.0 lib/cucumber/messages/time_conversion.rb