Location: PHPKode > scripts > Easter Date Calculator > easterdatecalculator.php
<?php
/**
 * easterdatecalculator
 * This class will output calculate the date on which easter will fall for a given year.
 *
 * Other Christian Hollydays:
 * Carnaval      (Mardi Grass)   -49 days from Easter
 * Aswoensdag    (Ash Wednesday) -46 days from Easter
 * Goede vrijdag (Good Friday)    -2 days from Easter
 * Hemelvaart    (Assention)     +39 days from Easter
 * Pinksteren    (Pentecost)     +49 days from Easter
 *
 * Copyright (C) 2010 by Marcel Bachus
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *_________________________________________________________________________
 *
 * Updates:
 * version 1.0 - First release of the class, for more explanations please
 *               see the example1.php
 *
 **/

class easterdatecalculator
{
  function eastercalculator($year)
  {
    /**
     * G is the Golden Number-1
     * H is 23-Epact (modulo 30)
     * I is the number of days from 21 March to the Paschal full moon
     * J is the weekday for the Paschal full moon (0=Sunday, 1=Monday, etc.)
     * L is the number of days from 21 March to the Sunday on or before the Paschal full moon (a number between -6 and 28)
     **/

    $G = $year % 19;
    $C = intval($year / 100);
    $H = intval($C - intval($C / 4) - intval((8*$C+13) / 25) + 19*$G + 15) % 30;
    $I = intval($H - intval($H / 28) * (1 - intval($H / 28) * intval(29 / ($H + 1)) * (intval(21 - $G) / 11)));
    $J = ($year + intval($year/4) + $I + 2 - $C + intval($C/4)) % 7;
    $L = $I - $J;

    $this->m = 3 + intval(($L + 40) / 44);
    $this->d = $L + 28 - 31 * (intval($this->m / 4));
    $this->y = $year;

    $this->easter = mktime(0,0,0, $this->m, $this->d, $this->y);
  }

  /**
   * Calculates the Easterdate for a particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd
   **/
  function easter($year)
  {
    $this->eastercalculator($year);
    return $this->easter ;
  }

  /**
   * Calculates the date difference in $days from the Easterdate for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function calcdate($year, $days)
  {
    $this->eastercalculator($year);
    $this->calcdate = mktime(0,0,0, $this->m, $this->d + $days, $this->y);
    return $this->calcdate;
  }

  /**
   * Calculates the date for Mardi Grass (in dutch called Carnaval) for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function carnaval($year)
  {
    $days = -49;
    $this->carnaval = $this->calcdate($year, $days) ;
    return $this->carnaval;
  }
  function mardi_grass($year)
  {
    $days = -49;
    $this->carnaval = $this->calcdate($year, $days) ;
    return $this->carnaval;
  }

  /**
   * Calculates the date for Ash Wednessday (in dutch called Aswoensday) for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function aswoensdag($year)
  {
    $days = -46;
    $this->aswoensdag = $this->calcdate($year, $days) ;
    return $this->aswoensdag;
  }
  function ash_wednesday($year)
  {
    $days = -46;
    $this->ash_wednesday = $this->calcdate($year, $days) ;
    return $this->ash_wednesday;
  }

  /**
   * Calculates the date for Good Friday (in dutch called Goede Vrijdag) for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function goede_vrijdag($year)
  {
    $days = -2;
    $this->goede_vrijdag = $this->calcdate($year, $days) ;
    return $this->goede_vrijdag;
  }
  function good_friday($year)
  {
    $days = -2;
    $this->good_friday = $this->calcdate($year, $days) ;
    return $this->good_friday;
  }

  /**
   * Calculates the date for Assention (in dutch called Hemelvaartsdag) for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function hemelvaartsdag($year)
  {
    $days = 39;
    $this->goede_vrijdag = $this->calcdate($year, $days) ;
    return $this->goede_vrijdag;
  }
  function assention($year)
  {
    $days = 39;
    $this->assention = $this->calcdate($year, $days) ;
    return $this->assention;
  }

  /**
   * Calculates the date for Pentacost (in dutch called Pinksteren) for a
   * particular year and outputs a timestamp.
   * This timestamp can then be translated to a real date by using the function date("Y-m-d", $timestamp)
   * showing the date as yyyy-mm-dd.
   **/
  function pinksteren($year)
  {
    $days = 49;
    $this->pinksteren = $this->calcdate($year, $days) ;
    return $this->pinksteren;
  }
  function pentecost($year)
  {
    $days = 49;
    $this->pentecost = $this->calcdate($year, $days) ;
    return $this->pentecost;
  }

}


?>
Return current item: Easter Date Calculator