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

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

abotalebie/jalali
=================

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

v3.3.1(5y ago)022MITPHPPHP ^7.0 | ^7.1 | ^7.2 | ^8.0

Since Jun 10Pushed 5y agoCompare

[ Source](https://github.com/abotalebie/jalali)[ Packagist](https://packagist.org/packages/abotalebie/jalali)[ RSS](/packages/abotalebie-jalali/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (31)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5051219155814fef6ae9ed7bfad3934f2a10e12cabce41887373226e668cdb21/68747470733a2f2f7472617669732d63692e6f72672f6d6f72696c6f672f6a616c616c692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/morilog/jalali)abotalebie/jalali
==========================================================================================================================================================================================================================================================================================

[](#abotalebiejalali)

- 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.
- CalendarUtils class was ported from [jalaali/jalaali-js](https://github.com/jalaali/jalaali-js)

Version 3 features
------------------

[](#version-3-features)

- High human readable API
- DateTime manipulating API
- DateTime comparing API
- Immutable

Installation Version 3.\*
-------------------------

[](#installation-version-3)

Run the Composer update command

```
$ composer require abotalebie/jalali:3.*

```

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

[](#basic-usage)

In the current version, I introduced `Jalalian` class for manipulating Jalali date time

### Jalalian

[](#jalalian)

In version &gt;= 1.1, you can use `jdate()` instead of `Jalalian::forge()`;

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

[](#nowtimestamp--null)

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

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

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

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

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

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

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

#### Methods api

[](#methods-api)

---

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

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

---

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

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

---

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

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

---

```
public static function forge($timestamp, \DateTimeZone $timeZone = null): Jalalian

// Alias fo fromDatetime
```

---

```
public static function fromDateTime($dateTime, \DateTimeZone $timeZone = null): Jalalian

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

---

```
public function getMonthDays(): int

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

---

```
public function getMonth(): int

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

---

```
public function isLeapYear(): bool

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

---

```
public function getYear(): int

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

---

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

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

---

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

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

---

```
public function getDay(): int

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

---

```
public function getHour(): int

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

---

```
public function getMinute(): int

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

---

```
public function getSecond(): int

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

---

```
public function getTimezone(): \DateTimeZone

// Get current timezone
```

---

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

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

---

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

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

---

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

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

---

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

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

---

```
public function toCarbon(): Carbon

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

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

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

---

```
public function isStartOfWeek(): bool

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

---

```
public function isSaturday(): bool

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

---

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

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

---

```
public function isEndOfWeek(): bool

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

---

```
public function isFriday(): bool

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

---

```
public function isToday(): bool

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

---

```
public function isTomorrow(): bool

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

---

```
public function isYesterday(): bool

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

---

```
public function isFuture(): bool

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

---

```
public function isPast(): bool

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

---

```
public function toArray(): array
$date = (new Jalalian(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 Jalalian(1397, 5, 24))->getDayOfWeek()
// output: 0
```

---

```
public function isSunday(): bool

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

---

```
public function isMonday(): bool

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

---

```
public function isTuesday(): bool

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

---

```
public function isWednesday(): bool

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

---

```
public function isThursday(): bool

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

---

```
public function getDayOfYear(): int

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

---

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

---

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

$date = (new Jalalian(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(): Jalalian
```

---

```
public function getNextMonth(): Jalalian
```

---

### CalendarUtils

[](#calendarutils)

---

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

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

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

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

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

---

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

[](#tojalaligyear-gmonth-gday)

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

---

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

[](#togregorianjyear-jmonth-jday)

```
\Abotalebie\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)

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

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

---

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

[](#createcarbonfromformatformat-jalaitimestring)

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

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

---

#### `convertNumbers($string)`

[](#convertnumbersstring)

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

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

---

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.

License
-------

[](#license)

- This bundle is created based on [Laravel-Date](https://github.com/swt83/laravel-date) by [Scott Travis](https://github.com/swt83) (MIT Licensed).
- [Jalali (Shamsi) DateTime](https://github.com/sallar/CalendarUtils) class included in the package is created by [Sallar Kaboli](http://sallar.me) and is released under the MIT License.
- This package is created and modified by [Morteza Parvini](http://morilog.ir) for Laravel &gt;= 5 and is released under the MIT License.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~75 days

Recently: every ~190 days

Total

29

Last Release

1866d ago

Major Versions

v0.1 → v1.02015-07-12

v1.1 → v2.02016-05-08

v2.3.0 → v3.0.02018-09-15

PHP version history (6 changes)v0.1PHP &gt;=5.4

v1.0.1PHP &gt;=5.5

v3.0.0PHP &gt;=7.0

v3.0.9PHP ^7.0

v3.0.10PHP ^7.0 | ^7.1 | ^7.2

v3.2.0PHP ^7.0 | ^7.1 | ^7.2 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/426ff255ebcaeccbdbb807019773b670928c12c306e7862bb36c38d63e2f8a91?d=identicon)[aboutalebi](/maintainers/aboutalebi)

---

Top Contributors

[![morilog](https://avatars.githubusercontent.com/u/4139179?v=4)](https://github.com/morilog "morilog (36 commits)")[![miladr](https://avatars.githubusercontent.com/u/1630638?v=4)](https://github.com/miladr "miladr (21 commits)")[![abotalebie](https://avatars.githubusercontent.com/u/2395041?v=4)](https://github.com/abotalebie "abotalebie (4 commits)")[![mahdiraad](https://avatars.githubusercontent.com/u/5654587?v=4)](https://github.com/mahdiraad "mahdiraad (3 commits)")[![cracki](https://avatars.githubusercontent.com/u/5469394?v=4)](https://github.com/cracki "cracki (3 commits)")[![dena-a](https://avatars.githubusercontent.com/u/4950968?v=4)](https://github.com/dena-a "dena-a (2 commits)")[![mohsen-hsh74](https://avatars.githubusercontent.com/u/62648733?v=4)](https://github.com/mohsen-hsh74 "mohsen-hsh74 (1 commits)")[![ocalypto](https://avatars.githubusercontent.com/u/829777?v=4)](https://github.com/ocalypto "ocalypto (1 commits)")[![reza-akbari](https://avatars.githubusercontent.com/u/35025677?v=4)](https://github.com/reza-akbari "reza-akbari (1 commits)")[![thearsalan](https://avatars.githubusercontent.com/u/12055863?v=4)](https://github.com/thearsalan "thearsalan (1 commits)")[![thg303](https://avatars.githubusercontent.com/u/6162994?v=4)](https://github.com/thg303 "thg303 (1 commits)")[![amin3mej](https://avatars.githubusercontent.com/u/4997188?v=4)](https://github.com/amin3mej "amin3mej (1 commits)")[![amiriun](https://avatars.githubusercontent.com/u/5228893?v=4)](https://github.com/amiriun "amiriun (1 commits)")[![immeyti](https://avatars.githubusercontent.com/u/24190257?v=4)](https://github.com/immeyti "immeyti (1 commits)")[![mehran-prs](https://avatars.githubusercontent.com/u/22454054?v=4)](https://github.com/mehran-prs "mehran-prs (1 commits)")[![meysammahfouzi](https://avatars.githubusercontent.com/u/14848008?v=4)](https://github.com/meysammahfouzi "meysammahfouzi (1 commits)")

---

Tags

laraveldatetimedateJalaliAbotalebie

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[hekmatinasser/verta

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

657530.5k27](/packages/hekmatinasser-verta)[aloko/nova-persian-datepicker

Persian Datepicker for Laravel Nova.

203.5k](/packages/aloko-nova-persian-datepicker)[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)
