Skip to content

Commit

Permalink
fix(opentelemetry-core): fixed timeInputToHrTime when time is Date ty…
Browse files Browse the repository at this point in the history
…pe (#1784)

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
zoomchan-cxj and dyladan committed Jan 12, 2021
1 parent 0545122 commit 73b8bd0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/common/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/test/common/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 73b8bd0

Please sign in to comment.