timeAgo accepts a Jalali date-time string (e.g. "1402/06/15 13:05:20") and returns a Persian relative-time phrase. For Gregorian countdowns to a future date, use Remaining Time.
Function
| Parameter | Type | Default | Description |
|---|---|---|---|
datetime | string | "" | Jalali date-time in "yyyy/mm/dd hh:mm:ss" |
since | Date | new Date() | reference “now” |
timeZone | string | "Asia/Tehran" | IANA TZ |
Input requirements
Thedatetime is a string, in Jalali calendar, in "yyyy/mm/dd hh:mm:ss" format. The library normalizes by zero-padding via standardizeFaDateTime, so "1402/6/5 1:5:0" is also accepted.
- Passing a
Date(ornumber) as the first argument throwsTypeError("PersianTools: timeAgo - The input must be a string"). - A format that can’t be normalized throws
TypeError("PersianTools: timeAgo - The input format must be yyyy/mm/dd hh:mm:ss").
Output vocabulary
Persian phrases using قبل / بعد (not پیش):| Span | Output |
|---|---|
| ~1 second | "اکنون" |
| up to a few seconds | "چند ثانیه قبل" / "چند ثانیه بعد" |
| minutes | "X دقیقه قبل" / "X دقیقه بعد" |
| hours / days / weeks / months / years | "X ساعت قبل", "X روز قبل", …, "حدود X سال قبل" |
"... بعد" phrases — the function is bidirectional.
Re-exported helpers
Pitfalls
- Input is a Jalali STRING, not a JS
Dateor number. Passnew Date(...)and it throws. - Output uses قبل/بعد, not پیش.
- No Gregorian → Jalali conversion is built in. If you have a Gregorian
Date, convert withdate-fns-jalaliormoment-jalaalifirst.
Source
src/modules/timeAgo/index.ts, helpers.ts, timestamp.ts, constants.ts · Tests: test/timeAgo.spec.ts