paskha.c revision 205821
190792Sgshapiro/*-
2261363Sgshapiro * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
390792Sgshapiro * All rights reserved.
490792Sgshapiro *
590792Sgshapiro * Redistribution and use in source and binary forms, with or without
690792Sgshapiro * modification, are permitted provided that the following conditions
790792Sgshapiro * are met:
890792Sgshapiro * 1. Redistributions of source code must retain the above copyright
990792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1090792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1190792Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1290792Sgshapiro *    documentation and/or other materials provided with the distribution.
1390792Sgshapiro *
1490792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
1590792Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1690792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1790792Sgshapiro * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1890792Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1990792Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2090792Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2190792Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2290792Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2390792Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2490792Sgshapiro * SUCH DAMAGE.
25266692Sgshapiro */
2690792Sgshapiro
2790792Sgshapiro#include <sys/cdefs.h>
2890792Sgshapiro__FBSDID("$FreeBSD: head/usr.bin/calendar/paskha.c 205821 2010-03-29 06:49:20Z edwin $");
2990792Sgshapiro
3090792Sgshapiro#include <stdio.h>
3190792Sgshapiro#include <stdlib.h>
3290792Sgshapiro#include <string.h>
3390792Sgshapiro
3490792Sgshapiro#include "calendar.h"
3590792Sgshapiro
3690792Sgshapiro#define	PASKHA		"paskha"
3790792Sgshapiro#define	PASKHALEN	(sizeof(PASKHA) - 1)
3890792Sgshapiro
3990792Sgshapiro/* return year day for Orthodox Easter using Gauss formula */
4090792Sgshapiro/* (old style result) */
4190792Sgshapiro
4290792Sgshapiroint
4390792Sgshapiropaskha(int R) /*year*/
4490792Sgshapiro{
4590792Sgshapiro	int a, b, c, d, e;
4690792Sgshapiro	static int x = 15;
4790792Sgshapiro	static int y = 6;
4890792Sgshapiro	int *cumday;
4990792Sgshapiro
5090792Sgshapiro	a = R % 19;
5190792Sgshapiro	b = R % 4;
5290792Sgshapiro	c = R % 7;
5390792Sgshapiro	d = (19 * a + x) % 30;
5490792Sgshapiro	e = (2 * b + 4 * c + 6 * d + y) % 7;
5590792Sgshapiro	cumday = cumdaytab[isleap(R)];
5690792Sgshapiro	return (((cumday[3] + 1) + 22) + (d + e));
5790792Sgshapiro}
5890792Sgshapiro