ostern.c revision 13840
113840Swosch/*
213840Swosch * Copyright (c) 1995 Wolfram Schneider. Public domain.
313840Swosch *
413840Swosch * $Id: ostern.c,v 1.2 1996/02/01 13:05:12 wosch Exp $
513840Swosch*/
613840Swosch
713840Swosch#include <string.h>
813840Swosch
913840Swosch/* return year day for Easter */
1013840Swosch
1113840Swoschint easter (year)
1213840Swosch    int year;            /* 0 ... abcd, NOT since 1900 */
1313840Swosch{
1413840Swosch
1513840Swosch    int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k,
1613840Swosch        e_l, e_m, e_n, e_p, e_q;
1713840Swosch
1813840Swosch    /* silly, but it works */
1913840Swosch    e_a = year % 19;
2013840Swosch    e_b = year / 100;
2113840Swosch    e_c = year % 100;
2213840Swosch
2313840Swosch    e_d = e_b / 4;
2413840Swosch    e_e = e_b % 4;
2513840Swosch    e_f = (e_b + 8) / 25;
2613840Swosch    e_g = (e_b + 1 - e_f) / 3;
2713840Swosch    e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30;
2813840Swosch    e_i = e_c / 4;
2913840Swosch    e_k = e_c % 4;
3013840Swosch    e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7;
3113840Swosch    e_m = (e_a + 11 * e_h + 22 * e_l) / 451;
3213840Swosch    e_n = (e_h + e_l + 114 - (7 * e_m)) / 31;
3313840Swosch    e_p = (e_h + e_l + 114 - (7 * e_m)) % 31;
3413840Swosch    e_p = e_p + 1;
3513840Swosch
3613840Swosch    e_q = 31 + 28;
3713840Swosch
3813840Swosch    if (e_k == 0 && e_c != 0)
3913840Swosch	e_q += 1;
4013840Swosch
4113840Swosch    if (e_n == 4)
4213840Swosch	e_q += 31;
4313840Swosch
4413840Swosch    e_q += e_p;
4513840Swosch
4613840Swosch#if DEBUG
4713840Swosch    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);
4813840Swosch#endif
4913840Swosch
5013840Swosch    return (e_q);
5113840Swosch}
5213840Swosch
5313840Swosch/* return year day for  Easter or easter depending days
5413840Swosch * Match: Easter([+-][0-9]+)?
5513840Swosch * e.g: Easter-2 is  Good Friday (2 days before Easter)
5613840Swosch */
5713840Swosch
5813840Swoschint
5913840Swoschgeteaster(s, year)
6013840Swosch	char *s;
6113840Swosch        int year;
6213840Swosch{
6313840Swosch	register int offset = 0;
6413840Swosch
6513840Swosch#define EASTER "easter"
6613840Swosch#define EASTERNAMELEN (sizeof(EASTER) - 1)
6713840Swosch
6813840Swosch	/* no easter */
6913840Swosch	if (strncasecmp(s, EASTER, EASTERNAMELEN))
7013840Swosch	    return(0);
7113840Swosch
7213840Swosch#if DEBUG
7313840Swosch	printf("%s %d %d\n", s, year, EASTERNAMELEN);
7413840Swosch#endif
7513840Swosch
7613840Swosch	/* Easter+1  or Easter-2
7713840Swosch	 *       ^            ^   */
7813840Swosch
7913840Swosch	switch(*(s + EASTERNAMELEN)) {
8013840Swosch
8113840Swosch	case '-':
8213840Swosch	    offset = -(atoi(s + EASTERNAMELEN + 1));
8313840Swosch	    break;
8413840Swosch
8513840Swosch	case '+':
8613840Swosch	    offset = atoi(s + EASTERNAMELEN + 1);
8713840Swosch	    break;
8813840Swosch
8913840Swosch	default:
9013840Swosch	    offset = 0;
9113840Swosch	}
9213840Swosch
9313840Swosch	return (easter(year) + offset);
9413840Swosch}
95