Class: Rclrb::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/rclrb/time.rb

Overview

Represent time.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = 0) ⇒ Time

Initialise time, time is given in seconds



7
8
9
# File 'lib/rclrb/time.rb', line 7

def initialize time = 0
  @time_sec = time
end

Class Method Details

.from_sec(sec) ⇒ Object

Create a time objects from seconds



12
13
14
# File 'lib/rclrb/time.rb', line 12

def Time.from_sec sec
  return Time.new sec
end

.from_sec_nsec(sec, nsec) ⇒ Object

Create a time objects from seconds and nanoseconds



17
18
19
# File 'lib/rclrb/time.rb', line 17

def Time.from_sec_nsec sec, nsec
  return Time.new sec + nsec * 1e-9
end

Instance Method Details

#to_secObject

Return the time in seconds



22
23
24
# File 'lib/rclrb/time.rb', line 22

def to_sec
  return @time_sec
end

#to_sec_nsecObject

Return the time in second and nanoseconds (as integers)



27
28
29
30
# File 'lib/rclrb/time.rb', line 27

def to_sec_nsec
  si = @time_sec.to_i
  return si, ((@time_sec - si) * 1e9).to_i
end