Module: ProcessShared::TimeSpec

Included in:
Posix::TimeSpec
Defined in:
lib/process_shared/time_spec.rb

Constant Summary

NS_PER_S =
1e9
US_PER_NS =
1000
TV_NSEC_MAX =
(NS_PER_S - 1)

Instance Method Summary collapse

Instance Method Details

#add_seconds!(float_sec) ⇒ Object

Assuming self responds to setting the value of [:tv_sec] and [:tv_nsec], add +secs+ to the time spec.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/process_shared/time_spec.rb', line 9

def add_seconds!(float_sec)
  # add timeout in seconds to abs_timeout; careful with rounding
  sec = float_sec.floor
  nsec = ((float_sec - sec) * NS_PER_S).floor

  self[:tv_sec] += sec
  self[:tv_nsec] += nsec
  while self[:tv_nsec] > TV_NSEC_MAX
    self[:tv_sec] += 1
    self[:tv_nsec] -= NS_PER_S
  end
end