Hijri dates
import { toHijri, fromHijri, formatHijri, getHijriMonthName, isRamadan } from 'pakdatakit/hijri'
Converts Gregorian dates to Hijri (Islamic) dates and back, formats them as "12 Ramadan 1447", and tells whether a date falls in Ramadan. Everything works offline from arithmetic, with no table of dates.
12 Ramadan 1447
- Hijri date
- 12 Ramadan 1447
- In Ramadan
- Yes
Tabular calendar: dates in Pakistan follow moon sighting and can differ by a day or two.
Examples
Section titled “Examples”import { formatHijri, toHijri, fromHijri, isRamadan } from 'pakdatakit';
formatHijri(new Date(2026, 2, 1, 0, 0));// → '12 Ramadan 1447'
toHijri(new Date(2026, 2, 1, 0, 0));// → {// "year": 1447,// "month": 9,// "day": 12// }
fromHijri({ year: 1447, month: 9, day: 1,});// → 2026-02-18 (a date)
isRamadan(new Date(2026, 2, 1, 0, 0));// → truefrom datetime import datetimefrom pakdatakit import format_hijri, to_hijri, from_hijri, is_ramadan
format_hijri(datetime(2026, 3, 1, 0, 0))# → '12 Ramadan 1447'
to_hijri(datetime(2026, 3, 1, 0, 0))# → {# "year": 1447,# "month": 9,# "day": 12# }
from_hijri({ 'year': 1447, 'month': 9, 'day': 1,})# → 2026-02-18 (a date)
is_ramadan(datetime(2026, 3, 1, 0, 0))# → Trueimport 'package:pakdatakit/pakdatakit.dart';
formatHijri(DateTime(2026, 3, 1, 0, 0));// → '12 Ramadan 1447'
toHijri(DateTime(2026, 3, 1, 0, 0));// → {// "year": 1447,// "month": 9,// "day": 12// }
fromHijri(HijriDate(year: 1447, month: 9, day: 1));// → 2026-02-18 (a date)
isRamadan(DateTime(2026, 3, 1, 0, 0));// → trueusing PakDataKit;
Hijri.Format(new DateOnly(2026, 3, 1));// → "12 Ramadan 1447"
Hijri.ToHijri(new DateOnly(2026, 3, 1));// → {// "year": 1447,// "month": 9,// "day": 12// }
Hijri.FromHijri(new HijriDate(1447, 9, 1));// → 2026-02-18 (a date)
Hijri.IsRamadan(new DateOnly(2026, 3, 1));// → trueuse PakDataKit\Hijri;use PakDataKit\HijriDate;
Hijri::format(new DateTimeImmutable('2026-03-01 00:00:00'));// → '12 Ramadan 1447'
Hijri::toHijri(new DateTimeImmutable('2026-03-01 00:00:00'));// → {// "year": 1447,// "month": 9,// "day": 12// }
Hijri::fromHijri(new HijriDate(1447, 9, 1));// → 2026-02-18 (a date)
Hijri::isRamadan(new DateTimeImmutable('2026-03-01 00:00:00'));// → trueReference
Section titled “Reference”toHijri()
Section titled “toHijri()”function toHijri(date: Date, options?: HijriOptions): HijriDate;
interface HijriDate { year: number; month: number; // 1 to 12 day: number;}
interface HijriOptions { offset?: number; // whole days, default 0}Parameters. date: a Gregorian date; its local date (year, month, day) is used. options.offset: whole days to shift the tabular calendar by, to match local moon sighting.
Returns the Hijri year, month and day.
Caveats. Throws a RangeError if date is invalid or offset is not an integer.
Related: formatHijri(), fromHijri().
fromHijri()
Section titled “fromHijri()”function fromHijri(hijri: HijriDate, options?: HijriOptions): Date;Parameters. hijri: the Hijri year, month and day. options.offset: the same offset used with toHijri().
Returns the Gregorian date, at local midnight.
Caveats. Throws a RangeError if the Hijri parts are out of range: the year must be 1 or more, the month 1 to 12 and the day 1 to 30.
formatHijri()
Section titled “formatHijri()”function formatHijri(date: Date, options?: HijriOptions): string;Returns the Hijri date as a string, such as "14 Ramadan 1447": the day, the English month name and the year.
Related: getHijriMonthName().
getHijriMonthName()
Section titled “getHijriMonthName()”function getHijriMonthName(month: number): string | null;Returns the English name of a Hijri month (1 to 12): Muharram, Safar, Rabi al-Awwal, Rabi al-Thani, Jumada al-Awwal, Jumada al-Thani, Rajab, Shaaban, Ramadan, Shawwal, Dhu al-Qadah, Dhu al-Hijjah. Returns null if month is not an integer from 1 to 12.
isRamadan()
Section titled “isRamadan()”function isRamadan(date: Date, options?: HijriOptions): boolean;Returns true when the date falls in Ramadan, the ninth Hijri month.
Caveats. As for every function here, the start and end of Ramadan follow the tabular calendar unless you pass an offset; the announced dates can differ by a day or two.
Related: public holidays for Eid dates actually observed in Pakistan.