PHPackages                             omarmokhtar/laravel-hijri-date - 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. omarmokhtar/laravel-hijri-date

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

omarmokhtar/laravel-hijri-date
==============================

Hijri &amp; Gregorian date converter for Laravel

v1.0.0(4mo ago)033↓100%MITPHPPHP ^8.1

Since Dec 31Pushed 4mo agoCompare

[ Source](https://github.com/omarmokhtar01/laravel-hijri-date)[ Packagist](https://packagist.org/packages/omarmokhtar/laravel-hijri-date)[ RSS](/packages/omarmokhtar-laravel-hijri-date/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

🕌 Laravel Hijri Date
====================

[](#-laravel-hijri-date)

> A clean and powerful Laravel package for handling **Hijri &amp; Gregorian dates** with automatic detection, flexible input formats, and reliable conversion using the **Umm Al-Qura calendar**.

---

✨ Features
----------

[](#-features)

- ✅ Convert **Gregorian ⇄ Hijri**
- ✅ Auto-detect input type
- ✅ Accepts Gregorian dates as:

    - `d-m-Y`
    - `d/m/Y`
    - `Y-m-d`
    - `Y/m/d`
- ✅ Accepts Hijri dates as:

    - `d/m/Y`
    - `d-m-Y`
    - `Y/m/d`
    - `Y-m-d`
- ✅ Accepts input as:

    - `string`
    - `Carbon`
    - `DateTime`
    - `array` with keys: `day`, `month`, `year`
- ✅ Timezone support for Gregorian dates
- ✅ Uses reliable **Umm Al-Qura calendar (via Aladhan API)**
- ✅ Daily caching for performance
- ✅ Simple Facade API
- ✅ Console command support
- ✅ Laravel **10, 11 &amp; 12** compatible

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require omarmokhtar/laravel-hijri-date
```

Laravel will auto-discover the service provider automatically.

---

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file:

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

### `config/hijri-date.php`

[](#confighijri-datephp)

```
return [
    'timezone'   => config('app.timezone'),
    'adjustment' => 0,        // -1 | 0 | +1 (Hijri day adjustment)
    'cache_ttl'  => 86400     // seconds (1 day)
];
```

---

🚀 Usage
-------

[](#-usage)

### Get today's Hijri date

[](#get-todays-hijri-date)

```
use HijriDate;

HijriDate::todayHijri();
```

**Example output:**

```
[
  "day" => "10",
  "month" => [
      "number" => 9,
      "en" => "Ramadan",
      "ar" => "رمضان"
  ],
  "year" => "1446"
]
```

---

### Convert Gregorian → Hijri

[](#convert-gregorian--hijri)

#### String input

[](#string-input)

```
HijriDate::fromGregorian('15-03-2025');
HijriDate::fromGregorian('15/03/2025');
HijriDate::fromGregorian('2025-03-15');
HijriDate::fromGregorian('2025/03/15');
```

#### With timezone

[](#with-timezone)

```
HijriDate::fromGregorian('15/03/2025', 'Africa/Cairo');
```

#### Carbon / DateTime

[](#carbon--datetime)

```
HijriDate::fromGregorian(now());
HijriDate::fromGregorian(new DateTime());
```

---

### Convert Hijri → Gregorian

[](#convert-hijri--gregorian)

#### Using day, month, year

[](#using-day-month-year)

```
HijriDate::fromHijri(1, 9, 1446);
```

#### String input

[](#string-input-1)

```
HijriDate::fromHijriString('13/08/1447');
HijriDate::fromHijriString('13-08-1447');
HijriDate::fromHijriString('1447/08/13');
HijriDate::fromHijriString('1447-08-13');
```

#### Array input

[](#array-input)

```
HijriDate::parse([
    'day' => 1,
    'month' => 9,
    'year' => 1446,
]);
```

---

### Auto-detect &amp; Parse

[](#auto-detect--parse)

```
HijriDate::parse('15-03-2025');          // Gregorian
HijriDate::parse('13/08/1447', 'hijri'); // Hijri
HijriDate::parse('1447/08/13', 'hijri'); // Hijri (YYYY/MM/DD)
```

The package will automatically detect whether the date is **Hijri or Gregorian** based on the year or optional type hint.

---

🧠 How It Works
--------------

[](#-how-it-works)

- Gregorian parsing handled via **Carbon**
- Hijri conversion handled via **Aladhan API**
- Calendar based on **Umm Al-Qura**
- Results cached daily for high performance

---

🖥️ Console Command
------------------

[](#️-console-command)

This package provides a built-in Artisan command for validating Hijri date sources.

### Run manually

[](#run-manually)

```
php artisan hijri:validate
```

---

⏱️ Scheduling the Command (Optional)
------------------------------------

[](#️-scheduling-the-command-optional)

You can run the Hijri validation command automatically every day using **Laravel Scheduler**.

### 1️⃣ Add to `app/Console/Kernel.php`

[](#1️⃣-add-to-appconsolekernelphp)

```
use Illuminate\Console\Scheduling\Schedule;

protected function schedule(Schedule $schedule)
{
    $schedule->command('hijri:validate')->dailyAt('00:05');
}
```

This will run the command **daily at 12:05 AM**.

---

### 2️⃣ Enable Scheduler on the Server

[](#2️⃣-enable-scheduler-on-the-server)

Make sure you have this Cron Job configured on your server:

```
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
```

> ⚠️ Replace `/path-to-your-project` with the actual path to your Laravel project.

---

### ✅ Notes

[](#-notes)

- Console commands are **auto-registered** via the package service provider
- No console files are copied into your project
- This is the **standard Laravel package behavior**

---

❌ Error Handling
----------------

[](#-error-handling)

Invalid or unsupported input will throw:

```
OmarMokhtar\HijriDate\Exceptions\InvalidDateException
```

---

🧪 Requirements
--------------

[](#-requirements)

- PHP ^8.1
- Laravel ^10 | ^11 | ^12
- Internet connection (API-based)

---

🔒 Offline Mode (Planned)
------------------------

[](#-offline-mode-planned)

Upcoming features:

- ⏳ Offline astronomical calculations
- ⏳ Carbon macro (`now()->toHijri()`)
- ⏳ Validation Rule (`hijri_date`)
- ⏳ Multi-calendar support (Umm Al-Qura, Turkish, etc.)

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome ❤️

1. Fork the repository
2. Create a new branch
3. Commit your changes
4. Open a Pull Request 🚀

---

📄 License
---------

[](#-license)

MIT License © 2025 Developed by **Omar Mokhtar**

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance76

Regular maintenance activity

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.9% 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

Unknown

Total

1

Last Release

133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a589cf165229ee7c2fb0d4b7e903e031c3fccda4c035cf8c33da317e209fd60?d=identicon)[omarmokhtar01](/maintainers/omarmokhtar01)

---

Top Contributors

[![omarmokhtar022](https://avatars.githubusercontent.com/u/258754014?v=4)](https://github.com/omarmokhtar022 "omarmokhtar022 (10 commits)")[![omarmokhtar01](https://avatars.githubusercontent.com/u/91415360?v=4)](https://github.com/omarmokhtar01 "omarmokhtar01 (3 commits)")

### Embed Badge

![Health badge](/badges/omarmokhtar-laravel-hijri-date/health.svg)

```
[![Health](https://phpackages.com/badges/omarmokhtar-laravel-hijri-date/health.svg)](https://phpackages.com/packages/omarmokhtar-laravel-hijri-date)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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