-
Notifications
You must be signed in to change notification settings - Fork 0
advanced
Each method accepts an optional options argument. You can mix UAQ and FCNA in the same codebase:
import dayjs from 'dayjs';
import hijri from 'dayjs-hijri-plus';
dayjs.extend(hijri);
const d = dayjs('2023-03-23');
const uaqYear = d.iYear(); // UAQ (default)
const fcnaYear = d.iYear({ calendar: 'fcna' }); // FCNANear month boundaries, UAQ and FCNA may differ by one day. The calendar argument is per-call, not session-wide.
d.toHijri() (if the package exposes it) returns null for dates outside UAQ range (approximately 1900-2076 CE). Guard before using:
const hijri = d.toHijri();
if (hijri !== null) {
console.log(hijri.hy, hijri.hm, hijri.hd);
}dayjs-hijri-plus works alongside other Day.js plugins. The order of extend() calls matters when two plugins patch the same method:
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import hijri from 'dayjs-hijri-plus';
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(hijri);
// UTC-aware conversion
const d = dayjs.utc('2023-03-23');
console.log(d.iYear()); // 1444Hijri tokens (iYYYY, iMM, iDD, iMMMM, etc.) coexist with Day.js Gregorian tokens. Use them in the same format string:
d.format('YYYY-MM-DD (iD iMMMM iYYYY)');
// '2023-03-23 (1 Ramadan 1444)'The package ships both ESM and CJS builds. In ESM bundlers (Vite, esbuild, Rollup), unused code is eliminated. The plugin itself is ~2 KB min+gz on top of Day.js.
The plugin augments the Day.js type definitions automatically. You do not need to import any separate types file:
import dayjs from 'dayjs';
import hijri from 'dayjs-hijri-plus';
dayjs.extend(hijri);
const d = dayjs('2023-03-23');
const year: number = d.iYear(); // fully typeddayjs-hijri-plus · MIT License · npm · Issues
Guides
Examples
Reference
API Pages
- plugin (default)
- toHijri
- isValidHijri
- hijriYear
- hijriMonth
- hijriDay
- formatHijri
- fromHijri
- registerCalendar
Community