v144 · JavaScript
Scheduling & Recurrence
Real-world scheduling — next business day, N-th working day, recurring monthly events, countdown to a date — is exactly where Temporal shines. The non-mutating arithmetic, 1-indexed months, and ISO day-of-week make scheduling algorithms readable and correct.
Feature detection: checking…
Next business day (skip weekends)
Press Calculate
N-th weekday of month (e.g. "3rd Tuesday of August 2026")
Press Calculate
Recurring event — next 10 occurrences
Countdown to a date
Press Calculate
// Next business day — skip weekends (dayOfWeek: 1=Mon, 6=Sat, 7=Sun)
function nextBusinessDay(date, skip = 1) {
let d = Temporal.PlainDate.from(date);
let skipped = 0;
while (skipped < skip) {
d = d.add({ days: 1 });
if (d.dayOfWeek <= 5) skipped++; // 1-5 = weekdays
}
return d;
}
// N-th weekday of a month (e.g. 3rd Tuesday)
function nthWeekdayOfMonth(year, month, weekday, n) {
// Start at first day of month
let d = Temporal.PlainDate.from({ year, month, day: 1 });
// Advance to the target weekday
const daysUntil = (weekday - d.dayOfWeek + 7) % 7;
d = d.add({ days: daysUntil });
// Advance N-1 more weeks
return d.add({ weeks: n - 1 });
}
// Recurring event generator
function* occurrences(start, frequency, count) {
let d = Temporal.PlainDate.from(start);
for (let i = 0; i < count; i++) {
yield d;
d = frequency === 'monthly'
? d.add({ months: 1 })
: d.add({ weeks: frequency === 'weekly' ? 1 : 2 });
}
}
see also
- PlainDate Playground — add, diff, sort, compare
- Duration Arithmetic — balancing and rounding durations
- Time Zone Converter — scheduling across time zones
- ChromeStatus entry