formatAgo()function
formatAgo(target: PossibleDate, current?: PossibleDate, options?: UnitFormatOptions, caller: AnyCaller = formatAgo): string
| Param | Type | |
|---|---|---|
target | PossibleDate | Date to count back from. required |
current | PossibleDate | Date to count to (defaults to now). |
options | UnitFormatOptions | Formatting options for the chosen duration unit. |
.one | string | String for one of this thing, e.g. product or item or sheep- Used for unitDisplay: "long" formatting.- Defaults to unit reference, e.g. "minute" readonly |
.many | string | String for several of this thing, e.g. products or items or sheep- Used for unitDisplay: "long" formatting.- Defaults to one + "s" readonly |
.abbr | string | Abbreviation for this thing, e.g. products or items or sheep (defaults to one + "s").- Used for unitDisplay: "narrow" formatting.- Defaults to unit reference, e.g. "minute" readonly |
caller | AnyCaller |
| Return | |
|---|---|
string | Compact string like 10d or 2h (negative if target is in the future). |
| Throws | |
|---|---|
RequiredError | If target or current cannot be converted to a valid date. |
Format a compact best-fit description of how long since a date, e.g. 10d or 2h or -1w
- See
getBestDurationUnit()for details on how the best-fit unit is chosen.
Examples
formatAgo("2000-01-01") // "26y"