EasterSundayRule.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. package org.jfree.date;
  45. /**
  46. * An annual date rule for Easter (Sunday). The algorithm used here was
  47. * obtained from a Calendar FAQ which can be found at:
  48. * <P>
  49. * <a href="http://www.tondering.dk/claus/calendar.html"
  50. * >http://www.tondering.dk/claus/calendar.html</a>.
  51. * <P>
  52. * It is based on an algorithm by Oudin (1940) and quoted in "Explanatory Supplement to the
  53. * Astronomical Almanac", P. Kenneth Seidelmann, editor.
  54. *
  55. * @author David Gilbert
  56. */
  57. public class EasterSundayRule extends AnnualDateRule {
  58. /**
  59. * Default constructor.
  60. */
  61. public EasterSundayRule() {
  62. }
  63. /**
  64. * Returns the date of Easter Sunday for the given year. See the class
  65. * description for the source of the algorithm.
  66. * <P>
  67. * This method supports the AnnualDateRule interface.
  68. *
  69. * @param year the year to check.
  70. *
  71. * @return the date of Easter Sunday for the given year.
  72. */
  73. public SerialDate getDate(final int year) {
  74. final int g = year % 19;
  75. final int c = year / 100;
  76. final int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
  77. final int i = h - h / 28 * (1 - h / 28 * 29 / (h + 1) * (21 - g) / 11);
  78. final int j = (year + year / 4 + i + 2 - c + c / 4) % 7;
  79. final int l = i - j;
  80. final int month = 3 + (l + 40) / 44;
  81. final int day = l + 28 - 31 * (month / 4);
  82. return SerialDate.createInstance(day, month, year);
  83. }
  84. }