File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -626,6 +626,14 @@ class Node {
626626 return this . _clock ;
627627 }
628628
629+ /**
630+ * Get the current time using the node's clock.
631+ * @returns {Time } - The current time.
632+ */
633+ now ( ) {
634+ return this . getClock ( ) . now ( ) ;
635+ }
636+
629637 /**
630638 * Get the list of published topics discovered by the provided node for the remote node name.
631639 * @param {string } nodeName - The name of the node.
Original file line number Diff line number Diff line change 1414
1515'use strict' ;
1616
17+ const IsClose = require ( 'is-close' ) ;
1718const assert = require ( 'assert' ) ;
1819const rclnodejs = require ( '../index.js' ) ;
1920const assertUtils = require ( './utils.js' ) ;
@@ -365,6 +366,16 @@ describe('rcl node methods testing', function() {
365366 assert . strictEqual ( clock . clockType , rclnodejs . ClockType . ROS_TIME ) ;
366367 } ) ;
367368
369+ it ( 'node.now' , function ( ) {
370+ const time = node . now ( ) ;
371+ assert . ok ( time ) ;
372+ assert . strictEqual ( node . getClock ( ) . clockType , time . clockType ) ;
373+
374+ const seconds = time . secondsAndNanoseconds . seconds ;
375+ const dateSeconds = Date . now ( ) / 1000 ;
376+ assert . ok ( IsClose . isClose ( seconds , dateSeconds , 1 ) ) ;
377+ } ) ;
378+
368379 it ( 'node.getNodeNames' , function ( ) {
369380 var nodeNames = node . getNodeNames ( ) ;
370381
Original file line number Diff line number Diff line change @@ -173,8 +173,17 @@ declare module 'rclnodejs' {
173173 */
174174 getClock ( ) : Clock ;
175175
176+ /**
177+ * Get the current time using the node's clock.
178+ *
179+ * @returns The current time.
180+ */
181+ now ( ) : Time ;
182+
176183 /**
177184 * Get the nodeOptions provided through the constructor.
185+ *
186+ * @returns The nodeOptions.
178187 */
179188 options ( ) : NodeOptions ;
180189
You can’t perform that action at this time.
0 commit comments