From ee51d384c3466012731efedd36c0bc857b95e3b7 Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Wed, 14 Jan 2026 18:06:44 +0800 Subject: [PATCH] Correct the type of return value for Time.toMsg() --- lib/time.js | 4 ++-- test/test-time.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/time.js b/lib/time.js index c7fa80c6..83e11416 100644 --- a/lib/time.js +++ b/lib/time.js @@ -352,8 +352,8 @@ class Time { toMsg() { const secondsAndNanoseconds = this.secondsAndNanoseconds; return { - sec: secondsAndNanoseconds.seconds, - nanosec: secondsAndNanoseconds.nanoseconds, + sec: Number(secondsAndNanoseconds.seconds), + nanosec: Number(secondsAndNanoseconds.nanoseconds), }; } diff --git a/test/test-time.js b/test/test-time.js index 9612a4fc..fae5a78f 100644 --- a/test/test-time.js +++ b/test/test-time.js @@ -48,6 +48,11 @@ describe('rclnodejs Time/Clock testing', function () { assert.strictEqual(time.nanoseconds, 1000000064n); assert.strictEqual(time.clockType, ClockType.ROS_TIME); + // Test with number types (compatible with updated interface) + time = Time.fromMsg({ sec: 1, nanosec: 64 }); + assert.strictEqual(time.nanoseconds, 1000000064n); + assert.strictEqual(time.clockType, ClockType.ROS_TIME); + assert.throws(() => { new Time(1n, 1n, 'SYSTEM_TIME'); }, rclnodejs.TypeValidationError); @@ -200,7 +205,9 @@ describe('rclnodejs Time/Clock testing', function () { let time = new Time(100n, 200n); let msg = time.toMsg(); - assert.strictEqual(msg.sec, 100n); - assert.strictEqual(msg.nanosec, 200n); + assert.strictEqual(msg.sec, 100); + assert.strictEqual(msg.nanosec, 200); + assert.strictEqual(typeof msg.sec, 'number'); + assert.strictEqual(typeof msg.nanosec, 'number'); }); });