formatUntil()function

formatUntil(target: PossibleDate, current?: PossibleDate, options?: UnitFormatOptions, caller: AnyCaller = formatUntil): string
ParamType
targetPossibleDate
Date to count up to. required
currentPossibleDate
Date to count from (defaults to now).
optionsUnitFormatOptions
Formatting options for the chosen duration unit.
    .onestring
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
    .manystring
String for several of this thing, e.g. products or items or sheep
- Used for unitDisplay: "long" formatting.
- Defaults to one + "s" readonly
    .abbrstring
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
callerAnyCaller
Function to attribute a thrown error to (defaults to formatUntil itself). Defaults to formatUntil
Return
string
Compact string like 10d or 2h (negative if target is in the past).
Throws
RequiredError
If target or current cannot be converted to a valid date.

Format a compact best-fit description of how long until a date, e.g. 10d or 2h or -1w

Examples

formatUntil("2099-01-01") // "73y"