Skip to content

calendaryjs-plugin-hijri

Gregorian ↔ Hijri date conversion plus Hijri recurring events. Uses the tabular (civil) Islamic calendar — arithmetic, deterministic, round-trip safe.

Terminal window
npm i calendaryjs calendaryjs-plugin-hijri

The plugin adds a hijri.date(month, day) builder selector:

import { calendary } from "calendaryjs";
import { every } from "calendaryjs/builder";
import { hijri } from "calendaryjs-plugin-hijri";
const cal = calendary().use(hijri());
cal.addGroup({
id: "islamic-holidays",
events: [
every("year").on(hijri.date(10, 1)).title("Eid al-Fitr"),
every("year").on(hijri.date(12, 10)).title("Eid al-Adha"),
],
});

hijri.date(month, day) compiles to a plain hijri event ({ type: "hijri", hijriMonth, hijriDay }) — the storage form.

import { gregorianToHijri, hijriToGregorian } from "calendaryjs-plugin-hijri";
gregorianToHijri({ year: 2024, month: 7, day: 8 }); // → { year: 1446, month: 1, day: 1 }
hijriToGregorian({ year: 1446, month: 1, day: 1 }); // → { year: 2024, month: 7, day: 8 }

Because a Hijri date drifts ~11 days earlier each Gregorian year, an event may occur 0, 1, or 2 times in a given Gregorian year; the engine returns every occurrence.