Skip to content

Version 0.4.3 is tagged on GitHub and is not published on npm. A beta will be published before the stable 1.0.0.

Parsing and formatting

Typed text is read in the adapter calendar, and dates are formatted in their own calendar. Neither step goes through a JavaScript Date.

Parsing

parse reads user text in the adapter calendar. It does not use Date.parse.

  • null and blank text parse to null. Any other unrecognized value, including a JavaScript Date or a timestamp, parses to an invalid date.
  • YYYY-MM-DD is year, month, and day in the adapter calendar. On an Umm al-Qura adapter, 1445-09-01 is 1 Ramadan 1445, and 2024-03-11 is an invalid date because AH 2024 is outside 1300–1599.
  • D/M/YYYY, D-M-YYYY, and D.M.YYYY are day, month, and year. When the first number is greater than 31, the same separators are read as year, month, and day, so 1447/10/15 is 15 Shawwal 1447.
  • D Month YYYY accepts the fixed English and Arabic Umm al-Qura month names on an Umm al-Qura adapter, and the active locale's month names on a Gregorian adapter.
  • Arabic-Indic digits (٠–٩) and Persian digits (۰–۹) are accepted.
  • Text outside AH 1300–1599 parses to an invalid date.

Serialization

deserialize accepts null, '', a CalendarDate, or a zero-padded YYYY-MM-DD in the adapter calendar. toIso8601 returns that same YYYY-MM-DD with ASCII digits. It is the adapter calendar's date, not a Gregorian conversion and not Date#toISOString.

Formatting

HIJRI_DATE_FORMATS follows Material's format slots. A numeric month renders as day/month/year. A long, short, or narrow month renders as day month, year, with the Arabic comma ، for Arabic locales. Digits follow the locale.

formatCalendarDate(date, locale, options) applies the same rules outside the adapter:

ts
import { createCalendarDate, formatCalendarDate } from 'ngx-mat-hijri-adapter';

formatCalendarDate(createCalendarDate('islamic-umalqura', 1445, 9, 1), 'en-US', {
  year: 'numeric',
  month: 'long',
  day: 'numeric',
}); // '1 Ramadan, 1445'

Umm al-Qura month names are fixed: Arabic when the locale starts with ar, English otherwise. Gregorian month names and all weekday names come from Intl. Formatting an invalid date throws.