KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > date > EasterSundayRule


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------
28  * EasterSundayRule.java
29  * ---------------------
30  * (C) Copyright 2000-2003, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: EasterSundayRule.java,v 1.4 2005/11/16 15:58:40 taqua Exp $
36  *
37  * Changes (from 26-Oct-2001)
38  * --------------------------
39  * 26-Oct-2001 : Changed package to com.jrefinery.date.*;
40  * 03-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  * 01-Jun-2005 : Removed the explicit clonable declaration, it is declared
42  * in the super class.
43  */

44
45 package org.jfree.date;
46
47 /**
48  * An annual date rule for Easter (Sunday). The algorithm used here was
49  * obtained from a Calendar FAQ which can be found at:
50  * <P>
51  * <a HREF="http://www.tondering.dk/claus/calendar.html"
52  * >http://www.tondering.dk/claus/calendar.html</a>.
53  * <P>
54  * It is based on an algorithm by Oudin (1940) and quoted in "Explanatory Supplement to the
55  * Astronomical Almanac", P. Kenneth Seidelmann, editor.
56  *
57  * @author David Gilbert
58  */

59 public class EasterSundayRule extends AnnualDateRule {
60
61     /**
62      * Default constructor.
63      */

64     public EasterSundayRule() {
65     }
66
67     /**
68      * Returns the date of Easter Sunday for the given year. See the class
69      * description for the source of the algorithm.
70      * <P>
71      * This method supports the AnnualDateRule interface.
72      *
73      * @param year the year to check.
74      *
75      * @return the date of Easter Sunday for the given year.
76      */

77     public SerialDate getDate(final int year) {
78         final int g = year % 19;
79         final int c = year / 100;
80         final int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
81         final int i = h - h / 28 * (1 - h / 28 * 29 / (h + 1) * (21 - g) / 11);
82         final int j = (year + year / 4 + i + 2 - c + c / 4) % 7;
83         final int l = i - j;
84         final int month = 3 + (l + 40) / 44;
85         final int day = l + 28 - 31 * (month / 4);
86         return SerialDate.createInstance(day, month, year);
87     }
88
89 }
90
Popular Tags