JavaScript API¶
Reference for the JavaScript and TypeScript package.
The JavaScript package wraps the same Rust engine through WebAssembly. Public
methods take and return Date objects. Schedule specs use the same JSON shape
as every other binding.
Exports¶
Name |
Description |
|---|---|
|
WebAssembly initialization function. |
|
Query engine class. |
|
Raw generated WebAssembly module exports. |
|
Runtime weekday enum object. |
|
Runtime nth-weekday enum object. |
|
Runtime makeup enum object. |
|
Runtime makeup-failure enum object. |
|
Runtime overlay-rule enum object. |
|
Runtime built-in calendar enum object. |
|
TypeScript schedule model type. |
|
TypeScript frequency union type. |
|
TypeScript calendar spec union type. |
|
TypeScript overlay types. |
|
|
Initialization¶
import init, { Schedule } from "dateme";
await init();
init() must resolve before constructing Schedule.
Schedule¶
Constructor¶
new Schedule(spec: ScheduleSpec | string, calendarProvider?: CalendarProvider)
Parameters:
Parameter |
Type |
Description |
|---|---|---|
|
|
Schedule model. |
|
function or object, optional |
Provider for |
The constructor validates the schedule. Malformed JSON, invalid enum values, invalid timezone names, and structural validation failures throw.
const schedule = new Schedule({
freq: { type: "daily", time: "09:00" },
timezone: "UTC",
});
Custom Calendar Providers¶
Custom calendars are referenced in a schedule with { custom: "name" }.
Providers receive (name, date) where date is a YYYY-MM-DD string.
A function provider:
const schedule = new Schedule(
{
freq: { type: "daily", time: "09:00" },
timezone: "UTC",
overlays: [{ calendar: { custom: "shutdown" }, rule: "exclude" }],
},
(name, date) => name === "shutdown" && date === "2026-08-14",
);
An object provider:
const provider = {
contains(name, date) {
return name === "shutdown" && date === "2026-08-14";
},
};
const schedule = new Schedule(spec, provider);
Missing custom calendar values are treated as absent from the set.
Date Handling¶
Rule |
Behavior |
|---|---|
Input dates |
JavaScript |
Returned values |
JavaScript |
Optional anchors |
Default to |
Query bounds |
Strict: occurrences exactly at |
WASM bridge |
The wrapper converts |
Methods¶
validate¶
schedule.validate(): void
Re-runs structural validation. Throws on failure.
schedule.validate();
toObject¶
schedule.toObject(): ScheduleSpec
Returns the schedule as a plain object.
const spec = schedule.toObject();
toJSON¶
schedule.toJSON(): ScheduleSpec
Returns the schedule as a plain object for JSON.stringify.
JSON.stringify(schedule);
next¶
schedule.next(after = new Date()): Date | null
Returns the first occurrence strictly after after.
const after = new Date("2026-01-13T00:00:00Z");
schedule.next(after);
previous¶
schedule.previous(before = new Date()): Date | null
Returns the last occurrence strictly before before.
schedule.previous(new Date("2026-01-13T00:00:00Z"));
until¶
schedule.until(before: Date, after = new Date()): Date[]
Returns occurrences in (after, before), ascending.
schedule.until(new Date("2026-02-01T00:00:00Z"), after);
since¶
schedule.since(after: Date, before = new Date()): Date[]
Returns occurrences in (after, before), descending.
schedule.since(new Date("2026-01-01T00:00:00Z"));
upcoming¶
schedule.upcoming(n: number, after = new Date()): Date[]
Returns the next n occurrences strictly after after, ascending.
schedule.upcoming(5, after);
Trace Methods¶
Trace methods return OccurrenceTrace values.
Method |
Return type |
Order |
|---|---|---|
|
|
— |
|
|
— |
|
|
ascending |
|
|
descending |
|
|
ascending |
Reason strings include:
Reason form |
Meaning |
|---|---|
|
Base occurrence was kept. |
|
Occurrence was moved from the local date. |
|
Base occurrence was shifted through DST gap. |
|
Made-up occurrence was shifted through DST gap. |
const trace = schedule.nextTrace(after);
// { instant: Date, reason: "base" }
isOccurrence¶
schedule.isOccurrence(instant: Date): boolean
Returns whether instant is an occurrence of the schedule.
schedule.isOccurrence(new Date("2026-01-20T22:30:00Z"));
countBetween¶
schedule.countBetween(after: Date, before: Date): number
Returns the number of occurrences strictly in (after, before).
schedule.countBetween(after, new Date("2026-02-01T00:00:00Z"));
describe¶
schedule.describe(): string
Returns a human-readable summary of the base recurrence, timezone, overlay count, and makeup presence.
schedule.describe();
// "Every Monday at 17:30 America/New_York, with 1 overlay(s), with makeup"
Iteration¶
schedule[Symbol.iterator](): IterableIterator<Date>
schedule.iterBetween(after: Date, before: Date): IterableIterator<Date>
schedule.iterUpcoming(n: number, after = new Date()): IterableIterator<Date>
for...of requires the schedule to have an end bound. It starts from start,
or from the current time when start is absent.
for (const instant of boundedSchedule) {
console.log(instant.toISOString());
}
Array.from(schedule.iterBetween(after, new Date("2026-02-01T00:00:00Z")));
Array.from(schedule.iterUpcoming(3, after));
TypeScript Model¶
The package exports TypeScript types that mirror the Schedule model.
import init, {
Schedule,
Weekday,
CalendarId,
OverlayRule,
Makeup,
} from "dateme";
import type { ScheduleSpec } from "dateme";
const spec: ScheduleSpec = {
freq: { type: "weekly", days: [Weekday.Mon], time: "17:30" },
timezone: "America/New_York",
overlays: [{ calendar: CalendarId.NyseHoliday, rule: OverlayRule.Exclude }],
makeup: Makeup.After,
};
await init();
const schedule = new Schedule(spec);
Type families:
Family |
Types or values |
|---|---|
Frequencies |
|
Calendar specs |
|
Overlays |
|
Makeup |
|
Date helpers |
|