← All docs

Calendar

The ext/calendar functions: Julian Day conversions for the Gregorian, Julian, French Republican and Jewish calendars, plus Easter and calendar metadata.

elephc implements PHP’s ext/calendar extension. Every function is pure integer Julian-Day-Number arithmetic (a faithful port of PHP’s sdncal algorithms), so results are byte-identical to PHP.

Julian Day conversions

The Julian Day Number (JD) is a continuous day count used as the common pivot between calendars. Each calendar has a *tojd function and an inverse jdto* function that returns an "m/d/y" string ("0/0/0" for out-of-range input).

CalendarTo JDFrom JD
Gregoriangregoriantojd($month, $day, $year)jdtogregorian($jd)
Julianjuliantojd($month, $day, $year)jdtojulian($jd)
French Republicanfrenchtojd($month, $day, $year)jdtofrench($jd)
Jewishjewishtojd($month, $day, $year)jdtojewish($jd)
$jd = gregoriantojd(1, 1, 2000);   // 2451545
echo jdtogregorian($jd);           // "1/1/2000"
echo jdtojewish($jd);              // "4/23/5760"

jdtojewish() accepts the PHP $hebrew and $flags arguments for signature compatibility, but always returns the numeric "m/d/y" form — Hebrew-script output is not produced.

Generic dispatch

cal_to_jd(), cal_from_jd(), cal_days_in_month() and cal_info() take a calendar selector: CAL_GREGORIAN (0), CAL_JULIAN (1), CAL_JEWISH (2), CAL_FRENCH (3).

cal_to_jd(CAL_GREGORIAN, 1, 1, 2000);        // 2451545
cal_days_in_month(CAL_GREGORIAN, 2, 2024);   // 29
cal_days_in_month(CAL_JEWISH, 1, 5784);      // 30 (Tishri)

$info = cal_from_jd(2451545, CAL_GREGORIAN);
// ["date" => "1/1/2000", "month" => 1, "day" => 1, "year" => 2000,
//  "dow" => 6, "abbrevdayname" => "Sat", "dayname" => "Saturday",
//  "abbrevmonth" => "Jan", "monthname" => "January"]

cal_info(CAL_JEWISH)["calname"];             // "Jewish"
count(cal_info());                            // 4 (all calendars when no argument)

Day and month names

jddayofweek($jd, CAL_DOW_DAYNO);   // 0-6 (Sunday = 0)
jddayofweek($jd, CAL_DOW_LONG);    // "Saturday"
jddayofweek($jd, CAL_DOW_SHORT);   // "Sat"

jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG);   // "January"
jdmonthname($jd, CAL_MONTH_JULIAN_SHORT);     // "Jan"
jdmonthname($jd, CAL_MONTH_JEWISH);           // "Tishri"
jdmonthname($jd, CAL_MONTH_FRENCH);           // "Vendemiaire"

Easter

easter_days(2024);                              // 10  (days after March 21)
easter_days(1750, CAL_EASTER_ALWAYS_JULIAN);    // 25
easter_date(2024);                              // Unix timestamp of Easter midnight

easter_days()/easter_date() default the year to the current year. The $mode selector is one of CAL_EASTER_DEFAULT (0), CAL_EASTER_ROMAN (1), CAL_EASTER_ALWAYS_GREGORIAN (2), CAL_EASTER_ALWAYS_JULIAN (3). easter_date() returns a timestamp built with mktime(), so it follows the default timezone (UTC unless changed).

Unix time

unixtojd(0);            // 2440588  (Julian Day of the Unix epoch)
unixtojd();             // Julian Day of the current date
jdtounix(2440588);      // 0

unixtojd() with no argument uses the current time; passing an explicit 0 means the epoch.

Functions {#functions}

Generated from the shared symbol catalog by scripts/docs/gen_module_sections.py; do not edit this section by hand. Each function links to its reference page.

FunctionSignatureReturnsAOTeval()
cal_days_in_month()(int $calendar, int $month, int $year): intint
cal_from_jd()(int $julian_day, int $calendar): arrayarray
cal_info()(int $calendar = -1): arrayarray
cal_to_jd()(int $calendar, int $month, int $day, int $year): intint
easter_date()(?int $year = null, int $mode = CAL_EASTER_DEFAULT): intint
easter_days()(?int $year = null, int $mode = CAL_EASTER_DEFAULT): intint
frenchtojd()(int $month, int $day, int $year): intint
gregoriantojd()(int $month, int $day, int $year): intint
jddayofweek()(int $julian_day, int $mode = CAL_DOW_DAYNO): mixedmixed
jdmonthname()(int $julian_day, int $mode): stringstring
jdtofrench()(int $julian_day): stringstring
jdtogregorian()(int $julian_day): stringstring
jdtojewish()(int $julian_day, bool $hebrew = false, int $flags = 0): stringstring
jdtojulian()(int $julian_day): stringstring
jdtounix()(int $julian_day): intint
jewishtojd()(int $month, int $day, int $year): intint
juliantojd()(int $month, int $day, int $year): intint
unixtojd()(?int $timestamp = null): mixedmixed

Constants: CAL_DOW_DAYNO, CAL_DOW_LONG, CAL_DOW_SHORT, CAL_EASTER_ALWAYS_GREGORIAN, CAL_EASTER_ALWAYS_JULIAN, CAL_EASTER_DEFAULT, CAL_EASTER_ROMAN, CAL_FRENCH, CAL_GREGORIAN, CAL_JEWISH, CAL_JEWISH_ADD_ALAFIM, CAL_JEWISH_ADD_ALAFIM_GERESH, CAL_JEWISH_ADD_GERESHAYIM, CAL_JULIAN, CAL_MONTH_FRENCH, CAL_MONTH_GREGORIAN_LONG, CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_JEWISH, CAL_MONTH_JULIAN_LONG, CAL_MONTH_JULIAN_SHORT, CAL_NUM_CALS.