Skip to content

Commit 28c9e88

Browse files
authored
Docs: Document the HrTime format (#2604)
1 parent 491dd80 commit 28c9e88

File tree

1 file changed

+9
-1
lines changed
  • packages/opentelemetry-core/src/common

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ const NANOSECOND_DIGITS = 9;
2222
const SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
2323

2424
/**
25-
* Converts a number to HrTime
25+
* Converts a number to HrTime, HrTime = [number, number].
26+
* The first number is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
27+
* The second number represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
28+
* For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
29+
* numberToHrtime calculates the first number by converting and truncating the Epoch time in milliseconds to seconds:
30+
* HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
31+
* numberToHrtime calculates the second number by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
32+
* HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * SECOND_TO_NANOSECONDS = 150000000.
33+
* This is represented in HrTime format as [1609504210, 150000000].
2634
* @param epochMillis
2735
*/
2836
function numberToHrtime(epochMillis: number): api.HrTime {

0 commit comments

Comments
 (0)