From f1ee78ab94f70c09df6d205fbe15f364a0cc1f4a Mon Sep 17 00:00:00 2001 From: shermanchen Date: Wed, 30 Dec 2020 11:08:48 +0800 Subject: [PATCH] fix(opentelemetry-core): fixed timeInputToHrTime when time is Date type --- packages/opentelemetry-core/src/common/time.ts | 2 +- packages/opentelemetry-core/test/common/time.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-core/src/common/time.ts b/packages/opentelemetry-core/src/common/time.ts index 893fa03dc6..ce56ab8605 100644 --- a/packages/opentelemetry-core/src/common/time.ts +++ b/packages/opentelemetry-core/src/common/time.ts @@ -85,7 +85,7 @@ export function timeInputToHrTime(time: api.TimeInput): api.HrTime { return numberToHrtime(time); } } else if (time instanceof Date) { - return [time.getTime(), 0]; + return numberToHrtime(time.getTime()); } else { throw TypeError('Invalid input type'); } diff --git a/packages/opentelemetry-core/test/common/time.test.ts b/packages/opentelemetry-core/test/common/time.test.ts index bfbace2df3..8cbe355c4a 100644 --- a/packages/opentelemetry-core/test/common/time.test.ts +++ b/packages/opentelemetry-core/test/common/time.test.ts @@ -109,9 +109,9 @@ describe('time', () => { describe('#timeInputToHrTime', () => { it('should convert Date hrTime', () => { - const timeInput = new Date(); + const timeInput = new Date(1609297640313); const output = timeInputToHrTime(timeInput); - assert.deepStrictEqual(output, [timeInput.getTime(), 0]); + assert.deepStrictEqual(output, [1609297640, 312999964]); }); it('should convert epoch milliseconds hrTime', () => {