diff --git a/packages/browser/test/integration/polyfills/raf.js b/packages/browser/test/integration/polyfills/raf.js index 1d6bc9935c65..2b84451134d2 100644 --- a/packages/browser/test/integration/polyfills/raf.js +++ b/packages/browser/test/integration/polyfills/raf.js @@ -17,7 +17,7 @@ if (!window.requestAnimationFrame) window.requestAnimationFrame = function (callback, _element) { - var currTime = new Date().getTime(); + var currTime = Date.now(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function () { callback(currTime + timeToCall); diff --git a/packages/integrations/test/offline.test.ts b/packages/integrations/test/offline.test.ts index 624c166763b8..1dac96bc1e53 100644 --- a/packages/integrations/test/offline.test.ts +++ b/packages/integrations/test/offline.test.ts @@ -194,7 +194,7 @@ function prepopulateEvents(count: number = 1): void { for (let i = 0; i < count; i++) { events.push({ message: 'There was an error!', - timestamp: new Date().getTime(), + timestamp: Date.now(), }); } } diff --git a/packages/replay/src/coreHandlers/handleHistory.ts b/packages/replay/src/coreHandlers/handleHistory.ts index 4732c0118831..f75998689c01 100644 --- a/packages/replay/src/coreHandlers/handleHistory.ts +++ b/packages/replay/src/coreHandlers/handleHistory.ts @@ -9,7 +9,7 @@ interface HistoryHandlerData { function handleHistory(handlerData: HistoryHandlerData): ReplayPerformanceEntry { const { from, to } = handlerData; - const now = new Date().getTime() / 1000; + const now = Date.now() / 1000; return { type: 'navigation.push', diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index c42a5cc5b9b6..df2f3e6c9774 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -78,7 +78,7 @@ export class ReplayContainer implements ReplayContainerInterface { /** * Timestamp of the last user activity. This lives across sessions. */ - private _lastActivity: number = new Date().getTime(); + private _lastActivity: number = Date.now(); /** * Is the integration currently active? @@ -108,7 +108,7 @@ export class ReplayContainer implements ReplayContainerInterface { traceIds: new Set(), urls: [], earliestEvent: null, - initialTimestamp: new Date().getTime(), + initialTimestamp: Date.now(), initialUrl: '', }; @@ -442,7 +442,7 @@ export class ReplayContainer implements ReplayContainerInterface { this._clearContext(); this._context.initialUrl = url; - this._context.initialTimestamp = new Date().getTime(); + this._context.initialTimestamp = Date.now(); this._context.urls.push(url); } @@ -634,14 +634,14 @@ export class ReplayContainer implements ReplayContainerInterface { /** * Update user activity (across session lifespans) */ - private _updateUserActivity(_lastActivity: number = new Date().getTime()): void { + private _updateUserActivity(_lastActivity: number = Date.now()): void { this._lastActivity = _lastActivity; } /** * Updates the session's last activity timestamp */ - private _updateSessionActivity(_lastActivity: number = new Date().getTime()): void { + private _updateSessionActivity(_lastActivity: number = Date.now()): void { if (this.session) { this.session.lastActivity = _lastActivity; this._maybeSaveSession(); @@ -768,7 +768,7 @@ export class ReplayContainer implements ReplayContainerInterface { eventContext, session: this.session, options: this.getOptions(), - timestamp: new Date().getTime(), + timestamp: Date.now(), }); } catch (err) { this._handleException(err); diff --git a/packages/replay/src/session/Session.ts b/packages/replay/src/session/Session.ts index d20fa0daf33c..9089ea54c76c 100644 --- a/packages/replay/src/session/Session.ts +++ b/packages/replay/src/session/Session.ts @@ -7,7 +7,7 @@ import { isSampled } from '../util/isSampled'; * Get a session with defaults & applied sampling. */ export function makeSession(session: Partial & { sampled: Sampled }): Session { - const now = new Date().getTime(); + const now = Date.now(); const id = session.id || uuid4(); // Note that this means we cannot set a started/lastActivity of `0`, but this should not be relevant outside of tests. const started = session.started || now; diff --git a/packages/replay/src/util/addEvent.ts b/packages/replay/src/util/addEvent.ts index 357ecaca0e61..b32050665519 100644 --- a/packages/replay/src/util/addEvent.ts +++ b/packages/replay/src/util/addEvent.ts @@ -31,7 +31,7 @@ export async function addEvent( // page has been left open and idle for a long period of time and user // comes back to trigger a new session. The performance entries rely on // `performance.timeOrigin`, which is when the page first opened. - if (timestampInMs + replay.timeouts.sessionIdle < new Date().getTime()) { + if (timestampInMs + replay.timeouts.sessionIdle < Date.now()) { return null; } diff --git a/packages/replay/src/util/addMemoryEntry.ts b/packages/replay/src/util/addMemoryEntry.ts index 8d31e06cd9d9..92431e45f2d4 100644 --- a/packages/replay/src/util/addMemoryEntry.ts +++ b/packages/replay/src/util/addMemoryEntry.ts @@ -33,7 +33,7 @@ function createMemoryEntry(memoryEntry: MemoryInfo): ReplayMemoryEntry { const { jsHeapSizeLimit, totalJSHeapSize, usedJSHeapSize } = memoryEntry; // we don't want to use `getAbsoluteTime` because it adds the event time to the // time origin, so we get the current timestamp instead - const time = new Date().getTime() / 1000; + const time = Date.now() / 1000; return { type: 'memory', name: 'memory', diff --git a/packages/replay/src/util/createBreadcrumb.ts b/packages/replay/src/util/createBreadcrumb.ts index b9f7527b0180..b8ff6097d571 100644 --- a/packages/replay/src/util/createBreadcrumb.ts +++ b/packages/replay/src/util/createBreadcrumb.ts @@ -9,7 +9,7 @@ export function createBreadcrumb( breadcrumb: Pick & Partial>, ): Breadcrumb { return { - timestamp: new Date().getTime() / 1000, + timestamp: Date.now() / 1000, type: 'default', ...breadcrumb, }; diff --git a/packages/replay/test/fixtures/error.ts b/packages/replay/test/fixtures/error.ts index 6008f81209e1..046efa619539 100644 --- a/packages/replay/test/fixtures/error.ts +++ b/packages/replay/test/fixtures/error.ts @@ -1,7 +1,7 @@ import type { Event } from '@sentry/types'; export function Error(obj?: Event): any { - const timestamp = new Date().getTime() / 1000; + const timestamp = Date.now() / 1000; return { exception: { diff --git a/packages/replay/test/fixtures/transaction.ts b/packages/replay/test/fixtures/transaction.ts index 1e8ec7a3272a..9362749e7c3b 100644 --- a/packages/replay/test/fixtures/transaction.ts +++ b/packages/replay/test/fixtures/transaction.ts @@ -1,7 +1,7 @@ import type { Event, SeverityLevel } from '@sentry/types'; export function Transaction(traceId?: string, obj?: Partial): any { - const timestamp = new Date().getTime() / 1000; + const timestamp = Date.now() / 1000; return { contexts: { diff --git a/packages/replay/test/mocks/mockRrweb.ts b/packages/replay/test/mocks/mockRrweb.ts index cef95093d125..0c7ef971483d 100644 --- a/packages/replay/test/mocks/mockRrweb.ts +++ b/packages/replay/test/mocks/mockRrweb.ts @@ -19,7 +19,7 @@ export type RecordMock = jest.MockedFunction & RecordAdditio function createCheckoutPayload(isCheckout: boolean = true) { return { data: { isCheckout }, - timestamp: new Date().getTime(), + timestamp: Date.now(), type: isCheckout ? 2 : 3, }; } diff --git a/packages/replay/test/unit/coreHandlers/handleScope.test.ts b/packages/replay/test/unit/coreHandlers/handleScope.test.ts index c7ba7cdc75ce..2f46fafba635 100644 --- a/packages/replay/test/unit/coreHandlers/handleScope.test.ts +++ b/packages/replay/test/unit/coreHandlers/handleScope.test.ts @@ -24,7 +24,7 @@ describe('Unit | coreHandlers | handleScope', () => { } const testMsg = { - timestamp: new Date().getTime() / 1000, + timestamp: Date.now() / 1000, message: 'testing', category: 'console', }; diff --git a/packages/replay/test/unit/session/getSession.test.ts b/packages/replay/test/unit/session/getSession.test.ts index 4ac92b148e75..2e7d3ec969b7 100644 --- a/packages/replay/test/unit/session/getSession.test.ts +++ b/packages/replay/test/unit/session/getSession.test.ts @@ -17,7 +17,7 @@ const SAMPLE_RATES = { errorSampleRate: 0, }; -function createMockSession(when: number = new Date().getTime()) { +function createMockSession(when: number = Date.now()) { return makeSession({ id: 'test_session_id', segmentId: 0, @@ -66,7 +66,7 @@ describe('Unit | session | getSession', () => { }); it('creates a non-sticky session, regardless of session existing in sessionStorage', function () { - saveSession(createMockSession(new Date().getTime() - 10000)); + saveSession(createMockSession(Date.now() - 10000)); const { session } = getSession({ timeouts: { @@ -93,8 +93,8 @@ describe('Unit | session | getSession', () => { ...SAMPLE_RATES, currentSession: makeSession({ id: 'old_session_id', - lastActivity: new Date().getTime() - 1001, - started: new Date().getTime() - 1001, + lastActivity: Date.now() - 1001, + started: Date.now() - 1001, segmentId: 0, sampled: 'session', }), @@ -142,7 +142,7 @@ describe('Unit | session | getSession', () => { }); it('fetches an existing sticky session', function () { - const now = new Date().getTime(); + const now = Date.now(); saveSession(createMockSession(now)); const { session } = getSession({ @@ -168,8 +168,8 @@ describe('Unit | session | getSession', () => { }); it('fetches an expired sticky session', function () { - const now = new Date().getTime(); - saveSession(createMockSession(new Date().getTime() - 2000)); + const now = Date.now(); + saveSession(createMockSession(Date.now() - 2000)); const { session } = getSession({ timeouts: { diff --git a/packages/svelte/test/performance.test.ts b/packages/svelte/test/performance.test.ts index cbfd320f35bd..1e02eb549d5f 100644 --- a/packages/svelte/test/performance.test.ts +++ b/packages/svelte/test/performance.test.ts @@ -80,7 +80,7 @@ describe('Sentry.trackComponent()', () => { it('creates an update span, when the component is updated', async () => { // Make the finish() function actually end the initSpan testInitSpan.finish.mockImplementation(() => { - testInitSpan.endTimestamp = new Date().getTime(); + testInitSpan.endTimestamp = Date.now(); }); // first we create the component @@ -171,7 +171,7 @@ describe('Sentry.trackComponent()', () => { it("doesn't record update spans, if there's no ongoing transaction at that time", async () => { // Make the finish() function actually end the initSpan testInitSpan.finish.mockImplementation(() => { - testInitSpan.endTimestamp = new Date().getTime(); + testInitSpan.endTimestamp = Date.now(); }); // first we create the component