File tree Expand file tree Collapse file tree 4 files changed +20
-11
lines changed
Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -251,12 +251,13 @@ class Time {
251251
252252 /**
253253 * Create a Time object from a message of builtin_interfaces/msg/Time
254- * @param {object } msg - The message to be created from.
255- * @param {ClockType } [clockType=Clock.ClockType.SYSTEM_TIME] - The type of the time object.
254+ * @param {object } msg - The builtin_interfaces.msg.Time message to be
255+ * created from.
256+ * @param {ClockType } [clockType=Clock.ClockType.ROS_TIME] - The type of the time object.
256257 * @return {Time } Return the created Time object.
257258 */
258259 static fromMsg ( msg , clockType = ClockType . ROS_TIME ) {
259- return new Time ( msg . sec , msg . nanoseconds , clockType ) ;
260+ return new Time ( msg . sec , msg . nanosec , clockType ) ;
260261 }
261262}
262263
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ describe('rclnodejs Time/Clock testing', function() {
4545 time = new Time ( 0 , '9223372036854775807' ) ;
4646 assert . strictEqual ( time . nanoseconds , '9223372036854775807' ) ;
4747
48+ time = Time . fromMsg ( { sec : 1 , nanosec : 64 } ) ;
49+ assert . strictEqual ( time . nanoseconds , 1000000064 ) ;
50+ assert . strictEqual ( time . clockType , ClockType . ROS_TIME ) ;
51+
4852 assert . throws ( ( ) => {
4953 new Time ( 1 , 1 , 'SYSTEM_TIME' ) ;
5054 } , TypeError ) ;
Original file line number Diff line number Diff line change @@ -219,10 +219,11 @@ duration1.gte(duration2);
219219const time1 = new rclnodejs . Time ( 100 , 100 ) ;
220220
221221// $ExpectType Time
222- const time2 = rclnodejs . Time . fromMsg (
223- 'helloworld' ,
224- rclnodejs . ClockType . SYSTEM_TIME
225- ) ;
222+ const time2 = rclnodejs . Time . fromMsg ( { sec : 0 , nanosec : 0 } ) ;
223+
224+ // $ExpectType Time
225+ const time3 =
226+ rclnodejs . Time . fromMsg ( { sec : 0 , nanosec : 0 } , rclnodejs . ClockType . ROS_TIME ) ;
226227
227228// $ExpectType ClockType
228229time1 . clockType ;
Original file line number Diff line number Diff line change 1- import { Message } from 'rclnodejs' ;
1+
2+ // eslint-disable-next-line camelcase
3+ import { Message , builtin_interfaces } from 'rclnodejs' ;
24
35declare module 'rclnodejs' {
46 /**
@@ -102,10 +104,11 @@ declare module 'rclnodejs' {
102104 /**
103105 * Create a Time object from a message of builtin_interfaces/msg/Time
104106 *
105- * @param msg - The message to be created from.
106- * @param clockType- The type of the time object.
107+ * @param msg - The Time message to be created from.
108+ * @param clockType - The type of the time object. Default is ClockType.ROS_TIME
107109 * @returns The new Time.
108110 */
109- static fromMsg ( msg : Message , clockType : ClockType ) : Time ;
111+ // eslint-disable-next-line camelcase
112+ static fromMsg ( msg : builtin_interfaces . msg . Time , clockType ?: ClockType ) : Time ;
110113 }
111114}
You can’t perform that action at this time.
0 commit comments