Files
FlowReader/web/src/lib/format.ts
T
Antigravity AgentandClaude Opus 5.5 360f3cf012 feat(web): unified reader with reading settings, faster lists, a11y
- New Reader (desktop + mobile): loads full content on open, prefetches
  the next article, reading progress and time, "Aa" settings (light /
  sepia / dark / auto theme, serif / sans / Atkinson Hyperlegible font,
  size, line height, measure), Space-to-next, keyboard shortcuts, focus
  management, inert background, URL-driven (?a=) so Back closes it.
- Dashboard: cursor pagination, unread/all filter, CSS grid (no masonry),
  no re-sorting under the reader, optimistic cache patches instead of
  refetch storms, "new articles" banner, error/offline states, j/k/o/m/s/v
  shortcuts and help dialog.
- Cards: keyboard-openable, lazy <img>, memoized, touch-only swipe.
- Focus mode: framer drag (drop @use-gesture), Read button, undo restores
  unread state, arrow keys.
- WebSocket: single connection, backoff, cache patching, no console logs.
- Contrast fixes (on-nature tokens), 44px targets, lang="fr", reduced
  motion, self-hosted fonts, theme applied before first paint.
- Code splitting + vendor chunk, prompt-based PWA updates, smaller
  precache, offline cache for opened articles and images, caches cleared
  on logout; upgrade react-router (CVE), drop unused deps and assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 07:34:09 +02:00

29 lines
1.2 KiB
TypeScript

// Formatters are built once: constructing Intl objects per render is costly in long lists.
const shortDate = new Intl.DateTimeFormat('fr-FR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
const longDate = new Intl.DateTimeFormat('fr-FR', { day: 'numeric', month: 'long', year: 'numeric' });
const relative = new Intl.RelativeTimeFormat('fr', { numeric: 'auto' });
export function formatShort(iso?: string) {
return iso ? shortDate.format(new Date(iso)) : '';
}
export function formatLong(iso?: string) {
return iso ? longDate.format(new Date(iso)) : '';
}
/** "il y a 5 min", "hier"… falling back to a short date after a week. */
export function formatRelative(iso?: string) {
if (!iso) return '';
const diff = (new Date(iso).getTime() - Date.now()) / 1000;
const abs = Math.abs(diff);
if (abs < 60) return "à l'instant";
if (abs < 3600) return relative.format(Math.round(diff / 60), 'minute');
if (abs < 86400) return relative.format(Math.round(diff / 3600), 'hour');
if (abs < 7 * 86400) return relative.format(Math.round(diff / 86400), 'day');
return shortDate.format(new Date(iso));
}
export function readingTimeLabel(minutes?: number) {
return `${Math.max(1, minutes ?? 1)} min`;
}