2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2020 The DragonFly Project. All rights reserved.
6 * This code is derived from software contributed to The DragonFly Project
7 * by Aaron LI <aly@aaronly.me>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
19 * 3. Neither the name of The DragonFly Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific, prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * Calendrical Calculations, The Ultimate Edition (4th Edition)
38 * by Edward M. Reingold and Nachum Dershowitz
39 * 2018, Cambridge University Press
47 #include "ecclesiastical.h"
48 #include "gregorian.h"
53 * Calculate the fixed date (RD) of Orthodox Easter in Gregorian year $g_year.
54 * Ref: Sec.(9.1), Eq.(9.1)
57 orthodox_easter(int g_year)
59 /* Age of moon for April 5 */
60 int shifted_epact = mod(14 + 11 * mod(g_year, 19), 30);
62 /* Day after full moon on/after March 21 */
63 int j_year = (g_year > 0) ? g_year : (g_year - 1);
64 struct date april19 = { j_year, 4, 19 };
65 int paschal_moon = fixed_from_julian(&april19) - shifted_epact;
67 return kday_after(SUNDAY, paschal_moon);
71 * Calculate the fixed date (RD) of Gregorian Easter (used by Catholic and
72 * Protestant churches) in Gregorian year $g_year.
73 * Ref: Sec.(9.2), Eq.(9.3)
78 int century = div_floor(g_year, 100) + 1;
79 int y_mod19 = mod(g_year, 19);
80 int n = (14 + 11 * y_mod19 - (int)floor(century * 0.75) +
81 div_floor(5 + 8 * century, 25));
82 int shifted_epact = mod(n, 30);
83 if (shifted_epact == 0 || (shifted_epact == 1 && y_mod19 > 10))
86 struct date april19 = { g_year, 4, 19 };
87 int paschal_moon = fixed_from_gregorian(&april19) - shifted_epact;
89 return kday_after(SUNDAY, paschal_moon);
93 * Calculate the fixed date (RD) of Advent Sunday (the 4th Sunday
94 * before Christmas, equivalent to the Sunday closest to November 30)
95 * in Gregorian year $g_year.
96 * Ref: Sec.(2.5), Eq.(2.42)
101 struct date date = { g_year, 11, 30 };
104 if (Calendar->id == CAL_JULIAN)
105 rd = fixed_from_julian(&date);
107 rd = fixed_from_gregorian(&date);
109 return kday_nearest(SUNDAY, rd);