Anniversaries & milestones
The 0.6.0 recurrence primitives, all declarative on a const event.
import { calendary } from "calendaryjs";
const cal = calendary();cal.addGroup({ id: "milestones", events: [ // Only the 1/5/10/25/50-year anniversaries, counted from the wedding (2010). { type: "const", id: "wedding", month: 6, day: 20, title: "Wedding anniversary", origin: 2010, keepOrdinals: [1, 5, 10, 25, 50], }, // A Feb-29 birthday, clamped to the last day of February in non-leap years // instead of spilling into March 1. { type: "const", id: "leapling", month: 2, day: 29, title: "Leap-day birthday", onMissingDay: "clamp" }, ],});
cal.getEvents("2015-06-20")[0].ordinal; // → 5 ("N years", no occurrenceYear − origin math)cal.getEvents("2013-06-20"); // → [] (3 years isn't a kept milestone)cal.getEvents("2020-06-20")[0].title; // → "Wedding anniversary" (10 years)
cal.getEvents("2025-02-28").map(e => e.title); // → ["Leap-day birthday"] (clamped)cal.getEvents("2024-02-29").map(e => e.title); // → ["Leap-day birthday"] (real leap day)keepOrdinals— emit only the listed anniversaries;origin(defaults tostartYear) is the anchor. For the arithmetic “every Nth year” case useintervalstartYearinstead.
onMissingDay—"overflow"(default, Feb 29 → Mar 1),"clamp"(last valid day), or"skip"(no occurrence that year).ordinal—occurrenceYear − (origin ?? startYear)on every computed event.
Full reference: Event types.