Module: PatientHttp::TimeHelper

Extended by:
TimeHelper
Included in:
LifecycleManager, Processor, RequestTask, TimeHelper
Defined in:
lib/patient_http/time_helper.rb

Overview

Helper module for time-related operations using monotonic and wall clock time.

This module provides utilities for accurate timing measurements that are immune to system clock changes, as well as conversion between monotonic and wall clock time.

Instance Method Summary collapse

Instance Method Details

#monotonic_timeFloat

Get the current monotonic time.

Monotonic time is guaranteed to be non-decreasing and immune to system clock changes.

Returns:

  • (Float)

    current monotonic time in seconds since an unspecified starting point



16
17
18
# File 'lib/patient_http/time_helper.rb', line 16

def monotonic_time
  ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
end

#wall_clock_time(monotonic_timestamp) ⇒ Time

Convert a monotonic timestamp to wall clock time.

Parameters:

  • monotonic_timestamp (Float)

    monotonic timestamp to convert

Returns:

  • (Time)

    wall clock time corresponding to the monotonic timestamp



24
25
26
27
28
29
30
# File 'lib/patient_http/time_helper.rb', line 24

def wall_clock_time(monotonic_timestamp)
  return nil unless monotonic_timestamp

  now = Time.now
  elapsed = monotonic_time - monotonic_timestamp
  now - elapsed
end