fisharebest / calendar
Implementation of the Arabic (Hijri), French, Gregorian, Jewish, Julian and Persian (Jalali) calendars.
Requires
- php: ~8.3
Requires (Dev)
- ext-calendar: *
- infection/infection: ^0.35
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^4.0
- vimeo/psalm: ^6.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-17 09:13:23 UTC
README
This package provides an implementation of the Arabic (Hijri), French Republican, Gregorian, Julian, Jewish and Persian (Jalali) calendars
Note, until version 2.6, this package was called fisharebest/ext-calendar, and
also provided a polyfill for PHP’s ext/calendar extension.
Since version 3.0, it is called fisharebest/calendar, and just provides calendar
conversions.
How to use it
composer require fisharebest/calendar
require 'vendor/autoload.php';
// Create calendars
$calendar = new Fisharebest\Calendar\ArabicCalendar;
$calendar = new Fisharebest\Calendar\FrenchCalendar;
$calendar = new Fisharebest\Calendar\GregorianCalendar;
$calendar = new Fisharebest\Calendar\JewishCalendar;
$calendar = new Fisharebest\Calendar\JulianCalendar;
$calendar = new Fisharebest\Calendar\PersianCalendar;
// Date conversions
$julian_day = $calendar->ymdToJd(year: $year, month: $month, day: $day);
[$year, $month, $day] = $calendar->jdToYmd(julian_day: $julian_day);
// Information about days, weeks and months
$is_leap_year = $calendar->isLeapYear(year: $year);
$days_in_month = $calendar->daysInMonth(year: $year, month: $month);
$months_in_year = $calendar->monthsInYear(year: $year); // Not all years have 12
$days_in_week = $calendar->daysInWeek(); // Not all calendars have 7
// Which dates are valid?
$jd = $calendar->jdStart();
$jd = $calendar->jdEnd();
daysInMonth() only validates the year when the month length depends on it.
Year checks are performed by the underlying leap-year or year-type calculation;
fixed-length months do not require a valid year. The Jewish leap-year calculation
accepts year zero for preceding-year calculations, but Jewish year types require
a positive year.
Development checks
Run composer ci to run PHPStan, Psalm, PHPUnit, PHP_CodeSniffer and Infection,
or run each check separately using composer phpstan, composer psalm,
composer phpunit, composer phpcs and composer infection.
Infection also uses PHPStan to kill mutants rejected by static analysis.
PHPUnit produces a text coverage report and .coverage/clover.xml. PHPUnit and
Infection require a code coverage driver such as PCOV or Xdebug; enable Xdebug's
coverage mode with XDEBUG_MODE=coverage when using Xdebug.
Future plans
- Support alternate leap-year schemes for the French calendar (true equinox, Romme, 128-year cycle) as well as the 4-year cycle.
- Support other calendars, such as Ethiopian, Hindu, Chinese, Swedish, etc.