Skip to content
Devix Open Source
Laravel package v1.0.0 MIT Stable

Laravel Hijri

Hijri dates in Laravel on the published Umm al-Qura table — and honest about where it ends.

composer require devix-labs/laravel-hijri
PHP Laravel
Laravel Hijri

Live demo coming soon

The month table is generated from ICU, checked against it day by day, and shipped as a PHP class so nothing is parsed at runtime. Whole-day offsets for countries that sight the moon a day either way, Arabic, Urdu and English formatting and parsing, arithmetic that stays inside the calendar, and the dates everyone asks for. A Hijri facade, a @hijri Blade directive and Carbon macros, with 135 shared vectors asserting the same answers as the JavaScript package.

What you get

The published table, as PHP

Generated from ICU and verified against it, then shipped as a class — no JSON parsed on each request, and no dependency on the server's ICU version.

Says when it is guessing

Outside 1300–1600 AH the tabular calendar answers and the result carries exact: false. No other PHP package tells you.

Carbon learns the calendar

$invoice->created_at->toHijri() and ->hijriFormat(), because a date in Laravel is already a Carbon instance.

@hijri in Blade

One directive, following your app's locale, so an Arabic page prints Arabic months and Arabic-Indic numerals.

Offsets for your country

Ministries publish “a day ahead of Umm al-Qura”. Set it in config and every conversion follows, both directions.

Agrees with the browser

135 shared vectors assert this package and @devix/hijri answer identically — conversions, formatting, parsing, events and arithmetic.

Laravel Hijri — overview

Why it exists

The Umm al-Qura calendar is a table, not a formula. PHP's alternatives either bundle an old copy of it or derive dates arithmetically, and none of them tells you when a date falls outside the published range.

What it does

  • The real table, generated from ICU and verified against it, shipped as a PHP class.
  • Says when it is guessing — exact: false outside 1300–1600 AH.
  • Offsets, because sighting differs by country.
  • Arabic, Urdu and English, formatting and parsing both.
  • Laravel where you need it: a facade, a Blade directive, Carbon macros, config.
  • The same answers as the browser, asserted by 135 shared vectors.

Not in 1.0

Sighting calendars that differ by more than a whole-day offset, and the Persian and Ottoman calendars.

How it compares

Questions

Why not just use IntlCalendar?

It has the right table, but it needs ext-intl, its answers move with whichever ICU version the server has, and it gives you no Hijri month names in Arabic or Urdu. This package pins the table, formats properly, and works without the extension.

What happens outside 1300–1600 AH?

The tabular calendar answers and the result carries exact: false. Show that when the date matters — no library can convert a 1250 AH date authoritatively.

My country's Eid is a day later.

That is normal: most countries sight the moon. Set offset in config, or pass it per call; it applies to both directions so the arithmetic stays consistent.

Should I store Hijri dates in the database?

Store the Gregorian date — it is unambiguous and sorts — and convert for display. If you must store Hijri, use three integers and record the offset you used.

Will the server and the browser agree?

Yes, and it is asserted rather than assumed: 135 shared vectors run in this package's test suite, generated from the JavaScript one.