Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(date): replace timeAgo with RelativeTime component (#584)

Corentin Thomassetf4740ba59a63
diff --git a/.changeset/bumpy-dolls-refuse.md b/.changeset/bumpy-dolls-refuse.md
new file mode 100644
index 00000000..6825ad65
--- /dev/null
+++ b/.changeset/bumpy-dolls-refuse.md
@@ -0,0 +1,5 @@
+---
+"@papra/docker": patch
+---
+
+Reduced client bundle size by removing date-fns
diff --git a/apps/papra-client/package.json b/apps/papra-client/package.json
index 2ac5bff3..dd471a37 100644
--- a/apps/papra-client/package.json
+++ b/apps/papra-client/package.json
@@ -43,7 +43,6 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk-solid": "^1.1.2",
- "date-fns": "^4.1.0",
"ofetch": "^1.4.1",
"posthog-js-lite": "^4.1.5",
"radix3": "^1.1.2",
diff --git a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
index eb5d4fbf..21f4a794 100644
--- a/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
+++ b/apps/papra-client/src/modules/documents/components/documents-list.component.tsx
@@ -1,4 +1,3 @@
-import type { TooltipTriggerProps } from '@kobalte/core/tooltip';
import type { ColumnDef } from '@tanstack/solid-table';
import type { Accessor, Component, Setter } from 'solid-js';
import type { Document } from '../documents.types';
@@ -7,13 +6,12 @@ import { formatBytes } from '@corentinth/chisels';
import { A } from '@solidjs/router';
import { createSolidTable, flexRender, getCoreRowModel, getPaginationRowModel } from '@tanstack/solid-table';
import { For, Match, Show, Switch } from 'solid-js';
-import { timeAgo } from '@/modules/shared/date/time-ago';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { cn } from '@/modules/shared/style/cn';
import { TagLink } from '@/modules/tags/components/tag.component';
import { Button } from '@/modules/ui/components/button';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/modules/ui/components/select';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/modules/ui/components/table';
-import { Tooltip, TooltipContent, TooltipTrigger } from '@/modules/ui/components/tooltip';
import { getDocumentIcon, getDocumentNameExtension, getDocumentNameWithoutExtension } from '../document.models';
import { DocumentManagementDropdown } from './document-management-dropdown.component';
@@ -25,13 +23,13 @@ type Pagination = {
export const createdAtColumn: ColumnDef<Document> = {
header: () => (<span class="hidden sm:block">Created at</span>),
accessorKey: 'createdAt',
- cell: data => <div class="text-muted-foreground hidden sm:block" title={data.getValue<Date>().toLocaleString()}>{timeAgo({ date: data.getValue<Date>() })}</div>,
+ cell: data => <RelativeTime class="text-muted-foreground hidden sm:block" date={data.getValue<Date>()} />,
};
export const deletedAtColumn: ColumnDef<Document> = {
header: () => (<span class="hidden sm:block">Deleted at</span>),
accessorKey: 'deletedAt',
- cell: data => <div class="text-muted-foreground hidden sm:block" title={data.getValue<Date>().toLocaleString()}>{timeAgo({ date: data.getValue<Date>() })}</div>,
+ cell: data => <RelativeTime class="text-muted-foreground hidden sm:block" date={data.getValue<Date>()} />,
};
export const standardActionsColumn: ColumnDef<Document> = {
@@ -92,17 +90,7 @@ export const DocumentsPaginatedList: Component<{
{' '}
-
{' '}
- <Tooltip>
- <TooltipTrigger as={(tooltipProps: TooltipTriggerProps) => (
- <span {...tooltipProps}>
- {timeAgo({ date: data.row.original.createdAt })}
- </span>
- )}
- />
- <TooltipContent>
- {data.row.original.createdAt.toLocaleString()}
- </TooltipContent>
- </Tooltip>
+ <RelativeTime date={data.row.original.createdAt} />
</div>
</div>
</div>
diff --git a/apps/papra-client/src/modules/documents/document.models.test.ts b/apps/papra-client/src/modules/documents/document.models.test.ts
index d5adcb9d..6d8a5b06 100644
--- a/apps/papra-client/src/modules/documents/document.models.test.ts
+++ b/apps/papra-client/src/modules/documents/document.models.test.ts
@@ -99,6 +99,98 @@ describe('files models', () => {
expect(daysBeforeDeletion).to.eql(undefined);
});
+
+ test('returns 0 when the permanent deletion date is today', () => {
+ const document = { deletedAt: new Date('2021-01-01') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2021-01-31');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(0);
+ });
+
+ test('returns negative days when the permanent deletion date has passed', () => {
+ const document = { deletedAt: new Date('2021-01-01') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2021-02-15');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(-15);
+ });
+
+ test('handles deletion that happened on the same day (considers time of day)', () => {
+ const document = { deletedAt: new Date('2021-01-10T08:00:00') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2021-01-10T14:00:00');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ // Since differenceInDays counts full days, and there's only 6 hours difference,
+ // the permanent deletion date (30 days from 08:00) is 29 full days from 14:00
+ expect(daysBeforeDeletion).to.eql(29);
+ });
+
+ test('handles very short retention periods', () => {
+ const document = { deletedAt: new Date('2021-01-10') };
+ const deletedDocumentsRetentionDays = 1;
+ const now = new Date('2021-01-10');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(1);
+ });
+
+ test('handles very long retention periods', () => {
+ const document = { deletedAt: new Date('2021-01-01') };
+ const deletedDocumentsRetentionDays = 365;
+ const now = new Date('2021-01-10');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(356);
+ });
+
+ test('handles zero retention days (immediate deletion)', () => {
+ const document = { deletedAt: new Date('2021-01-10') };
+ const deletedDocumentsRetentionDays = 0;
+ const now = new Date('2021-01-10');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(0);
+ });
+
+ test('handles dates across year boundaries', () => {
+ const document = { deletedAt: new Date('2020-12-20') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2021-01-05');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(14);
+ });
+
+ test('handles dates across leap year February', () => {
+ const document = { deletedAt: new Date('2020-02-15') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2020-02-20');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(25);
+ });
+
+ test('handles timestamp precision with hours and minutes', () => {
+ const document = { deletedAt: new Date('2021-01-01T23:59:59') };
+ const deletedDocumentsRetentionDays = 30;
+ const now = new Date('2021-01-02T00:00:01');
+
+ const daysBeforeDeletion = getDaysBeforePermanentDeletion({ document, deletedDocumentsRetentionDays, now });
+
+ expect(daysBeforeDeletion).to.eql(29);
+ });
});
describe('getDocumentNameWithoutExtension', () => {
diff --git a/apps/papra-client/src/modules/documents/document.models.ts b/apps/papra-client/src/modules/documents/document.models.ts
index 406c431c..4d859f89 100644
--- a/apps/papra-client/src/modules/documents/document.models.ts
+++ b/apps/papra-client/src/modules/documents/document.models.ts
@@ -1,5 +1,5 @@
import type { DocumentActivityEvent } from './documents.types';
-import { addDays, differenceInDays } from 'date-fns';
+import { IN_MS } from '../shared/utils/units';
export const iconByFileType = {
'*': 'i-tabler-file',
@@ -44,9 +44,12 @@ export function getDaysBeforePermanentDeletion({ document, deletedDocumentsReten
return undefined;
}
- const deletionDate = addDays(document.deletedAt, deletedDocumentsRetentionDays);
+ // Calculate the permanent deletion date by adding retention days to the deleted date
+ const deletionDate = new Date(document.deletedAt);
+ deletionDate.setDate(deletionDate.getDate() + deletedDocumentsRetentionDays);
- const daysBeforeDeletion = differenceInDays(deletionDate, now);
+ // Calculate the difference in milliseconds and convert to days
+ const daysBeforeDeletion = Math.floor((deletionDate.getTime() - now.getTime()) / IN_MS.DAY);
return daysBeforeDeletion;
}
diff --git a/apps/papra-client/src/modules/documents/pages/deleted-documents.page.tsx b/apps/papra-client/src/modules/documents/pages/deleted-documents.page.tsx
index 48e05809..4765df7c 100644
--- a/apps/papra-client/src/modules/documents/pages/deleted-documents.page.tsx
+++ b/apps/papra-client/src/modules/documents/pages/deleted-documents.page.tsx
@@ -4,9 +4,9 @@ import { useParams } from '@solidjs/router';
import { keepPreviousData, useMutation, useQuery } from '@tanstack/solid-query';
import { createSignal, Show, Suspense } from 'solid-js';
import { useConfig } from '@/modules/config/config.provider';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
import { useConfirmModal } from '@/modules/shared/confirm';
-import { timeAgo } from '@/modules/shared/date/time-ago';
import { queryClient } from '@/modules/shared/query/query-client';
import { Alert, AlertDescription } from '@/modules/ui/components/alert';
import { Button } from '@/modules/ui/components/button';
@@ -199,7 +199,7 @@ export const DeletedDocumentsPage: Component = () => {
<div class="text-muted-foreground hidden sm:block">
{t('documents.deleted.deleted-at')}
{' '}
- <span class="text-foreground font-bold" title={data.row.original.deletedAt?.toLocaleString()}>{timeAgo({ date: data.row.original.deletedAt! })}</span>
+ <RelativeTime class="text-foreground font-bold" date={data.row.original.deletedAt!} />
</div>
),
},
diff --git a/apps/papra-client/src/modules/documents/pages/document.page.tsx b/apps/papra-client/src/modules/documents/pages/document.page.tsx
index 515cdf81..53fb2b35 100644
--- a/apps/papra-client/src/modules/documents/pages/document.page.tsx
+++ b/apps/papra-client/src/modules/documents/pages/document.page.tsx
@@ -5,8 +5,8 @@ import { A, useNavigate, useParams, useSearchParams } from '@solidjs/router';
import { useInfiniteQuery, useQuery } from '@tanstack/solid-query';
import { createEffect, createSignal, For, Match, Show, Suspense, Switch } from 'solid-js';
import { useConfig } from '@/modules/config/config.provider';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
-import { timeAgo } from '@/modules/shared/date/time-ago';
import { downloadFile } from '@/modules/shared/files/download';
import { DocumentTagPicker } from '@/modules/tags/components/tag-picker.component';
import { TagLink } from '@/modules/tags/components/tag.component';
@@ -83,7 +83,7 @@ const ActivityItem: Component<{ activity: DocumentActivity }> = (props) => {
</Switch>
<div class="flex items-center gap-1 text-xs text-muted-foreground">
- <span title={props.activity.createdAt.toLocaleString()}>{timeAgo({ date: props.activity.createdAt })}</span>
+ <RelativeTime date={props.activity.createdAt} />
<Show when={props.activity.user}>
{getUser => (
<span>{te('activity.document.user.name', { name: <A href={`/organizations/${params.organizationId}/members`} class="underline hover:text-primary transition">{getUser().name}</A> })}</span>
@@ -99,7 +99,7 @@ const tabs = ['info', 'content', 'activity'] as const;
type Tab = typeof tabs[number];
export const DocumentPage: Component = () => {
- const { t } = useI18n();
+ const { t, formatRelativeTime } = useI18n();
const params = useParams();
const [searchParams, setSearchParams] = useSearchParams();
const { deleteDocument } = useDeleteDocument();
@@ -325,12 +325,12 @@ export const DocumentPage: Component = () => {
},
{
label: t('documents.info.created-at'),
- value: timeAgo({ date: getDocument().createdAt }),
+ value: formatRelativeTime(getDocument().createdAt),
icon: 'i-tabler-calendar',
},
{
label: t('documents.info.updated-at'),
- value: getDocument().updatedAt ? timeAgo({ date: getDocument().updatedAt! }) : <span class="text-muted-foreground">{t('documents.info.never')}</span>,
+ value: getDocument().updatedAt ? formatRelativeTime(getDocument().updatedAt!) : <span class="text-muted-foreground">{t('documents.info.never')}</span>,
icon: 'i-tabler-calendar',
},
]}
diff --git a/apps/papra-client/src/modules/i18n/components/RelativeTime.tsx b/apps/papra-client/src/modules/i18n/components/RelativeTime.tsx
new file mode 100644
index 00000000..8b27648a
--- /dev/null
+++ b/apps/papra-client/src/modules/i18n/components/RelativeTime.tsx
@@ -0,0 +1,20 @@
+import type { Component, JSX } from 'solid-js';
+import type { CoercibleDate } from '@/modules/shared/date/date.types';
+import { splitProps } from 'solid-js';
+import { coerceDate } from '@/modules/shared/date/coerce-date';
+import { useI18n } from '../i18n.provider';
+
+export const RelativeTime: Component<{ date: CoercibleDate } & JSX.IntrinsicElements['time']> = (props) => {
+ const [local, rest] = splitProps(props, ['date', 'title', 'dateTime']);
+ const { formatRelativeTime, formatDate } = useI18n();
+
+ return (
+ <time
+ title={local.title ?? formatDate(local.date, { dateStyle: 'short', timeStyle: 'short' })}
+ dateTime={local.dateTime ?? coerceDate(local.date).toISOString()}
+ {...rest}
+ >
+ {formatRelativeTime(local.date)}
+ </time>
+ );
+};
diff --git a/apps/papra-client/src/modules/i18n/i18n.models.ts b/apps/papra-client/src/modules/i18n/i18n.models.ts
index a53db2b7..16b594bc 100644
--- a/apps/papra-client/src/modules/i18n/i18n.models.ts
+++ b/apps/papra-client/src/modules/i18n/i18n.models.ts
@@ -1,6 +1,8 @@
import type { JSX } from 'solid-js';
+import type { CoercibleDate } from '../shared/date/date.types';
import type { Locale } from './i18n.provider';
import { createBranchlet } from '@branchlet/core';
+import { coerceDate } from '../shared/date/coerce-date';
import { IN_MS } from '../shared/utils/units';
// This tries to get the most preferred language compatible with the supported languages
@@ -74,16 +76,16 @@ export function createFragmentTranslator<Dict extends Record<string, string>>({
}
export function createDateFormatter({ getLocale }: { getLocale: () => string }) {
- return (date: Date, options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', day: 'numeric' }) => {
- return new Intl.DateTimeFormat(getLocale(), options).format(date);
+ return (date: CoercibleDate, options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', day: 'numeric' }) => {
+ return new Intl.DateTimeFormat(getLocale(), options).format(coerceDate(date));
};
}
export function createRelativeTimeFormatter({ getLocale }: { getLocale: () => string }) {
- return (rawDate: Date | string, { now = new Date(), numeric = 'auto', style = 'long' }: { now?: Date; numeric?: 'auto' | 'always'; style?: 'long' | 'short' } = {}) => {
+ return (rawDate: CoercibleDate, { now = new Date(), numeric = 'auto', style = 'long' }: { now?: Date; numeric?: 'auto' | 'always'; style?: 'long' | 'short' } = {}) => {
const formatter = new Intl.RelativeTimeFormat(getLocale(), { numeric, style });
- const date = typeof rawDate === 'string' ? new Date(rawDate) : rawDate;
+ const date = coerceDate(rawDate);
const msDiff = now.getTime() - date.getTime();
const absDiff = Math.abs(msDiff);
const sign = msDiff >= 0 ? -1 : 1;
diff --git a/apps/papra-client/src/modules/invitations/pages/invitations.page.tsx b/apps/papra-client/src/modules/invitations/pages/invitations.page.tsx
index 8370073a..bcbcda46 100644
--- a/apps/papra-client/src/modules/invitations/pages/invitations.page.tsx
+++ b/apps/papra-client/src/modules/invitations/pages/invitations.page.tsx
@@ -2,8 +2,8 @@ import type { Component } from 'solid-js';
import { useMutation, useQuery } from '@tanstack/solid-query';
import { createSolidTable, flexRender, getCoreRowModel, getPaginationRowModel } from '@tanstack/solid-table';
import { For, Show } from 'solid-js';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
-import { timeAgo } from '@/modules/shared/date/time-ago';
import { queryClient } from '@/modules/shared/query/query-client';
import { Button } from '@/modules/ui/components/button';
import { EmptyState } from '@/modules/ui/components/empty';
@@ -56,7 +56,7 @@ export const InvitationsPage: Component = () => {
{
header: t('invitations.list.headers.created'),
accessorKey: 'createdAt',
- cell: data => <time dateTime={data.getValue()}>{timeAgo({ date: data.getValue() })}</time>,
+ cell: data => <RelativeTime date={data.getValue()} />,
},
{
header: () => <div class="text-right">{t('invitations.list.headers.actions')}</div>,
diff --git a/apps/papra-client/src/modules/organizations/pages/invitations-list.page.tsx b/apps/papra-client/src/modules/organizations/pages/invitations-list.page.tsx
index 91fe85c8..ecc98e5b 100644
--- a/apps/papra-client/src/modules/organizations/pages/invitations-list.page.tsx
+++ b/apps/papra-client/src/modules/organizations/pages/invitations-list.page.tsx
@@ -4,10 +4,10 @@ import { A, useNavigate, useParams } from '@solidjs/router';
import { useMutation, useQuery } from '@tanstack/solid-query';
import { createSolidTable, flexRender, getCoreRowModel, getPaginationRowModel } from '@tanstack/solid-table';
import { For, Match, onMount, Show, Switch } from 'solid-js';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
import { cancelInvitation, resendInvitation } from '@/modules/invitations/invitations.services';
import { useConfirmModal } from '@/modules/shared/confirm';
-import { timeAgo } from '@/modules/shared/date/time-ago';
import { queryClient } from '@/modules/shared/query/query-client';
import { Badge } from '@/modules/ui/components/badge';
import { Button } from '@/modules/ui/components/button';
@@ -148,7 +148,7 @@ const InvitationsList: Component = () => {
{
header: t('organizations.members.table.headers.created'),
accessorKey: 'createdAt',
- cell: data => <span title={data.getValue<Date>().toLocaleString()} class="text-muted-foreground">{timeAgo({ date: data.getValue<Date>() })}</span>,
+ cell: data => <RelativeTime date={data.getValue<Date>()} class="text-muted-foreground" />,
},
{
header: '',
diff --git a/apps/papra-client/src/modules/shared/date/coerce-date.ts b/apps/papra-client/src/modules/shared/date/coerce-date.ts
new file mode 100644
index 00000000..30dab7a6
--- /dev/null
+++ b/apps/papra-client/src/modules/shared/date/coerce-date.ts
@@ -0,0 +1,13 @@
+import type { CoercibleDate } from './date.types';
+
+export function coerceDate(date: CoercibleDate): Date {
+ if (date instanceof Date) {
+ return date;
+ }
+
+ if (typeof date === 'string' || typeof date === 'number') {
+ return new Date(date);
+ }
+
+ throw new Error(`Invalid date: expected Date, string, or number, but received value "${date}" of type "${typeof date}"`);
+}
diff --git a/apps/papra-client/src/modules/shared/date/date.types.ts b/apps/papra-client/src/modules/shared/date/date.types.ts
new file mode 100644
index 00000000..59d29500
--- /dev/null
+++ b/apps/papra-client/src/modules/shared/date/date.types.ts
@@ -0,0 +1 @@
+export type CoercibleDate = Date | string | number;
diff --git a/apps/papra-client/src/modules/shared/date/time-ago.test.ts b/apps/papra-client/src/modules/shared/date/time-ago.test.ts
deleted file mode 100644
index ec965e31..00000000
--- a/apps/papra-client/src/modules/shared/date/time-ago.test.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { describe, expect, test } from 'vitest';
-import { timeAgo } from './time-ago';
-
-describe('time-ago', () => {
- describe('timeAgo', () => {
- test('formats the relative time', () => {
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T00:00:00Z') })).toBe('just now');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T00:00:06Z') })).toBe('a few seconds ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T00:01:00Z') })).toBe('a minute ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T00:02:00Z') })).toBe('2 minutes ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T01:00:00Z') })).toBe('an hour ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-01T02:00:00Z') })).toBe('2 hours ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-02T00:00:00Z') })).toBe('a day ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-01-03T00:00:00Z') })).toBe('2 days ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-02-01T00:00:00Z') })).toBe('a month ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2021-03-02T00:00:00Z') })).toBe('2 months ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2022-01-01T00:00:00Z') })).toBe('a year ago');
- expect(timeAgo({ date: new Date('2021-01-01T00:00:00Z'), now: new Date('2023-01-01T00:00:00Z') })).toBe('2 years ago');
- });
-
- test('the date can be a parsable string', () => {
- expect(timeAgo({ date: '2021-01-01T00:00:00Z', now: new Date('2021-01-01T00:00:00Z') })).toBe('just now');
- expect(timeAgo({ date: '2021-01-01T00:00:00Z', now: new Date('2021-03-02T00:00:00Z') })).toBe('2 months ago');
- });
- });
-});
diff --git a/apps/papra-client/src/modules/shared/date/time-ago.ts b/apps/papra-client/src/modules/shared/date/time-ago.ts
deleted file mode 100644
index 7a9a3072..00000000
--- a/apps/papra-client/src/modules/shared/date/time-ago.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-export { timeAgo };
-
-function timeAgo({ date: maybeRawDate, now = new Date() }: { date: Date | string; now?: Date }): string {
- const date = typeof maybeRawDate === 'string' ? new Date(maybeRawDate) : maybeRawDate;
-
- const diffMs = now.getTime() - date.getTime();
- const diffSeconds = Math.floor(diffMs / 1000);
- const diffMinutes = Math.floor(diffSeconds / 60);
- const diffHours = Math.floor(diffMinutes / 60);
- const diffDays = Math.floor(diffHours / 24);
- const diffMonths = Math.floor(diffDays / 30);
- const diffYears = Math.floor(diffMonths / 12);
-
- if (diffSeconds < 5) {
- return 'just now';
- }
-
- if (diffSeconds < 10) {
- return 'a few seconds ago';
- }
-
- if (diffSeconds < 60) {
- return `${diffSeconds} seconds ago`;
- }
-
- if (diffMinutes === 1) {
- return 'a minute ago';
- }
-
- if (diffMinutes < 60) {
- return `${diffMinutes} minutes ago`;
- }
-
- if (diffHours === 1) {
- return 'an hour ago';
- }
-
- if (diffHours < 24) {
- return `${diffHours} hours ago`;
- }
-
- if (diffDays === 1) {
- return 'a day ago';
- }
-
- if (diffDays < 30) {
- return `${diffDays} days ago`;
- }
-
- if (diffMonths === 1) {
- return 'a month ago';
- }
-
- if (diffMonths < 12) {
- return `${diffMonths} months ago`;
- }
-
- if (diffYears === 1) {
- return 'a year ago';
- }
-
- return `${diffYears} years ago`;
-}
diff --git a/apps/papra-client/src/modules/tags/pages/tags.page.tsx b/apps/papra-client/src/modules/tags/pages/tags.page.tsx
index 5ad587d8..3d60fc32 100644
--- a/apps/papra-client/src/modules/tags/pages/tags.page.tsx
+++ b/apps/papra-client/src/modules/tags/pages/tags.page.tsx
@@ -7,9 +7,9 @@ import { A, useParams } from '@solidjs/router';
import { useQuery } from '@tanstack/solid-query';
import { createSignal, For, Show, Suspense } from 'solid-js';
import * as v from 'valibot';
+import { RelativeTime } from '@/modules/i18n/components/RelativeTime';
import { useI18n } from '@/modules/i18n/i18n.provider';
import { useConfirmModal } from '@/modules/shared/confirm';
-import { timeAgo } from '@/modules/shared/date/time-ago';
import { createForm } from '@/modules/shared/form/form';
import { useI18nApiErrors } from '@/modules/shared/http/composables/i18n-api-errors';
import { queryClient } from '@/modules/shared/query/query-client';
@@ -355,7 +355,7 @@ export const TagsPage: Component = () => {
</A>
</TableCell>
<TableCell class="text-muted-foreground" title={tag.createdAt.toLocaleString()}>
- {timeAgo({ date: tag.createdAt })}
+ <RelativeTime date={tag.createdAt} />
</TableCell>
<TableCell>
<div class="flex gap-2 justify-end">
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6e20566b..e998e7a3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -12,18 +12,12 @@ catalogs:
'@types/node':
specifier: ^22.15.21
version: 22.16.0
- '@vitest/coverage-v8':
- specifier: ^3.0.2
- version: 3.2.4
better-auth:
specifier: 1.3.4
version: 1.3.4
eslint:
specifier: ^9.30.1
version: 9.30.1
- tsdown:
- specifier: ^0.13.4
- version: 0.13.4
typescript:
specifier: ^5.6.2
version: 5.8.3
@@ -165,9 +159,6 @@ importers:
cmdk-solid:
specifier: ^1.1.2
version: 1.1.2([email protected])
- date-fns:
- specifier: ^4.1.0
- version: 4.1.0
ofetch:
specifier: ^1.4.1
version: 1.4.1
@@ -5644,10 +5635,6 @@ packages:
resolution: {integrity: sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==}
hasBin: true
- resolution: {integrity: sha512-Kqq/ewnRACQ20e0BlQ5KqHRYWRBp7yv+jttK4Yj2yY+2ldgCoxJkrP1NHUhjypsJ+eQXlGJ/jebM3wa60s1rbQ==}
- hasBin: true
-
resolution: {integrity: sha512-gkWGshjYcQCF+6qtlrqBqELqNqnt4CxruY6UVAWWnqb3DQ6qaNFEIKqzYep1XzHLM/QtrHVCxyPOtTk4LTQ7Aw==}
hasBin: true
@@ -7790,9 +7777,6 @@ packages:
resolution: {integrity: sha512-vrN+B7DBIoTTZjnPNewwhx6cBA/H+IS7rfW68n7XxC1y7uoiGQBxaKzqucGUgavX15dJgiGztLJ8vxuEzwqBdA==}
- resolution: {integrity: sha512-YAT3K/sgpCUxhxNMrrdhtod3jckkpYwH6JAuwmUdXZsmzH1wUyzTMrrK2wYCEEqlKwrWDd35NeuUkbBy/1iK+Q==}
-
resolution: {integrity: sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==}
@@ -9684,7 +9668,7 @@ snapshots:
dependencies:
- fast-xml-parser: 5.2.1
+ fast-xml-parser: 5.3.0
tslib: 2.8.1
@@ -10661,12 +10645,6 @@ snapshots:
eslint: 9.27.0([email protected])
eslint-visitor-keys: 3.4.3
- dependencies:
- eslint: 9.30.1([email protected])
- eslint-visitor-keys: 3.4.3
- optional: true
-
dependencies:
eslint: 9.27.0([email protected])
@@ -14362,14 +14340,14 @@ snapshots:
dependencies:
- '@eslint-community/eslint-utils': 4.5.1([email protected]([email protected]))
- '@jridgewell/sourcemap-codec': 1.5.0
- '@typescript-eslint/types': 8.26.1
+ '@eslint-community/eslint-utils': 4.7.0([email protected]([email protected]))
+ '@jridgewell/sourcemap-codec': 1.5.5
+ '@typescript-eslint/types': 8.35.1
astro-eslint-parser: 1.1.0([email protected])
eslint: 9.30.1([email protected])
- eslint-compat-utils: 0.6.4([email protected]([email protected]))
+ eslint-compat-utils: 0.6.5([email protected]([email protected]))
globals: 15.15.0
- postcss: 8.5.3
+ postcss: 8.5.6
postcss-selector-parser: 7.0.0
transitivePeerDependencies:
- supports-color
@@ -14930,10 +14908,6 @@ snapshots:
dependencies:
strnum: 1.1.2
- dependencies:
- strnum: 2.0.5
-
dependencies:
strnum: 2.1.1
@@ -17771,8 +17745,6 @@ snapshots:
-