paskha.c revision 218473
1139749Simp/*-
254134Swpaul * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
354134Swpaul * All rights reserved.
454134Swpaul *
554134Swpaul * Redistribution and use in source and binary forms, with or without
654134Swpaul * modification, are permitted provided that the following conditions
754134Swpaul * are met:
854134Swpaul * 1. Redistributions of source code must retain the above copyright
954134Swpaul *    notice, this list of conditions and the following disclaimer.
1054134Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1154134Swpaul *    notice, this list of conditions and the following disclaimer in the
1254134Swpaul *    documentation and/or other materials provided with the distribution.
1354134Swpaul *
1454134Swpaul * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
1554134Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1654134Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1754134Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1854134Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1954134Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2054134Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2154134Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2254134Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2354134Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2454134Swpaul * SUCH DAMAGE.
2554134Swpaul */
2654134Swpaul
2754134Swpaul#include <sys/cdefs.h>
2854134Swpaul__FBSDID("$FreeBSD: head/usr.bin/calendar/paskha.c 218473 2011-02-09 06:38:32Z osa $");
2954134Swpaul
3054134Swpaul#include <stdio.h>
3154134Swpaul#include <stdlib.h>
3254134Swpaul#include <string.h>
33119418Sobrien
34119418Sobrien#include "calendar.h"
35119418Sobrien
3654134Swpaul#define	PASKHA		"paskha"
3754134Swpaul#define	PASKHALEN	(sizeof(PASKHA) - 1)
38183505Smarius
3954134Swpaul/* return year day for Orthodox Easter using Gauss formula */
40183505Smarius/* (new style result) */
4154134Swpaul
4254134Swpaulint
4354134Swpaulpaskha(int R) /*year*/
4454134Swpaul{
4554134Swpaul	int a, b, c, d, e;
4654134Swpaul	static int x = 15;
4754134Swpaul	static int y = 6;
4854134Swpaul	int *cumday;
4954134Swpaul
5074914Sjhb	a = R % 19;
5154134Swpaul	b = R % 4;
5267365Sjhb	c = R % 7;
5354134Swpaul	d = (19 * a + x) % 30;
5454134Swpaul	e = (2 * b + 4 * c + 6 * d + y) % 7;
5554134Swpaul	cumday = cumdaytab[isleap(R)];
5654134Swpaul	return (((cumday[3] + 1) + 22) + (d + e) + 13);
5754134Swpaul}
5854134Swpaul