/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 1997 Wolfgang Helbig4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/cdefs.h>29#include "calendar.h"3031typedef struct date date;3233static int easterodn(int y);3435/* Compute Easter Sunday in Gregorian Calendar */36date *37easterg(int y, date *dt)38{39int c, i, j, k, l, n;4041n = y % 19;42c = y / 100;43k = (c - 17) / 25;44i = (c - c/4 -(c-k)/3 + 19 * n + 15) % 30;45i = i -(i/28) * (1 - (i/28) * (29/(i + 1)) * ((21 - n)/11));46j = (y + y/4 + i + 2 - c + c/4) % 7;47l = i - j;48dt->m = 3 + (l + 40) / 44;49dt->d = l + 28 - 31*(dt->m / 4);50dt->y = y;51return (dt);52}5354/* Compute the Gregorian date of Easter Sunday in Julian Calendar */55date *56easterog(int y, date *dt)57{5859return (gdate(easterodn(y), dt));60}6162/* Compute the Julian date of Easter Sunday in Julian Calendar */63date *64easteroj(int y, date * dt)65{6667return (jdate(easterodn(y), dt));68}6970/* Compute the day number of Easter Sunday in Julian Calendar */71static int72easterodn(int y)73{74/*75* Table for the easter limits in one metonic (19-year) cycle. 2176* to 31 is in March, 1 through 18 in April. Easter is the first77* sunday after the easter limit.78*/79int mc[] = {5, 25, 13, 2, 22, 10, 30, 18, 7, 27, 15, 4,8024, 12, 1, 21, 9, 29, 17};8182/* Offset from a weekday to next sunday */83int ns[] = {6, 5, 4, 3, 2, 1, 7};84date dt;85int dn;8687/* Assign the easter limit of y to dt */88dt.d = mc[y % 19];8990if (dt.d < 21)91dt.m = 4;92else93dt.m = 3;9495dt.y = y;9697/* Return the next sunday after the easter limit */98dn = ndaysj(&dt);99return (dn + ns[weekday(dn)]);100}101102103