Skip to content

Commit

Permalink
Fix timestamp calculation
Browse files Browse the repository at this point in the history
We had an incorrect calculation in place for customs timestamps. Add a
test for that and fix it.
  • Loading branch information
thijsc committed Aug 19, 2021
1 parent fb354d1 commit f0256d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/nodejs/.changesets/timestamp-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bump: "patch"
---

Bug fix in custom timestamp calculation
12 changes: 12 additions & 0 deletions packages/nodejs/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getAgentTimestamps } from "../utils"

describe("Utils", () => {
describe("getAgentTimestamps", () => {
it("calculates the timeestamp", () => {
const timestamp = getAgentTimestamps(1_589_192_966_108)

expect(timestamp.sec).toEqual(1_589_192_966)
expect(timestamp.nsec).toEqual(108000000)
})
})
})
5 changes: 3 additions & 2 deletions packages/nodejs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export function getPackageVerson(basedir: string): string {
* @function
*/
export function getAgentTimestamps(timestamp: number) {
const sec = Math.round(timestamp / 1000)
return {
sec: Math.round(timestamp / 1000), // seconds
nsec: Math.round(timestamp * 1e6) // nanoseconds
sec: sec, // seconds
nsec: timestamp * 1e6 - sec * 1e9 // nanoseconds
}
}

0 comments on commit f0256d3

Please sign in to comment.