roukmoute / polyfill-calendar
PHP Polyfill for the Calendar extension
Installs: 11 831
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
pkg:composer/roukmoute/polyfill-calendar
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pedrotroller/php-cs-custom-fixer: ^2.19
- phpspec/phpspec: ^7.2
- phpstan/phpstan: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- pyrech/composer-changelogs: ^1.7
- roave/security-advisories: dev-master
- vimeo/psalm: ^5.0
- dev-master / 1.1.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4
- v0.3
- v0.2
- v0.1
- dev-fix-branch-alias
- dev-improve-readme
- dev-implement-easter-mode
- dev-add-missing-constants
- dev-add-cal-info
- dev-add-cal-from-jd
- dev-add-jdmonthname
- dev-add-jddayofweek
- dev-add-jdtofrench
- dev-add-jdtojulian
- dev-add-unixtojd
- dev-add-jdtounix
- dev-add-frenchtojd
- dev-fix-readme-badge
- dev-add-gregoriantojd
- dev-refactor-linter-workflow
- dev-add-cal-days-in-month
- dev-add-jdtojewish
- dev-drop-php-7-support
- dev-add_cal_days_in_month
This package is auto-updated.
Last update: 2026-01-17 09:44:32 UTC
README
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.
Requirements
- PHP 8.0 or higher
Installation
composer require roukmoute/polyfill-calendar
Supported Calendars
| Constant | Calendar |
|---|---|
CAL_GREGORIAN |
Gregorian Calendar |
CAL_JULIAN |
Julian Calendar |
CAL_JEWISH |
Jewish Calendar |
CAL_FRENCH |
French Republican Calendar |
Available Functions
Calendar Conversion
| 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 |
Gregorian Calendar
| Function | Description |
|---|---|
gregoriantojd |
Converts a Gregorian date to Julian Day Count |
jdtogregorian |
Converts Julian Day Count to Gregorian date |
Julian Calendar
| Function | Description |
|---|---|
juliantojd |
Converts a Julian Calendar date to Julian Day Count |
jdtojulian |
Converts a Julian Day Count to Julian Calendar Date |
Jewish Calendar
| Function | Description |
|---|---|
jewishtojd |
Converts a date in the Jewish Calendar to Julian Day Count |
jdtojewish |
Converts a Julian Day Count to the Jewish Calendar |
French Republican 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 |
Easter Functions
| 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 |
Unix Timestamp Conversion
| Function | Description |
|---|---|
unixtojd |
Convert Unix timestamp to Julian Day |
jdtounix |
Convert Julian Day to Unix timestamp |
Utility Functions
| Function | Description |
|---|---|
jddayofweek |
Returns the day of the week for a Julian Day |
jdmonthname |
Returns a month name |
Usage Examples
Converting between calendars
// 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"
Getting Easter date
// 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
Calendar information
// 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
Days in a month
// 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); // 28
Available Constants
Calendar Types
CAL_GREGORIAN,CAL_JULIAN,CAL_JEWISH,CAL_FRENCH,CAL_NUM_CALS
Day of Week Modes
CAL_DOW_DAYNO,CAL_DOW_SHORT,CAL_DOW_LONG
Month Name Modes
CAL_MONTH_GREGORIAN_SHORT,CAL_MONTH_GREGORIAN_LONGCAL_MONTH_JULIAN_SHORT,CAL_MONTH_JULIAN_LONGCAL_MONTH_JEWISH,CAL_MONTH_FRENCH
Easter Calculation Modes
CAL_EASTER_DEFAULT,CAL_EASTER_ROMANCAL_EASTER_ALWAYS_GREGORIAN,CAL_EASTER_ALWAYS_JULIAN
Jewish Calendar Formatting
CAL_JEWISH_ADD_ALAFIM_GERESH,CAL_JEWISH_ADD_ALAFIM,CAL_JEWISH_ADD_GERESHAYIM
License
This library is released under the MIT license.