A PHP polyfill for the calendar extension.
This library provides a pure PHP implementation of all calendar extension functions, allowing you to use calendar functionality without requiring the calendar extension to be installed.
- PHP 8.0 or higher
composer require roukmoute/polyfill-calendar| Constant | Calendar |
|---|---|
CAL_GREGORIAN |
Gregorian Calendar |
CAL_JULIAN |
Julian Calendar |
CAL_JEWISH |
Jewish Calendar |
CAL_FRENCH |
French Republican Calendar |
| Function | Description |
|---|---|
cal_to_jd |
Converts from a supported calendar to Julian Day Count |
cal_from_jd |
Converts from Julian Day Count to a supported calendar |
cal_days_in_month |
Return the number of days in a month for a given year and calendar |
cal_info |
Returns information about a particular calendar |
| Function | Description |
|---|---|
gregoriantojd |
Converts a Gregorian date to Julian Day Count |
jdtogregorian |
Converts Julian Day Count to Gregorian date |
| Function | Description |
|---|---|
juliantojd |
Converts a Julian Calendar date to Julian Day Count |
jdtojulian |
Converts a Julian Day Count to Julian Calendar Date |
| Function | Description |
|---|---|
jewishtojd |
Converts a date in the Jewish Calendar to Julian Day Count |
jdtojewish |
Converts a Julian Day Count to the Jewish Calendar |
| Function | Description |
|---|---|
frenchtojd |
Converts a date from the French Republican Calendar to a Julian Day Count |
jdtofrench |
Converts a Julian Day Count to French Republican Calendar Date |
| Function | Description |
|---|---|
easter_date |
Get Unix timestamp for midnight on Easter of a given year |
easter_days |
Get number of days after March 21 on which Easter falls for a given year |
| Function | Description |
|---|---|
unixtojd |
Convert Unix timestamp to Julian Day |
jdtounix |
Convert Julian Day to Unix timestamp |
| Function | Description |
|---|---|
jddayofweek |
Returns the day of the week for a Julian Day |
jdmonthname |
Returns a month name |
// Gregorian to Julian Day Count
$jd = gregoriantojd(12, 25, 2024); // December 25, 2024
// Julian Day Count to Gregorian
$date = jdtogregorian($jd); // "12/25/2024"
// Convert to Jewish calendar
$jewish = jdtojewish($jd); // "10/23/5785"// Get Easter Sunday timestamp for 2025
$easter = easter_date(2025);
echo date('Y-m-d', $easter); // 2025-04-20
// Get days after March 21
$days = easter_days(2025); // 30// Get info about all calendars
$info = cal_info();
// Get info about a specific calendar
$gregorian = cal_info(CAL_GREGORIAN);
print_r($gregorian['months']); // Array of month names// February 2024 (leap year)
$days = cal_days_in_month(CAL_GREGORIAN, 2, 2024); // 29
// February 2023 (not a leap year)
$days = cal_days_in_month(CAL_GREGORIAN, 2, 2023); // 28CAL_GREGORIAN,CAL_JULIAN,CAL_JEWISH,CAL_FRENCH,CAL_NUM_CALS
CAL_DOW_DAYNO,CAL_DOW_SHORT,CAL_DOW_LONG
CAL_MONTH_GREGORIAN_SHORT,CAL_MONTH_GREGORIAN_LONGCAL_MONTH_JULIAN_SHORT,CAL_MONTH_JULIAN_LONGCAL_MONTH_JEWISH,CAL_MONTH_FRENCH
CAL_EASTER_DEFAULT,CAL_EASTER_ROMANCAL_EASTER_ALWAYS_GREGORIAN,CAL_EASTER_ALWAYS_JULIAN
CAL_JEWISH_ADD_ALAFIM_GERESH,CAL_JEWISH_ADD_ALAFIM,CAL_JEWISH_ADD_GERESHAYIM
This library is released under the MIT license.