PHPackages                             sdo-sa/hijri-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sdo-sa/hijri-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sdo-sa/hijri-converter
======================

Accurate Hijri (Umm al-Qura) ⇄ Gregorian date conversion for PHP, with optional Laravel support.

v1.1.0(1mo ago)410↓25%MITPHPPHP ^8.2

Since Jun 23Pushed 1mo agoCompare

[ Source](https://github.com/SDO-SA/hijri-converter)[ Packagist](https://packagist.org/packages/sdo-sa/hijri-converter)[ RSS](/packages/sdo-sa-hijri-converter/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

hijri-converter
===============

[](#hijri-converter)

Accurate **Hijri (Umm al-Qura) ⇄ Gregorian** date conversion for PHP.

- **Exact, not approximate.** Backed by the official Umm al-Qura calendar — no arithmetic guesswork.
- **One class to remember:** `SDOSA\Hijri`, with `::toHijri()` and `::toGregorian()`.
- **Localized** month and day names in **Arabic, English, Bengali, and Turkish** out of the box.
- **Zero required dependencies.** Optional first-class Laravel + Carbon support.
- **Supported span:** Gregorian `1924-08-01 → 2077-11-16`, Hijri `1343 → 1500`.

Installation
------------

[](#installation)

```
composer require sdo-sa/hijri-converter
```

Requires PHP 8.2+.

Quick start
-----------

[](#quick-start)

Everything goes through the single static class `SDOSA\Hijri` — identical in plain PHP or Laravel:

```
use SDOSA\Hijri;

$h = Hijri::toHijri('1982-12-02');   // accepts string, DateTime, or Carbon
echo $h->toIso();                    // 1403-02-17
echo $h->format();                   // 17/02/1403
echo $h->monthName();                // صفر   (default locale is "ar")
echo $h->monthName('en');            // Safar
echo $h->dayName();                  // الخميس

$g = Hijri::toGregorian('1403-02-17');
echo $g->toIso();                    // 1982-12-02

Hijri::today();                      // HijriDate for today
```

Value objects
-------------

[](#value-objects)

Conversions return small **immutable** value objects — `SDOSA\HijriDate` and `SDOSA\GregorianDate` — that carry the rich API below. Build them yourself with `::make()` (or a named constructor); the plain `new` constructor is intentionally closed off, so there is exactly one obvious way to create a date.

```
use SDOSA\GregorianDate;
use SDOSA\HijriDate;

GregorianDate::make(1982, 12, 2)->toHijri();       // HijriDate
HijriDate::make(1403, 2, 17)->toGregorian();       // GregorianDate

GregorianDate::fromString('1982-12-02');
HijriDate::fromString('1403-02-17');
GregorianDate::fromDateTime(new DateTimeImmutable); // any DateTime / Carbon
```

### API reference

[](#api-reference)

Both value objects share the same shape:

MethodReturnsExample`year()` `month()` `day()``int``1403`, `2`, `17``toIso()``string``1403-02-17``format($sep = '/', $pad)``string``17/02/1403``monthName($locale = null)``string``صفر` / `Safar``dayName($locale = null)``string``الخميس` / `Thursday``notation($locale = null)``string``هـ` / `AH``longFormat($locale = null)``string``17 صفر 1403 هـ` / `17 Safar 1403 AH``isoWeekday()``int` (1–7)`4` — ISO, Monday = 1`weekday()``int` (1–7)`5` — Saudi week, Sunday = 1`equals($other)``bool``compareTo($other)``int` (-1, 0, 1)`(string) $date``string`same as `toIso()``HijriDate` adds `monthLength()`, `yearLength()`, and `toGregorian()`; `GregorianDate` adds `toDateTime()`, `toCarbon()`, and `toHijri()`.

Out-of-range or impossible dates throw `SDOSA\Exceptions\DateOutOfRange`, `InvalidHijriDate`, or `InvalidGregorianDate` — all extend `HijriException`.

Locales
-------

[](#locales)

Four locales ship in the box: **`ar`** (default), **`en`**, **`bn`** (Bengali), **`tr`** (Turkish).

Pass a tag to any name method:

```
Hijri::toHijri('2024-03-11')->monthName('tr');  // Ramazan
Hijri::toHijri('2024-03-11')->monthName('bn');  // রমজান
```

Or change the default used when no tag is passed:

```
use SDOSA\Locales\LocaleRegistry;

LocaleRegistry::setDefault('en');
```

In Laravel, set it in `config/hijri.php` (or the `HIJRI_LOCALE` env var) instead — the service provider applies it on boot. Unknown tags fall back to the default, so a missing translation never breaks a call.

Laravel
-------

[](#laravel)

The service provider is auto-discovered. The core API is static, so there is no facade to register — just call `SDOSA\Hijri` anywhere. The provider wires up config, the default locale, and Carbon macros.

```
php artisan vendor:publish --tag=hijri-config
```

```
use SDOSA\Hijri;
use Carbon\Carbon;

Hijri::toHijri(Carbon::now());     // accepts Carbon / DateTime
Carbon::now()->toHijri();          // HijriDate (macro)
Carbon::now()->hijriFormat('-');   // e.g. 01-09-1445 (macro)
```

Try it
------

[](#try-it)

- **CLI:** `php examples/demo.php`
- **Web:** a self-contained, interactive converter that runs the real library —

    ```
    php -S localhost:8000 -t examples/web
    ```

    then open .

Credits
-------

[](#credits)

The Umm al-Qura dataset and conversion algorithm derive from [`dralshehri/hijridate`](https://github.com/dralshehri/hijridate) (MIT). See `LICENSE`.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

2

Last Release

31d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d425199b7d8bfc377a88c151e63ead62e0a39b158dc500be2718d350ea3fc697?d=identicon)[SDO-SA](/maintainers/SDO-SA)

---

Top Contributors

[![SDO-SA](https://avatars.githubusercontent.com/u/129124547?v=4)](https://github.com/SDO-SA "SDO-SA (3 commits)")

---

Tags

calendarconverterdategregorianhijriislamiclaravelphpsaudiarabialaraveldatecalendarhijrigregorianislamicumm-al-qura

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/sdo-sa-hijri-converter/health.svg)

```
[![Health](https://phpackages.com/badges/sdo-sa-hijri-converter/health.svg)](https://phpackages.com/packages/sdo-sa-hijri-converter)
```

###  Alternatives

[fisharebest/ext-calendar

Implementation of the Arabic (Hijri), French, Gregorian, Jewish, Julian and Persian (Jalali) calendars. Also provides a replacement for the PHP ext/calendar extension.

36529.1k11](/packages/fisharebest-ext-calendar)[mohamedsabil83/laravel-hijrian

Hijri-Gregorian date converter for Laravel

1322.5k](/packages/mohamedsabil83-laravel-hijrian)[maherelgamil/arabicdatetime

Easy and useful tool to generate arabic or hijri date with multi-language support for laravel

414.6k](/packages/maherelgamil-arabicdatetime)[p3ym4n/jdate

Date converter from Jalali to Georgian and vice versa. It has Carbon instance inside and it's Laravel friendly.

101.8k2](/packages/p3ym4n-jdate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
