Skip to content

Commit

Permalink
fix: it's just rude to assign to date now (#1435)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Sep 24, 2024
1 parent dcef47a commit 1a53339
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { PostHog } from '../../posthog-core'
import { DecideResponse, FlagVariant, NetworkRecordOptions, NetworkRequest, Properties } from '../../types'
import { EventType, type eventWithTime, IncrementalSource, type listenerHandler, RecordPlugin } from '@rrweb/types'
import { timestamp } from '../../utils'

import { isBoolean, isFunction, isNullish, isNumber, isObject, isString, isUndefined } from '../../utils/type-utils'
import { logger } from '../../utils/logger'
Expand Down Expand Up @@ -492,7 +491,7 @@ export class SessionRecording {
payload: [JSON.stringify(message)],
},
},
timestamp: timestamp(),
timestamp: Date.now(),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getQueryParam, convertToURL } from './request-utils'
import { isNull } from './type-utils'
import { Properties } from '../types'
import Config from '../config'
import { each, extend, stripEmptyProperties, stripLeadingDollar, timestamp } from './index'
import { each, extend, stripEmptyProperties, stripLeadingDollar } from './index'
import { document, location, userAgent, window } from './globals'
import { detectBrowser, detectBrowserVersion, detectDevice, detectDeviceType, detectOS } from './user-agent-utils'

Expand Down Expand Up @@ -211,7 +211,7 @@ export const Info = {
$lib: 'web',
$lib_version: Config.LIB_VERSION,
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
$time: timestamp() / 1000, // epoch time in seconds
$time: Date.now() / 1000, // epoch time in seconds
}
)
},
Expand Down
9 changes: 0 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ export const isValidRegex = function (str: string): boolean {
return true
}

export const timestamp = function (): number {
Date.now =
Date.now ||
function () {
return +new Date()
}
return Date.now()
}

export const trySafe = function <T>(fn: () => T): T | undefined {
try {
return fn()
Expand Down

0 comments on commit 1a53339

Please sign in to comment.