PHPackages                             ariaieboy/jalali - 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. ariaieboy/jalali

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

ariaieboy/jalali
================

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in php appliations, based on Jalali (Shamsi) DateTime class.

1.2.1(3mo ago)530.0k↓41%1[2 PRs](https://github.com/ariaieboy/jalali/pulls)2MITPHPPHP ~8.3|~8.4|~8.5CI passing

Since Mar 3Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/ariaieboy/jalali)[ Packagist](https://packagist.org/packages/ariaieboy/jalali)[ Docs](https://github.com/ariaieboy/jalali)[ GitHub Sponsors](https://github.com/ariaieboy)[ RSS](/packages/ariaieboy-jalali/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (7)Used By (2)

Ariaieboy/jalai
===============

[](#ariaieboyjalai)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e2b916ed92764a598812247293f7bd490eed73cefe4924ccf4ba1573f6af87b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617269616965626f792f6a616c616c692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ariaieboy/jalali)[![Tests](https://camo.githubusercontent.com/9c23931baaef2712a27b77dfc65137fefbaea331d3e1533a0051a32898527ab6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f617269616965626f792f6a616c616c692f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ariaieboy/jalali/actions/workflows/run-tests.yml)[![PHPSTAN](https://camo.githubusercontent.com/df18dd2b4fcfc268de7be1e3fb2b8ccd1da5f6ee1f90e10e372bd81fe49b1f43/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f617269616965626f792f6a616c616c692f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d5048505374616e267374796c653d666c61742d737175617265)](https://github.com/ariaieboy/jalali/actions/workflows/phpstan.yml)[![Total Downloads](https://camo.githubusercontent.com/a8c4f052d016643200d22934519ade3945396e87d4325fed46b04138262c1ae3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617269616965626f792f6a616c616c692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ariaieboy/jalali)

- Jalali calendar is a solar calendar that was used in Persia, variants of which today are still in use in Iran as well as Afghanistan. [Read more on Wikipedia](http://en.wikipedia.org/wiki/Jalali_calendar) or see [Calendar Converter](http://www.fourmilab.ch/documents/calendar/).
- Calendar conversion is based on the [algorithm provided by Kazimierz M. Borkowski](http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm) and has a very good performance.
- This repo is a hard fork from [morilog/jalali](https://github.com/morilog/jalali)

Difference with morilog/jalali
------------------------------

[](#difference-with-morilogjalali)

- Automated testing
- Level 9 PHPStan check
- Carbon 3 support
- Only dependant on Carbon

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

[](#installation)

You can install the package via composer:

```
composer require ariaieboy/jalali
```

Basic Usage
-----------

[](#basic-usage)

You can use `Jalali` class for manipulating Jalali date time

### Jalali

[](#jalali)

You can use `jdate()` helper instead of `Jalali::forge()`;

#### `now([$timestamp = null])`

[](#nowtimestamp--null)

```
// the default timestamp is Now
$date = \Ariaieboy\Jalali\Jalali::now()
// OR
$date = jdate();

// pass timestamps
$date = Jalali::forge(1333857600);
// OR
$date = jdate(1333857600);

// pass human readable strings to make timestamps
$date = Jalali::forge('last sunday');

// get the timestamp
$date = Jalali::forge('last sunday')->getTimestamp(); // 1333857600

// format the timestamp
$date = Jalali::forge('last sunday')->format('%B %d، %Y'); // دی 02، 1391
$date = Jalali::forge('today')->format('%A, %d %B %y'); // جمعه، 23 اسفند 97

// get a predefined format
$date = Jalali::forge('last sunday')->format('datetime'); // 1391-10-02 00:00:00
$date = Jalali::forge('last sunday')->format('date'); // 1391-10-02
$date = Jalali::forge('last sunday')->format('time'); // 00:00:00

// get relative 'ago' format
$date = Jalali::forge('now - 10 minutes')->ago() // 10 دقیقه پیش
```

#### Methods api

[](#methods-api)

---

```
public static function now(\DateTimeZone|null $timeZone = null): Jalali

$jDate = Jalali::now();
```

---

```
public static function fromCarbon(Carbon $carbon): Jalali

$jDate = Jalali::fromCarbon(Carbon::now());
```

---

```
public static function fromFormat(string $format, string $timestamp, \DateTimeZone|null $timeZone = null): Jalali

$jDate = Jalali::fromFormat('Y-m-d H:i:s', '1397-01-18 12:00:40');
```

---

```
public static function forge(string|DateTimeInterface $timestamp, DateTimeZone|null $timeZone = null): Jalali

// Alias fo fromDatetime
```

---

```
public static function fromDateTime(string|DateTimeInterface $dateTime, \DateTimeZone|null $timeZone = null): Jalali

$jDate = Jalali::fromDateTime(Carbon::now())
// OR
$jDate = Jalali::fromDateTime(new \DateTime());
// OR
$jDate = Jalali::fromDateTime('yesterday');
```

---

```
public function getMonthDays(): int

$date = (new Jalali(1397, 1, 18))->getMonthDays()
// output: 31
```

---

```
public function getMonth(): int

$date = (new Jalali(1397, 1, 18))->getMonth()
// output: 1
```

---

```
public function isLeapYear(): bool

$date = (new Jalali(1397, 1, 18))->isLeapYear()
// output: false
```

---

```
public function getYear(): int

$date = (new Jalali(1397, 1, 18))->getYear()
// output: 1397
```

---

```
public function subMonths(int $months = 1): Jalali

$date = (new Jalali(1397, 1, 18))->subMonths(1)->toString()
// output: 1396-12-18 00:00:00
```

---

```
public function subYears(int $years = 1): Jalali

$date = (new Jalali(1397, 1, 18))->subYears(1)->toString()
// output: 1396-01-18 00:00:00
```

---

```
public function getDay(): int

$date = (new Jalali(1397, 1, 18))->getDay()
// output: 18
```

---

```
public function getHour(): int

$date = (new Jalali(1397, 1, 18, 12, 0, 0))->getHour()
// output: 12
```

---

```
public function getMinute(): int

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->getMinute()
// output: 10
```

---

```
public function getSecond(): int

$date = (new Jalali(1397, 1, 18, 12, 10, 45))->getSecond()
// output: 45
```

---

```
public function getTimezone(): \DateTimeZone|null

// Get current timezone
```

---

```
public function addMonths(int $months = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addMonths(1)->format('m')
// output: 02
```

---

```
public function addYears(int $years = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addYears(1)->format('Y')
// output: 1398
```

---

```
public function getDaysOf(int $monthNumber = 1): int

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->getDaysOf(1)
// output: 31
```

---

```
public function addDays(int $days = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addDays(1)->format('d')
// output: 18
```

---

```
public function toCarbon(): Carbon

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->toCarbon()->toDateTimeString()
// output: 2018-04-07 12:10:00
```

---

```
public function subDays(int $days = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->subDays(10)->format('d')
// output: 08
```

---

```
public function addHours(int $hours = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addHours(1)->format('H')
// output: 13
```

---

```
public function subHours(int $hours = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->subHours(1)->format('H')
// output: 11
```

---

```
public function addMinutes(int $minutes = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addMinutes(10)->format('i')
// output: 22
```

---

```
public function subMinutes(int $minutes = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->subMinutes(10)->format('i')
// output: 02
```

---

```
public function addSeconds(int $secs = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->addSeconds(10)->format('s')
// output: 10
```

---

```
public function subSeconds(int $secs = 1): Jalali

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->subSeconds(10)->format('i:s')
// output: 11:40
```

---

```
public function equalsTo(Jalali $other): bool

$date = (new Jalali(1397, 1, 18, 12, 10, 0))->equalsTo(Jalali::now())
// output: false

$date = Jalali::now()->equalsTo(Jalali::now())
// output: true
```

---

```
public function equalsToCarbon(Carbon $carbon): bool

$date = Jalali::now()->equalsToCarbon(Carbon::now())
// output: true
```

---

```
public function greaterThan(Jalali $other): bool

$date = Jalali::now()->greaterThan(Jalali::now()->subDays(1)))
// output: true
```

---

```
public function greaterThanCarbon(Carbon $carbon): bool

$date = Jalali::now()->greaterThanCarbon(Carbon::now()->subDays(1)))
// output: true
```

---

```
public function lessThan(Jalali $other): bool

$date = Jalali::now()->lessThan(Jalali::now()->addDays(1)))
// output: true
```

---

```
public function lessThanCarbon(Carbon $carbon): bool

$date = Jalali::now()->lessThanCarbon(Carbon::now()->addDays(1)))
// output: true
```

---

```
public function greaterThanOrEqualsTo(Jalali $other): bool

$date = Jalali::now()->greaterThan(Jalali::now()->subDays(1)))
// output: true
```

---

```
public function greaterThanOrEqualsToCarbon(Carbon $carbon): bool

$date = Jalali::now()->greaterThanOrEqualsToCarbon(Carbon::now()))
// output: true
```

---

```
public function lessThanOrEqualsTo(Jalali $other): bool

$date = Jalali::now()->lessThanOrEqualsTo(Jalali::now()))
// output: true
```

---

```
public function lessThanOrEqualsToCarbon(Carbon $carbon): bool

$date = Jalali::now()->lessThanOrEqualsToCarbon(Carbon::now()))
// output: true
```

---

```
public function isStartOfWeek(): bool

$date = (new Jalali(1397, 6, 24))->isStartOfWeek()
// output: true
```

---

```
public function isSaturday(): bool

$date = (new Jalali(1397, 6, 24))->isSaturday()
// output: true
```

---

```
public function isDayOfWeek(int $day): bool

$date = (new Jalali(1397, 6, 24))->isDayOfWeek(0)
// output: true
```

---

```
public function isEndOfWeek(): bool

$date = (new Jalali(1397, 6, 24))->isEndOfWeek()
// output: false
```

---

```
public function isFriday(): bool

$date = (new Jalali(1397, 6, 24))->isFriday()
// output: false
```

---

```
public function isToday(): bool

$date = (new Jalali(1397, 6, 24))->isToday()
// output: (!maybe) true
```

---

```
public function isTomorrow(): bool

$date = (new Jalali(1397, 6, 25))->isTomorrow()
// output: true
```

---

```
public function isYesterday(): bool

$date = (new Jalali(1397, 6, 23))->isYesterday()
// output: true
```

---

```
public function isFuture(): bool

$date = (new Jalali(1397, 6, 26))->isFuture()
// output: true
```

---

```
public function isPast(): bool

$date = (new Jalali(1397, 5, 24))->isPast()
// output: true
```

---

```
public function toArray(): array
$date = (new Jalali(1397, 6, 24))->toArray()
// output: (
//     [year] => 1397
//     [month] => 6
//     [day] => 24
//     [dayOfWeek] => 0
//     [dayOfYear] => 179
//     [hour] => 0
//     [minute] => 0
//     [second] => 0
//     [micro] => 0
//     [timestamp] => 1536969600
//     [formatted] => 1397-06-24 00:00:00
//     [timezone] =>
// )
```

---

```
public function getDayOfWeek(): int

$date = (new Jalali(1397, 5, 24))->getDayOfWeek()
// output: 0
```

---

```
public function isSunday(): bool

$date = (new Jalali(1397, 6, 24))->isSunday()
// output: false
```

---

```
public function isMonday(): bool

$date = (new Jalali(1397, 6, 26))->isMonday()
// output: true
```

---

```
public function isTuesday(): bool

$date = (new Jalali(1397, 6, 24))->isTuesday()
// output: false
```

---

```
public function isWednesday(): bool

$date = (new Jalali(1397, 6, 24))->isWednesday()
// output: false
```

---

```
public function isThursday(): bool

$date = (new Jalali(1397, 6, 22))->isThursday()
// output: true
```

---

```
public function getDayOfYear(): int

$date = (new Jalali(1397, 5, 24))->getDayOfYear()
// output: 179
```

---

```
public function toString(): string
$date = (new Jalali(1397, 5, 24))->isPast()
// output: 1397-05-24 00:00:00
```

---

```
public function format(string $format): string

$date = (new Jalali(1397, 5, 24))->format('y')
// output: 1397
// see php date formats
```

---

```
public function __toString(): string

// Alias of toString()
```

---

```
public function ago(): string
```

---

```
public function getTimestamp(): int
```

---

```
public function getNextWeek(): Jalali
```

---

```
public function getNextMonth(): Jalali
```

---

### CalendarUtils

[](#calendarutils)

---

#### `checkDate($year, $month, $day, [$isJalali = true])`

[](#checkdateyear-month-day-isjalali--true)

```
// Check jalali date
\Ariaieboy\Jalali\CalendarUtils::checkDate(1391, 2, 30, true); // true

// Check jalali date
\Ariaieboy\Jalali\CalendarUtils::checkDate(2016, 5, 7); // false

// Check gregorian date
\Ariaieboy\Jalali\CalendarUtils::checkDate(2016, 5, 7, false); // true
```

---

#### `toJalali($gYear, $gMonth, $gDay)`

[](#tojalaligyear-gmonth-gday)

```
\Ariaieboy\Jalali\CalendarUtils::toJalali(2016, 5, 7); // [1395, 2, 18]
```

---

#### `toGregorian($jYear, $jMonth, $jDay)`

[](#togregorianjyear-jmonth-jday)

```
\Ariaieboy\Jalali\CalendarUtils::toGregorian(1395, 2, 18); // [2016, 5, 7]
```

---

#### `strftime($format, [$timestamp = false, $timezone = null])`

[](#strftimeformat-timestamp--false-timezone--null)

```
CalendarUtils::strftime('Y-m-d', strtotime('2016-05-8')); // 1395-02-19
```

---

#### `createDateTimeFromFormat($format, $jalaiTimeString)`

[](#createdatetimefromformatformat-jalaitimestring)

```
$Jalali = '1394/11/25 15:00:00';

// get instance of \DateTime
$dateTime = \Ariaieboy\Jalali\CalendarUtils::createDatetimeFromFormat('Y/m/d H:i:s', $Jalali);
```

---

#### `createCarbonFromFormat($format, $jalaiTimeString)`

[](#createcarbonfromformatformat-jalaitimestring)

```
$Jalali = '1394/11/25 15:00:00';

// get instance of \Carbon\Carbon
$carbon = \Ariaieboy\Jalali\CalendarUtils::createCarbonFromFormat('Y/m/d H:i:s', $Jalali);
```

---

#### `convertNumbers($string)`

[](#convertnumbersstring)

```
// convert latin to persian
$date = \Ariaieboy\Jalali\CalendarUtils::strftime('Y-m-d', strtotime('2016-05-8')); // 1395-02-19
\Ariaieboy\Jalali\CalendarUtils::convertNumbers($date); // ۱۳۹۵-۰۲-۱۹

// convert persian to latin
$dateString = \Ariaieboy\Jalali\CalendarUtils::convertNumbers('۱۳۹۵-۰۲-۱۹', true); // 1395-02-19
\Ariaieboy\Jalali\CalendarUtils::createCarbonFromFormat('Y-m-d', $dateString)->format('Y-m-d'); //2016-05-8
```

---

#### `Carbon api-difference`

[](#carbon-api-difference)

You can convert date/time to [briannesbitt/carbon](https://github.com/briannesbitt/carbon), thus being able to use it's [API](https://carbon.nesbot.com/docs/) to work with PHP DateTime class.

##### [Difference](https://carbon.nesbot.com/docs/#api-difference) in months:

[](#difference-in-months)

```
// convert persian to Carbon
$date = \Ariaieboy\Jalali\Jalali::fromFormat('Y-m-d', "1395-02-19")->toCarbon();
// ->toString() => Sun May 08 2016 00:00:00 GMT+0000

// Add 4 months to Carbon
$dateAdd4Months = $date->addMonths(4);

// Difference in months
$dateAdd4Months->DiffInMonths($date); //4
$dateAdd4Months->floatDiffInMonths($date); //4.0
```

---

Formatting
----------

[](#formatting)

For help in building your formats, checkout the [PHP strftime() docs](http://php.net/manual/en/function.strftime.php).

Notes
-----

[](#notes)

The class relies on `strtotime()` to make sense of your strings, and `strftime()` to handle the formatting. Always check the `time()` output to see if you get false timestamps, it which case, means the class couldn't understand what you were asking it to do.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [AriaieBOY](https://github.com/ariaieboy)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 65.1% 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 ~174 days

Total

5

Last Release

111d ago

PHP version history (4 changes)1.0.0PHP ~8.2||~8.3

1.0.1PHP ~8.2|~8.3|~8.4

1.2.0PHP ~8.3|~8.4

1.2.1PHP ~8.3|~8.4|~8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/e89700c75410a20d43857b37107b59d3dffe75166434efa9bed47668723fcdb9?d=identicon)[ariaieboy](/maintainers/ariaieboy)

---

Top Contributors

[![ariaieboy](https://avatars.githubusercontent.com/u/15873972?v=4)](https://github.com/ariaieboy "ariaieboy (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

Jalalishamsiariaieboypersian-calendar

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ariaieboy-jalali/health.svg)

```
[![Health](https://phpackages.com/badges/ariaieboy-jalali/health.svg)](https://phpackages.com/packages/ariaieboy-jalali)
```

###  Alternatives

[hekmatinasser/verta

This Package helps developers to work with Jalali Datetime class for Laravel Framework PHP

657530.5k27](/packages/hekmatinasser-verta)[morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.

9201.2M45](/packages/morilog-jalali)[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.

36473.2k8](/packages/fisharebest-ext-calendar)[opilo/farsi

Farsi Tools for Dates and Numbers and Strings (with Laravel Validation Support)

333.2k1](/packages/opilo-farsi)[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)[symfony_persia/symfonyjdate

Jalali (Shamsi) DateTime for Symfony2, Supports year higher than 2038

1010.6k](/packages/symfony-persia-symfonyjdate)

PHPackages © 2026

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