/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { useTranslation } from 'react-i18next' import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip' import { toIntlLocale } from '@/i18n/languages' import { formatTimestampRelative, formatTimestampToDate } from '@/lib/format' import { cn } from '@/lib/utils' interface TimestampCellProps { timestamp: number now?: number format?: 'relative' | 'absolute' locale?: string justNowLabel: string className?: string } export function TimestampCell(props: TimestampCellProps) { if (!props.timestamp || props.timestamp === -1) { return - } const timestampMs = props.timestamp * 1000 const absoluteTime = formatTimestampToDate(props.timestamp) if (props.format === 'absolute') { return ( ) } const now = props.now ?? Date.now() const isJustNow = timestampMs <= now && now - timestampMs < 60_000 const relativeTime = isJustNow ? props.justNowLabel : formatTimestampRelative(props.timestamp, 'seconds', props.locale) const [relativePrefix, relativeNumber, relativeSuffix] = relativeTime.split( /(\p{Number}+(?:[.,\u00a0\u202f]\p{Number}+)*)/u ) return ( } > {relativePrefix} {relativeNumber && ( {relativeNumber} )} {relativeSuffix} {absoluteTime} ) } export function ActivityTimeCell(props: { createdAt: number lastAt: number lastLabel: string lastClassName?: string now?: number format?: 'relative' | 'absolute' layout?: 'rows' | 'columns' }) { const { t, i18n } = useTranslation() const locale = toIntlLocale(i18n.resolvedLanguage || i18n.language) return (
{t('Created')} {props.lastLabel}
) }