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', () => {