Componentmedia0.57 KB gzipZero dependencies

TimeAgo

Relative time display showing '5 MIN AGO' with live re-render tick every 30s

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add time-ago

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { TimeAgo } from "@/components/ui/time-ago" <TimeAgo date={new Date()} live />

Source code

time-ago.tsx + 1 helper

Zero third-party dependencies (2 local files shown in tabs below).

tsxtime-ago.tsx64 lines
"use client";import * as React from "react";import { cn } from "./lib/utils"; export type TimeAgoProps = {  date: Date | number | string;  live?: boolean;}; function formatTimeAgo(date: Date | number | string): string {  const now = new Date();  const target = typeof date === "number" ? new Date(date) : new Date(date);  if (Number.isNaN(target.getTime())) return "UNKNOWN";  const diffMs = now.getTime() - target.getTime();  const isFuture = diffMs < 0;  const diffSec = Math.floor(Math.abs(diffMs) / 1000);  const diffMin = Math.floor(diffSec / 60);  const diffHour = Math.floor(diffMin / 60);

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { TimeAgo } from "@/components/ui/time-ago"; <TimeAgo />
PropTypeDescription
dateDate | number | stringThe date to calculate relative time from
livebooleanWhether to live-update the relative time every 30s