remainingTime accepts a Gregorian target date (string, number, or Date) and returns a structured countdown plus a Persian-digit toString() and an isFinished flag.
Function
When the target has passed
Calendar-naive math
Months are 30 days, years are 365 days. This is an approximation — leap years and varying month lengths are ignored. For legal/financial deadlines requiring calendar precision, use a calendar-aware library.Input handling
- Accepts anything
new Date(date)accepts. - Invalid dates (
"not-a-date") throwTypeError("PersianTools: remainingTime - The input must be a valid date").
toString() — Persian digit output
The string method converts component values to Persian digits via digitsEnToFa, then joins non-zero parts with و:
Pitfalls
toString()returns""when finished — checkisFinishedto render a “Finished” label.- Calendar-naive. Not suitable for “exactly N months from today”.
- No Jalali support here. Convert Jalali targets to Gregorian first if you have one.
Source
src/modules/remainingTime/index.ts, getCurrentDateTime.ts · Tests: test/remainingTime.spec.ts