Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.6 KB
Raw Blame
import { useValues } from 'kea'

import { Dayjs } from 'lib/dayjs'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { cn } from 'lib/utils/css-classes'
import { formatLocalizedDate, formatLocalizedTime } from 'lib/utils/datetime'
import { colonDelimitedDuration } from 'lib/utils/durations'

import { TimestampFormat } from '../player/playerSettingsLogic'
import { playerSettingsLogic } from '../player/playerSettingsLogic'

export function ItemTimeDisplay({
    timestamp,
    timeInRecording,
    className,
}: {
    timestamp: Dayjs
    timeInRecording: number
    className?: string
}): JSX.Element {
    const { timestampFormat } = useValues(playerSettingsLogic)

    return (
        <div className={cn('px-2 py-1 text-xs min-w-18 text-center', className)}>
            {timestampFormat !== TimestampFormat.Relative ? (
                (timestampFormat === TimestampFormat.UTC ? timestamp.tz('UTC') : timestamp).format(
                    `${formatLocalizedDate()}, ${formatLocalizedTime()}`
                )
            ) : (
                <>
                    {timeInRecording < 0 ? (
                        <Tooltip
                            title="This event occurred before the recording started, likely as the page was loading."
                            placement="left"
                        >
                            <span className="text-secondary">load</span>
                        </Tooltip>
                    ) : (
                        colonDelimitedDuration(timeInRecording / 1000, null)
                    )}
                </>
            )}
        </div>
    )
}