paskha.c revision 218797
1251875Speter/*-
2251875Speter * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
3253734Speter * All rights reserved.
4251875Speter *
5251875Speter * Redistribution and use in source and binary forms, with or without
6253734Speter * modification, are permitted provided that the following conditions
7251875Speter * are met:
8251875Speter * 1. Redistributions of source code must retain the above copyright
9251875Speter *    notice, this list of conditions and the following disclaimer.
10251875Speter * 2. Redistributions in binary form must reproduce the above copyright
11251875Speter *    notice, this list of conditions and the following disclaimer in the
12251875Speter *    documentation and/or other materials provided with the distribution.
13251875Speter *
14251875Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
15251875Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16251875Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17251875Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18251875Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19251875Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20251875Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21251875Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22251875Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23251875Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24251875Speter * SUCH DAMAGE.
25251875Speter */
26251875Speter
27251875Speter#include <sys/cdefs.h>
28251875Speter__FBSDID("$FreeBSD: head/usr.bin/calendar/paskha.c 218797 2011-02-18 13:41:45Z osa $");
29251875Speter
30251875Speter#include <stdio.h>
31251875Speter#include <stdlib.h>
32251875Speter#include <string.h>
33251875Speter
34251875Speter#include "calendar.h"
35251875Speter
36251875Speter#define	PASKHA		"paskha"
37251875Speter#define	PASKHALEN	(sizeof(PASKHA) - 1)
38251875Speter
39251875Speter/* return difference in days between Julian and Gregorian calendars */
40251875Speterint
41251875Speterj2g(int year)
42251875Speter{
43251875Speter	return (year < 1500) ?
44251875Speter		0 :
45251875Speter		10 + (year/100 - 16) - ((year/100 - 16) / 4);
46251875Speter}
47251875Speter
48251875Speter/* return year day for Orthodox Easter using Gauss formula */
49251875Speter/* (new style result) */
50251875Speter
51251875Speterint
52251875Speterpaskha(int R) /*year*/
53251875Speter{
54251875Speter	int a, b, c, d, e;
55251875Speter	static int x = 15;
56251875Speter	static int y = 6;
57251875Speter	int *cumday;
58251875Speter
59251875Speter	a = R % 19;
60251875Speter	b = R % 4;
61251875Speter	c = R % 7;
62251875Speter	d = (19 * a + x) % 30;
63251875Speter	e = (2 * b + 4 * c + 6 * d + y) % 7;
64251875Speter	cumday = cumdaytab[isleap(R)];
65251875Speter	return (((cumday[3] + 1) + 22) + (d + e) + j2g(R));
66251875Speter}
67251875Speter