Add months with Temporal.PlainDate
Keep the original billing date as the anchor for month-end renewals, then compare calendar dates with Temporal.PlainDate.
A subscription starts on January 31. The next invoice should fall on February 28, and the one after that should land on March 31. If you calculate from February's clamped date, the March invoice slips to the 28th.
Keep the original date as the anchor
Temporal.PlainDate holds a calendar date without a time or time zone. It fits a renewal date that you store as YYYY-MM-DD. Use PlainDate.add with the number of months since signup.
Run this in a runtime with Temporal, such as a browser that ships it or Node 26.
const start = Temporal.PlainDate.from('2026-01-31')
const february = start.add({ months: 1 })
const march = start.add({ months: 2 })
console.log(february.toString())
console.log(march.toString())
console.log(february.add({ months: 1 }).toString())
const today = Temporal.PlainDate.from('2026-03-31')
console.log(Temporal.PlainDate.compare(today, march) >= 0)The dates printed are 2026-02-28, 2026-03-31 and 2026-03-28, followed by true for the due-date check.
February has no 31st. The default overflow: 'constrain' clamps the result to the last valid day in February. The March calculation starts at January 31 again, so there is a 31st to land on. Save the signup date and the cycle number if that is the rule your billing system uses.
If the billing rule treats a missing day as an error, pass { overflow: 'reject' } as the second argument to add. The January-to-February calculation then throws a RangeError. Decide what to do with that error at the billing boundary. Use the default clamp when the product rule calls for the last valid day.
Compare dates by value
Temporal.PlainDate.compare(today, march) returns zero on March 31 and a positive value after it. Checking for zero or above includes the due date itself. Use today.equals(march) if the job should run on that date alone.
In the example the job supplies today as a string. In production, decide whose calendar sets that date before you do the comparison. A batch job that runs around midnight UTC can already be on the next date in one billing region and still on the previous date in another.
Read the region's date at the edge of the job and pass it to the comparison. Keep the renewal itself as a PlainDate while the rule deals in days. Use a zoned date-time at the point where the requirement adds an hour or a time zone.