SkySim
Home
>
Algorithms
>
Western Church Holy Days
>
Source Code
Home
Algorithms
Julian Days
Source Code
Western Church Holy Days
Source Code
Sidereal Time
Sun Rise and Set
Moon Rise and Set
About Us
0.15 seconds
Western Church Holy Days Code
Source Code (last updated: 21-May-2008)
#region Copyright (c) 2008 Larry D. Hunt /****************************************************************************** ' ' License: MIT License (also called the X11 License) ' ' Copyright (c) 2008 Larry D. Hunt ' ' Permission is hereby granted, free of charge, to any person obtaining a copy ' of this software and associated documentation files (the "Software"), to deal ' in the Software without restriction, including without limitation the rights ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ' copies of the Software, and to permit persons to whom the Software is ' furnished to do so, subject to the following conditions: ' ' The above copyright notice and this permission notice shall be included in ' all copies or substantial portions of the Software. ' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ' THE SOFTWARE. ' '*****************************************************************************/ #endregion using System; using System.Collections.Generic; using System.Text; using SpaceLib.Tools; namespace SpaceLib.Algorithms { // Western Church Holy Days Algorithms. // Reference: Astronomical Algorithms (2nd edition) by Jean Meeus, ISBN: 0-943396-61-1; Chapter 8. public class WesternChurchHolyDays { #region Properties private DateTime _ashWednesday; public DateTime AshWednesday { get { return _ashWednesday; } set { _ashWednesday = value; } } private DateTime _easter; public DateTime Easter { get { return _easter; } set { _easter = value; } } private DateTime _goodFriday; public DateTime GoodFriday { get { return _goodFriday; } set { _goodFriday = value; } } private DateTime _pentecost; public DateTime Pentecost { get { return _pentecost; } set { _pentecost = value; } } private int _year; public int Year { get { return _year; } set { _year = value; CalculateHolyDays(_year); } } #endregion public WesternChurchHolyDays(int year) { CalculateHolyDays(year); } private void CalculateHolyDays(int year) { JulianDay julianDay = new JulianDay(year, 1, 1); if (julianDay.IsGregorianDateRange()) { CalculateGregorianEaster(year); } else { CalculateJulianEaster(year); } CalculateOtherHolyDays(); } private void CalculateGregorianEaster(int x) { // Note; use one character variable names to match equation in Meeus book. _year = x; int a; Math.DivRem(x, 19, out a); int c; int b = Math.DivRem(x, 100, out c); int e; int d = Math.DivRem(b, 4, out e); int f = (b + 8) / 25; int g = (b - f + 1) / 3; int h; Math.DivRem(((19 * a) + b - d - g + 15), 30, out h); int k; int i = Math.DivRem(c, 4, out k); int l; Math.DivRem((32 + (2 * e) + (2 * i) - h - k), 7, out l); int m = (a + (11 * h) + (22 * l)) / 451; int p; int n = Math.DivRem((h + l - (7 * m) + 114), 31, out p); _easter = new DateTime(x, n, p + 1); } private void CalculateJulianEaster(int x) { // Note; use one character variable names to match equation in Meeus book. _year = x; int a; Math.DivRem(x, 4, out a); int b; Math.DivRem(x, 7, out b); int c; Math.DivRem(x, 19, out c); int d; Math.DivRem(((19 * c) + 15), 30, out d); int e; Math.DivRem(((2 * a) + (4 * b) - d + 34), 7, out e); int g; int f = Math.DivRem((d + e + 114), 31, out g); _easter = new DateTime(x, f, g + 1); } private void CalculateOtherHolyDays() { _goodFriday = _easter.AddDays(-2); _ashWednesday = _easter.AddDays(-46); _pentecost = _easter.AddDays(49); } } }
Unit Test Code (last updated: 21-May-2008)
[TestFixture] public class WesternChurchHolyDaysTest { [Test] public void s001_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1991); Assert.AreEqual(new DateTime(1991, 3, 31), holidays.Easter , "Easter date not correct."); } [Test] public void s002_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1992); Assert.AreEqual(new DateTime(1992, 4, 19), holidays.Easter, "Easter date not correct."); } [Test] public void s003_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1993); Assert.AreEqual(new DateTime(1993, 4, 11), holidays.Easter, "Easter date not correct."); } [Test] public void s004_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1954); Assert.AreEqual(new DateTime(1954, 4, 18), holidays.Easter, "Easter date not correct."); } [Test] public void s005_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(2000); Assert.AreEqual(new DateTime(2000, 4, 23), holidays.Easter, "Easter date not correct."); } [Test] public void s006_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1818); Assert.AreEqual(new DateTime(1818, 3, 22), holidays.Easter, "Easter date not correct."); } [Test] public void s010_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(179); Assert.AreEqual(new DateTime(179, 4, 12), holidays.Easter, "Easter date not correct."); } [Test] public void s011_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(711); Assert.AreEqual(new DateTime(711, 4, 12), holidays.Easter, "Easter date not correct."); } [Test] public void s012_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1243); Assert.AreEqual(new DateTime(1243, 4, 12), holidays.Easter, "Easter date not correct."); } [Test] public void s013_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(1991); Assert.AreEqual(new DateTime(1991, 3, 31), holidays.Easter, "Easter date not correct."); holidays.Year = 1992; Assert.AreEqual(new DateTime(1992, 4, 19), holidays.Easter, "Easter date not correct."); } [Test] public void s020_AshWednesday() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(2008); Assert.AreEqual(new DateTime(2008, 2, 6), holidays.AshWednesday, "Ash Wednesday date not correct."); } [Test] public void s021_GoodFriday() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(2008); Assert.AreEqual(new DateTime(2008, 3, 21), holidays.GoodFriday, "Good Friday date not correct."); } [Test] public void s022_Easter() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(2008); Assert.AreEqual(new DateTime(2008, 3, 23), holidays.Easter, "Easter date not correct."); } [Test] public void s023_Pentecost() { WesternChurchHolyDays holidays = new WesternChurchHolyDays(2008); Assert.AreEqual(new DateTime(2008, 5, 11), holidays.Pentecost, "Pentecost date not correct."); } }