Utilities
Relative Time
Show labels like yesterday, tomorrow, today, and in 3 days with Bangla support.
Start Here
Use relative time when you want a human-friendly label instead of a fixed date.
Quick Rule
If the exact calendar date does not matter to the user, relative time is usually easier to read.
Common Outputs
| Case | What it feels like |
|---|---|
| Past date | 1 day ago or ১ দিন আগে |
| Current day | today when numeric: "auto" is enabled |
| Future date | tomorrow or in 1 day depending on options |
| Localized output | Use locale: "bn-BD" for Bangla wording |
| Compact UI | Use style: "short" |
| Deterministic comparisons | Use baseDate |
Example
import { fromNow } from "@coreify/tarikh";
fromNow(new Date(Date.now() - 86400000));
// -> "1 day ago"
fromNow(new Date(Date.now() - 86400000), { locale: "bn-BD" });
// -> "১ দিন আগে"
fromNow(new Date(Date.now() - 86400000), { numeric: "auto" });
// -> "yesterday"
fromNow(new Date(Date.now() + 86400000), {
locale: "bn-BD",
numeric: "auto",
});
// -> "আগামীকাল"
fromNow("2026-03-31T10:00:00Z", {
baseDate: "2026-03-31T12:00:00Z",
style: "short",
});
// -> "2h ago"
fromNow(new Date(Date.now() - 30000), {
threshold: { justNow: 60000 },
});
// -> "just now"Good Fit
Use this for feeds, reminders, notifications, and timelines where relative wording reads better than a full date.