001    /* ========================================================================
002     * JCommon : a free general purpose class library for the Java(tm) platform
003     * ========================================================================
004     *
005     * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006     * 
007     * Project Info:  http://www.jfree.org/jcommon/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it 
010     * under the terms of the GNU Lesser General Public License as published by 
011     * the Free Software Foundation; either version 2.1 of the License, or 
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but 
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022     * USA.  
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025     * in the United States and other countries.]
026     *
027     * ---------------------
028     * EasterSundayRule.java
029     * ---------------------
030     * (C) Copyright 2000-2003, by Object Refinery Limited.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * $Id: EasterSundayRule.java,v 1.4 2005/11/16 15:58:40 taqua Exp $
036     *
037     * Changes (from 26-Oct-2001)
038     * --------------------------
039     * 26-Oct-2001 : Changed package to com.jrefinery.date.*;
040     * 03-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041     * 01-Jun-2005 : Removed the explicit clonable declaration, it is declared
042     *               in the super class.
043     */
044    
045    package org.jfree.date;
046    
047    /**
048     * An annual date rule for Easter (Sunday).  The algorithm used here was
049     * obtained from a Calendar FAQ which can be found at:
050     * <P>
051     * <a href="http://www.tondering.dk/claus/calendar.html"
052     *     >http://www.tondering.dk/claus/calendar.html</a>.
053     * <P>
054     * It is based on an algorithm by Oudin (1940) and quoted in "Explanatory Supplement to the
055     * Astronomical Almanac", P. Kenneth Seidelmann, editor.
056     *
057     * @author David Gilbert
058     */
059    public class EasterSundayRule extends AnnualDateRule {
060    
061        /**
062         * Default constructor.
063         */
064        public EasterSundayRule() {
065        }
066    
067        /**
068         * Returns the date of Easter Sunday for the given year.  See the class
069         * description for the source of the algorithm.
070         * <P>
071         * This method supports the AnnualDateRule interface.
072         *
073         * @param year  the year to check.
074         *
075         * @return the date of Easter Sunday for the given year.
076         */
077        public SerialDate getDate(final int year) {
078            final int g = year % 19;
079            final int c = year / 100;
080            final int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
081            final int i = h - h / 28 * (1 - h / 28 * 29 / (h + 1) * (21 - g) / 11);
082            final int j = (year + year / 4 + i + 2 - c + c / 4) % 7;
083            final int l = i - j;
084            final int month = 3 + (l + 40) / 44;
085            final int day = l + 28 - 31 * (month / 4);
086            return SerialDate.createInstance(day, month, year);
087        }
088    
089    }