Skip to content

Add monotonic_seconds to the clock interface and rename monotonic_time #880

Description

@bolshakov

Problem

SlidingWindow exposes a private monotonic_seconds helper that converts @clock.monotonic_time (ms) to seconds:

def monotonic_seconds
  @clock.monotonic_time / 1000.0
end

The ms→s division is a unit-conversion concern that belongs on the clock, not on every caller. monotonic_time also has an ambiguous name — the unit is not apparent from the method name.

Proposed change

  • Add monotonic_seconds to the clock interface (SystemClock, NullClock) returning Float seconds via Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
  • Rename monotonic_timemonotonic_millis to make the unit explicit
  • Update SlidingWindow to call @clock.monotonic_seconds directly, removing its own conversion helper
  • Update RBS signatures for both clock types and SlidingWindow

Acceptance criteria

  • SystemClock#monotonic_seconds returns float seconds
  • SystemClock#monotonic_millis replaces monotonic_time
  • NullClock exposes both methods
  • SlidingWindow removes its private conversion helper and calls @clock.monotonic_seconds
  • RBS updated throughout
  • system_clock_spec covers both new methods

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueFor newcomers to learn the codebase. Human contributions only, AI-assisted PRs not accepted

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions