Skip to content

Commit 7b8fbf6

Browse files
committed
fix(opentelemetry-core): fixed timeInputToHrTime when time is Date type
1 parent 56e46f4 commit 7b8fbf6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/opentelemetry-core/src/common/time.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function timeInputToHrTime(time: api.TimeInput): api.HrTime {
8585
return numberToHrtime(time);
8686
}
8787
} else if (time instanceof Date) {
88-
return [time.getTime(), 0];
88+
return numberToHrtime(time.getTime());
8989
} else {
9090
throw TypeError('Invalid input type');
9191
}

packages/opentelemetry-core/test/common/time.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ describe('time', () => {
111111
it('should convert Date hrTime', () => {
112112
const timeInput = new Date();
113113
const output = timeInputToHrTime(timeInput);
114-
assert.deepStrictEqual(output, [timeInput.getTime(), 0]);
114+
const epochSeconds = timeInput.getTime() / 1000;
115+
const seconds = Math.trunc(epochSeconds);
116+
const nanos =
117+
Number((epochSeconds - seconds).toFixed(9)) * Math.pow(10, 9);
118+
assert.deepStrictEqual(output, [seconds, nanos]);
115119
});
116120

117121
it('should convert epoch milliseconds hrTime', () => {

0 commit comments

Comments
 (0)