CakeFest 2024: The Official CakePHP Conference

easter_days

(PHP 4, PHP 5, PHP 7, PHP 8)

easter_days指定した年において、3 月 21 日から復活祭までの日数を得る

説明

easter_days(?int $year = null, int $mode = CAL_EASTER_DEFAULT): int

指定した年 year において、3 月 21 日から復活祭までの日数を返します。 year が指定されない場合、現在の年が仮定されます。

この関数は、Unix 時の範囲外(すなわち 1970 年以前または 2037 年以降)の復活祭を 計算するために easter_date() の代わりに使用することが できます。

復活祭の日付は、西暦 325 年の Nicaea の会議で春分の日以降の 最初の満月の後の日曜日として定義されました。 満月とその次の日曜日の日付の計算を簡単にするために 春分の日は常に 3 月 21 日になるとして計算されます。 ここで用いるアルゴリズムは、532 年頃に Dionysius Exiguus により 導出されたものです。(1753 年より前の年に関して)ユリウス暦のもとでは 月の周期を追うために簡単な 19 年周期が用いられます。グレゴリオ暦 (1753 年以降。この暦は Clavius と Lilius により考案され、 教皇グレゴリウス 13 世により 1582 年 10 月に導入、イギリス及びその植民地に 1752 年 9 月に導入された) のもとで、二つの補正係数が周期をより正確に作成するために追加されました。

パラメータ

year

正の数値で表した年。省略した場合、もしくは null の場合は、 ローカルタイムにおける現在の年を使います。

mode

CAL_EASTER_ROMAN に設定すると 1582 年から 1752 年までの復活祭の日付をグレゴリオ暦にもとづいて 計算します。それ以外に使用可能な定数については カレンダー定数を参照ください。

戻り値

指定した年 year において、3 月 21 日から復活祭までの日数を返します。

変更履歴

バージョン 説明
8.0.0 year は、nullable になりました。

例1 easter_days() の例

<?php

echo easter_days(1999); // 14, i.e. April 4
echo easter_days(1492); // 32, i.e. April 22
echo easter_days(1913); // 2, i.e. March 23

?>

参考

  • easter_date() - 指定した年における復活祭の真夜中のUnix時を得る

add a note

User Contributed Notes 2 notes

up
6
p dot rijt at caesar dot nl
8 years ago
This function returns an array of timestamp corresponding to Dutch National holidays. Liberation Day (Bevrijdingsdag) is added as a National holiday once every five years (2000, 2005, 2010, ...).

<?php
function getHolidays($year = null) {
if (
$year === null) {
$year = intval(date('Y'));
}

$easterDate = easter_date($year);
$easterDay = date('j', $easterDate);
$easterMonth = date('n', $easterDate);
$easterYear = date('Y', $easterDate);

$holidays = array(
// Nieuwjaarsdag
mktime(0, 0, 0, 1, 1, $year),
// 1e Kerstdag
mktime(0, 0, 0, 12, 25, $year),
// 2e Kerstdag
mktime(0, 0, 0, 12, 26, $year)
);

// Bevrijdingsdag
if (($year % 5) == 0) {
$holidays[] = mktime(0, 0, 0, 5, 5, $year);
}

// Koninginnedag (< 2014) of Koningsdag (>= 2014).
// Verplaats naar zaterdag als het valt op zondag.
if ($year <= 2013) { // Koninginnedag <= 2013
if (date('w', mktime(0, 0, 0, 4, 30, $year)) == 0) { // Op zondag?
$holidays[] = mktime(0, 0, 0, 4, 29, $year); // Verplaats naar zaterdag
} else {
$holidays[] = mktime(0, 0, 0, 4, 30, $year); // Koninginnedag
}
} else {
// Koningsdag > 2014
if (date('w', mktime(0, 0, 0, 4, 27, $year)) == 0) { // Op zondag?
$holidays[] = mktime(0, 0, 0, 4, 26, $year); // Verplaats naar zaterdag
} else {
$holidays[] = mktime(0, 0, 0, 4, 27, $year); // Koningsdag
}
}

// Onderstaande dagen hebben een datum afhankelijk van Pasen
// Goede Vrijdag (= pasen - 2)
$holidays[] = strtotime('-2 days', mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear));
// 1e Paasdag
$holidays[] = mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear);
// 2e Paasdag (= pasen +1)
$holidays[] = strtotime('+1 days', mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear));
// Hemelvaartsdag (= pasen + 39)
$holidays[] = strtotime('+39 days', mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear));
// 1e Pinksterdag (= pasen + 49)
$holidays[] = strtotime('+49 days', mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear));
// 2e Pinksterdag (= pasen + 50)
$holidays[] = strtotime('+50 days', mktime(0, 0, 0, $easterMonth, $easterDay, $easterYear));

sort($holidays);

return
$holidays;
}

$holidays = getHolidays(2014);

foreach (
$holidays as $holiday) {
echo
date('d-M-Y', $holiday) . '<br>';
}
?>
up
0
ian at eiloart dot com-NOSPAM
22 years ago
Also, be aware that the eastern orthodox churches sometimes have different dates for easter. See, for example <http://webexhibits.org/calendars/calendar-christian-easter.html>. And note that the dates of easter a subject to change, for example, the churches might some day decide to unify the dates.
To Top