From 0f92a31f599697db879b449f9ad5ca19da2e8a51 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 26 Oct 2023 12:31:44 -0700 Subject: [PATCH] feat: rounds expiry down to nearest minute --- packages/agent/src/agent/http/transforms.test.ts | 6 +++--- packages/agent/src/agent/http/transforms.ts | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/agent/src/agent/http/transforms.test.ts b/packages/agent/src/agent/http/transforms.test.ts index 97bb31fc4..7521309c5 100644 --- a/packages/agent/src/agent/http/transforms.test.ts +++ b/packages/agent/src/agent/http/transforms.test.ts @@ -1,15 +1,15 @@ import { Expiry } from './transforms'; jest.useFakeTimers(); -test('it should round down to the nearest second', () => { +test('it should round down to the nearest minute', () => { // 2021-04-26T17:47:11.314Z - high precision jest.setSystemTime(new Date(1619459231314)); const expiry = new Expiry(5 * 60 * 1000); - expect(expiry['_value']).toEqual(BigInt(1619459471000000000)); + expect(expiry['_value']).toEqual(BigInt(1619459460000000000)); const expiry_as_date_string = new Date( Number(expiry['_value'] / BigInt(1_000_000)), ).toISOString(); - expect(expiry_as_date_string).toBe('2021-04-26T17:51:11.000Z'); + expect(expiry_as_date_string).toBe('2021-04-26T17:51:00.000Z'); }); diff --git a/packages/agent/src/agent/http/transforms.ts b/packages/agent/src/agent/http/transforms.ts index 890e64f82..ea0dfedc1 100644 --- a/packages/agent/src/agent/http/transforms.ts +++ b/packages/agent/src/agent/http/transforms.ts @@ -24,7 +24,12 @@ export class Expiry { // round down to the nearest second const ingress_as_seconds = raw_value / BigInt(1_000_000_000); - const rounded_down_nanos = ingress_as_seconds * BigInt(1_000_000_000); + + // round down to nearest minute + const ingress_as_minutes = ingress_as_seconds / BigInt(60); + + const rounded_down_nanos = ingress_as_minutes * BigInt(60) * BigInt(1_000_000_000); + this._value = rounded_down_nanos; }