1205821Sedwin/*- 217849Swosch * Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin. 3181322Sedwin * All rights reserved. 413840Swosch * 517849Swosch * Redistribution and use in source and binary forms, with or without 617849Swosch * modification, are permitted provided that the following conditions 717849Swosch * are met: 817849Swosch * 1. Redistributions of source code must retain the above copyright 917849Swosch * notice, this list of conditions and the following disclaimer. 1017849Swosch * 2. Redistributions in binary form must reproduce the above copyright 1117849Swosch * notice, this list of conditions and the following disclaimer in the 1217849Swosch * documentation and/or other materials provided with the distribution. 1317849Swosch * 1417849Swosch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1517849Swosch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1617849Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1717849Swosch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1817849Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1917849Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2017849Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2117849Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2217849Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2317849Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2417849Swosch * SUCH DAMAGE. 2517849Swosch */ 2613840Swosch 2787235Smarkm#include <sys/cdefs.h> 2887235Smarkm__FBSDID("$FreeBSD$"); 2987235Smarkm 3015737Sache#include <stdio.h> 3115737Sache#include <stdlib.h> 3213840Swosch#include <string.h> 3313840Swosch 3415720Sache#include "calendar.h" 3515720Sache 3613840Swosch/* return year day for Easter */ 3713840Swosch 3870598Sdwmalone/* 3970598Sdwmalone * This code is based on the Calendar FAQ's code for how to calculate 4070598Sdwmalone * easter is. This is the Gregorian calendar version. They refer to 4170598Sdwmalone * the Algorithm of Oudin in the "Explanatory Supplement to the 4270598Sdwmalone * Astronomical Almanac". 4370598Sdwmalone */ 4470598Sdwmalone 45169343Sdwmaloneint 46169343Sdwmaloneeaster(int year) /* 0 ... abcd, NOT since 1900 */ 4713840Swosch{ 48181322Sedwin int G, /* Golden number - 1 */ 49181322Sedwin C, /* Century */ 50181322Sedwin H, /* 23 - epact % 30 */ 51181322Sedwin I, /* days from 21 March to Paschal full moon */ 52181322Sedwin J, /* weekday of full moon */ 53181322Sedwin L; /* days from 21 March to Sunday on of before full moon */ 5413840Swosch 55181322Sedwin G = year % 19; 56181322Sedwin C = year / 100; 57181322Sedwin H = (C - C / 4 - (8 * C + 13) / 25 + 19 * G + 15) % 30; 58181322Sedwin I = H - (H / 28) * (1 - (H / 28) * (29 / (H + 1)) * ((21 - G) / 11)); 59181322Sedwin J = (year + year / 4 + I + 2 - C + C / 4) % 7; 6013840Swosch 61181322Sedwin L = I - J; 6213840Swosch 63205821Sedwin if (isleap(year)) 64181322Sedwin return 31 + 29 + 21 + L + 7; 65181322Sedwin else 66181322Sedwin return 31 + 28 + 21 + L + 7; 6713840Swosch} 68