Skip to content

Commit c9c9209

Browse files
wayneparrottMinggang Wang
authored andcommitted
fix #531 time.secondsAndNanoseconds (#533)
Correct Time.secondsAndNanoseconds error Currently, after calling function secondsAndNanoseconds of Time object, the value of it will be changed which should keep the same as it is. This patch corrects this wrong behaviour and a unit test for this is also added. Fix #531
1 parent d2724ff commit c9c9209

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/time.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class Time {
9797
*/
9898

9999
get secondsAndNanoseconds() {
100-
let seconds = this._nanoseconds.divide(1e9).toNumber();
101-
let nanoseconds = this._nanoseconds.mod(1e9).toNumber();
102-
return {seconds, nanoseconds};
100+
const seconds = int64.from(this._nanoseconds).divide(1e9).toNumber();
101+
const nanoseconds = int64.from(this._nanoseconds).mod(1e9).toNumber();
102+
return { seconds, nanoseconds };
103103
}
104104

105105
/**

test/test-time.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ describe('rclnodejs Time/Clock testing', function() {
148148
assert.throws(() => {
149149
time.add(result);
150150
}, TypeError);
151+
152+
let nanos = time._nanoseconds;
153+
time.secondsAndNanoseconds;
154+
assert.strictEqual(time._nanoseconds, nanos);
151155
});
152156

153157
it('Test duration functions', function() {

0 commit comments

Comments
 (0)