Sha256: af026aea3e1348afaae136279a24816ca3b2c584a9d1a4d705d2afb83a905643

Contents?: true

Size: 800 Bytes

Versions: 9

Compression:

Stored size: 800 Bytes

Contents

module Cucumber
  module Messages
    module TimeConversion
      NANOSECONDS_PER_SECOND = 1000000000

      def time_to_timestamp(time)
        rational = time.to_r
        Timestamp.new(seconds: rational.numerator, nanos: rational.denominator)
      end

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

      def seconds_to_duration(seconds_float)
        seconds, second_modulus = seconds_float.divmod(1)
        nanos = second_modulus * NANOSECONDS_PER_SECOND
        Duration.new(seconds: seconds, nanos: nanos)
      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

9 entries across 9 versions & 1 rubygems

Version Path
cucumber-messages-12.2.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-12.1.1 lib/cucumber/messages/time_conversion.rb
cucumber-messages-12.1.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-12.0.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-11.1.1 lib/cucumber/messages/time_conversion.rb
cucumber-messages-11.1.0 lib/cucumber/messages/time_conversion.rb
cucumber-messages-11.0.1 lib/cucumber/messages/time_conversion.rb
cucumber-messages-10.0.3 lib/cucumber/messages/time_conversion.rb
cucumber-messages-10.0.1 lib/cucumber/messages/time_conversion.rb