Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
A minimal relative time string library
Time-ago
A minimal relative time string function
Check the Documentation in JSR
Overview
The timeAgo
function returns a human-readable string representing the time
elapsed since a given date. It supports producing strings like "just now", "5
minutes ago", and "a year ago" for quick and simple time formatting.
Supported intervals are "year", "month", "week", "day", "hour",
"minute", and "second".
The timeRemaining
function returns a human-readable string representing the
time remaining until a given date. It supports producing strings like "in 5
seconds", "in 5 minutes", and "in a year" for quick and simple time
formatting. Supported intervals are "year", "month", "week", "day",
"hour", "minute", and "second".
Usage
timeAgo
import { timeAgo } from "@egamagz/time-ago"; console.log(timeAgo(new Date())); // "just now" console.log(timeAgo(new Date(Date.now() - 1000))); // "a second ago" console.log(timeAgo(new Date(Date.now() - 1000 * 60 * 5))); // "5 minutes ago" console.log(timeAgo(new Date(Date.now() - 1000 * 60 * 60 * 24 * 5))); // "5 days ago"
timeRemaining
import { timeRemaining } from "@egamagz/time-ago"; console.log(timeRemaining(Date.now() + 5000)); // "in 5 seconds" console.log(timeRemaining(Date.now() + 5 * 60 * 1000)); // "in 5 minutes" console.log(timeRemaining(Date.now() + 3 * 60 * 60 * 1000)); // "in 3 hours" console.log(timeRemaining(Date.now() + 60 * 60 * 1000)); // "in an hour" // Weeks console.log(timeRemaining(Date.now() + 3 * 7 * 24 * 60 * 60 * 1000)); // "in 3 weeks" // Month (exact month difference) console.log(timeRemaining(Date.now() + 30 * 24 * 60 * 60 * 1000)); // "in a month" // Four weeks vs month example console.log(timeRemaining(Date.now() + 4 * 7 * 24 * 60 * 60 * 1000)); // "in 4 weeks"
Installation
With Deno
deno add jsr:@egamagz/time-ago
With Bun
bunx jsr add @egamagz/time-ago
With NPM
npx jsr add @egamagz/time-ago
License
MIT License
Add Package
deno add jsr:@egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";
Import directly with a jsr specifier
import * as time_ago from "jsr:@egamagz/time-ago";
Add Package
pnpm i jsr:@egamagz/time-ago
pnpm dlx jsr add @egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";
Add Package
yarn add jsr:@egamagz/time-ago
yarn dlx jsr add @egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";
Add Package
vlt install jsr:@egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";
Add Package
npx jsr add @egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";
Add Package
bunx jsr add @egamagz/time-ago
Import symbol
import * as time_ago from "@egamagz/time-ago";