File tree 2 files changed +6
-2
lines changed
packages/opentelemetry-core
2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export function timeInputToHrTime(time: api.TimeInput): api.HrTime {
85
85
return numberToHrtime ( time ) ;
86
86
}
87
87
} else if ( time instanceof Date ) {
88
- return [ time . getTime ( ) , 0 ] ;
88
+ return numberToHrtime ( time . getTime ( ) ) ;
89
89
} else {
90
90
throw TypeError ( 'Invalid input type' ) ;
91
91
}
Original file line number Diff line number Diff line change @@ -111,7 +111,11 @@ describe('time', () => {
111
111
it ( 'should convert Date hrTime' , ( ) => {
112
112
const timeInput = new Date ( ) ;
113
113
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 ] ) ;
115
119
} ) ;
116
120
117
121
it ( 'should convert epoch milliseconds hrTime' , ( ) => {
You can’t perform that action at this time.
0 commit comments