ostern.c revision 17849
117849Swosch/* 217849Swosch * Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin. 317849Swosch * 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 * 2617849Swosch * $Id: ostern.c,v 1.4 1996/05/11 20:44:20 ache Exp $ 2717849Swosch */ 2813840Swosch 2915737Sache#include <stdio.h> 3015737Sache#include <stdlib.h> 3113840Swosch#include <string.h> 3215737Sache#include <time.h> 3313840Swosch 3415720Sache#include "calendar.h" 3515720Sache 3613840Swosch/* return year day for Easter */ 3713840Swosch 3813840Swoschint easter (year) 3913840Swosch int year; /* 0 ... abcd, NOT since 1900 */ 4013840Swosch{ 4113840Swosch 4213840Swosch int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k, 4313840Swosch e_l, e_m, e_n, e_p, e_q; 4413840Swosch 4513840Swosch /* silly, but it works */ 4613840Swosch e_a = year % 19; 4713840Swosch e_b = year / 100; 4813840Swosch e_c = year % 100; 4913840Swosch 5013840Swosch e_d = e_b / 4; 5113840Swosch e_e = e_b % 4; 5213840Swosch e_f = (e_b + 8) / 25; 5313840Swosch e_g = (e_b + 1 - e_f) / 3; 5413840Swosch e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30; 5513840Swosch e_i = e_c / 4; 5613840Swosch e_k = e_c % 4; 5713840Swosch e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7; 5813840Swosch e_m = (e_a + 11 * e_h + 22 * e_l) / 451; 5913840Swosch e_n = (e_h + e_l + 114 - (7 * e_m)) / 31; 6013840Swosch e_p = (e_h + e_l + 114 - (7 * e_m)) % 31; 6113840Swosch e_p = e_p + 1; 6213840Swosch 6313840Swosch e_q = 31 + 28; 6413840Swosch 6513840Swosch if (e_k == 0 && e_c != 0) 6613840Swosch e_q += 1; 6713840Swosch 6813840Swosch if (e_n == 4) 6913840Swosch e_q += 31; 7013840Swosch 7113840Swosch e_q += e_p; 7213840Swosch 7313840Swosch#if DEBUG 7413840Swosch printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", e_a , e_b , e_c , e_d , e_e , e_f , e_g , e_h , e_i , e_k , e_l , e_m , e_n , e_p , e_q); 7513840Swosch#endif 7613840Swosch 7713840Swosch return (e_q); 7813840Swosch} 7913840Swosch 8013840Swosch/* return year day for Easter or easter depending days 8113840Swosch * Match: Easter([+-][0-9]+)? 8213840Swosch * e.g: Easter-2 is Good Friday (2 days before Easter) 8313840Swosch */ 8413840Swosch 8513840Swoschint 8613840Swoschgeteaster(s, year) 8713840Swosch char *s; 8813840Swosch int year; 8913840Swosch{ 9013840Swosch register int offset = 0; 9115720Sache extern struct fixs neaster; 9213840Swosch 9313840Swosch#define EASTER "easter" 9413840Swosch#define EASTERNAMELEN (sizeof(EASTER) - 1) 9513840Swosch 9615720Sache if (strncasecmp(s, EASTER, EASTERNAMELEN) == 0) 9715720Sache s += EASTERNAMELEN; 9815720Sache else if ( neaster.name != NULL 9915720Sache && strncasecmp(s, neaster.name, neaster.len) == 0 10015720Sache ) 10115720Sache s += neaster.len; 10215720Sache else 10313840Swosch return(0); 10413840Swosch 10513840Swosch#if DEBUG 10613840Swosch printf("%s %d %d\n", s, year, EASTERNAMELEN); 10713840Swosch#endif 10813840Swosch 10913840Swosch /* Easter+1 or Easter-2 11013840Swosch * ^ ^ */ 11113840Swosch 11215720Sache switch(*s) { 11313840Swosch 11413840Swosch case '-': 11513840Swosch case '+': 11615720Sache offset = atoi(s); 11713840Swosch break; 11813840Swosch 11913840Swosch default: 12013840Swosch offset = 0; 12113840Swosch } 12213840Swosch 12313840Swosch return (easter(year) + offset); 12413840Swosch} 125